MIAC for pulse duration measuring
MIAC for pulse duration measuring
Hi,
I'm new user MIAC and flow code. I wanna read generator rpm by using proximity sensor. First of all I need to get pulse width(duration) of the input signal. After that can apply some calculation to get rpm. I try to get the pulse width but it's not working with MIAC . can some one help me to solve this. Thank you,
PK
I'm new user MIAC and flow code. I wanna read generator rpm by using proximity sensor. First of all I need to get pulse width(duration) of the input signal. After that can apply some calculation to get rpm. I try to get the pulse width but it's not working with MIAC . can some one help me to solve this. Thank you,
PK
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: MIAC for pulse duration measuring
Hi PK,
Measuring pulse width could be one method for measuring frequency.
However, the method I use for measuring RPM is start a timer interrupt, use a port pin interrupt(e.g INT2) to count pulses over a set period of time e.g 1 second.
The RPM will be the total number of pulses * 60.
I have used a Miac to measure RPM of fans.
Measuring pulse width could be one method for measuring frequency.
However, the method I use for measuring RPM is start a timer interrupt, use a port pin interrupt(e.g INT2) to count pulses over a set period of time e.g 1 second.
The RPM will be the total number of pulses * 60.
I have used a Miac to measure RPM of fans.
Martin
-
- Posts: 5
- Joined: Tue Mar 03, 2020 5:19 pm
- Has thanked: 4 times
- Contact:
Re: MIAC for pulse duration measuring
Hi medelec35,
Thankyou for replying me. Its ok but I need to get exact RPM using pulse duration measurement. According to your instruction I tried it but I was unable to get exact RPM. it's increment by 15. here the example I tried.
Thankyou for replying me. Its ok but I need to get exact RPM using pulse duration measurement. According to your instruction I tried it but I was unable to get exact RPM. it's increment by 15. here the example I tried.
- Attachments
-
- Speed sensing.fcfx
- (14.92 KiB) Downloaded 258 times
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: MIAC for pulse duration measuring
The only other way I can think of is measure the time period between pulses rather than the pulse width.prasannak@123 wrote: it's increment by 15. here the example I tried.
Then RPM = 1/time period * 60
To make it easier there is a timer component in Flowcode V8.
Just click the magnifying glass and enter the word timerin the search filter box.
I believe it would be better to use INT2 rather than tight loop.
Martin
-
- Posts: 5
- Joined: Tue Mar 03, 2020 5:19 pm
- Has thanked: 4 times
- Contact:
Re: MIAC for pulse duration measuring
Hi medelec35,
I tried to get pulse time with using timer component. But can't get the time. can u please correct this. Here the example I tried.
thankyou
PK
I tried to get pulse time with using timer component. But can't get the time. can u please correct this. Here the example I tried.
thankyou
PK
- Attachments
-
- Speed sensing.fcfx
- (17.79 KiB) Downloaded 271 times
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: MIAC for pulse duration measuring
What value are you getting for the time?prasannak@123 wrote:I tried to get pulse time with using timer component. But can't get the time
Is it just 0 all the time or random values?
Have not played with the Timer component yet,
but I plan to soon as I can see it as being very useful.
I believe LeighM or Benj would be able to shed some light on using timer component with MIAC?
Will have a play myself with a MIAC when get home from work this evening.
Martin
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: MIAC for pulse duration measuring
Hi,
To time a complete cycle, you need to do this:
Wait for leading edge (loop while low)
Reset the counter/timer
Wait for trailing edge (loop while high)
Wait for next leading edge (loop while low)
Stop the counter/timer
Get the Count in milliseconds
This assumes you have a clean signal from the proximity sensor (i.e. no bounce)
Nb. Also depends what your max rpm is.
As medelec35 mentioned, might be best to use an interrupt to increment the pulse counter and use the timer to set a period of time to count and reset.
Both methods need a clean square wave from your sensor. Might need a filter capacitor, depending on your external circuit.
To time a complete cycle, you need to do this:
Wait for leading edge (loop while low)
Reset the counter/timer
Wait for trailing edge (loop while high)
Wait for next leading edge (loop while low)
Stop the counter/timer
Get the Count in milliseconds
This assumes you have a clean signal from the proximity sensor (i.e. no bounce)
Nb. Also depends what your max rpm is.
As medelec35 mentioned, might be best to use an interrupt to increment the pulse counter and use the timer to set a period of time to count and reset.
Both methods need a clean square wave from your sensor. Might need a filter capacitor, depending on your external circuit.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: MIAC for pulse duration measuring
Hello,
You are calling the StartCounter from within the loop which will be constantly resetting the count value to 0. You should only call this once to start the count, maybe before the while in=1 loop.
You might need to update your components as you are not on the latest version which allows you to reset or continue the count when calling the StartCounter function.
You are calling the StartCounter from within the loop which will be constantly resetting the count value to 0. You should only call this once to start the count, maybe before the while in=1 loop.
You might need to update your components as you are not on the latest version which allows you to reset or continue the count when calling the StartCounter function.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 5
- Joined: Tue Mar 03, 2020 5:19 pm
- Has thanked: 4 times
- Contact:
Re: MIAC for pulse duration measuring
Hi Benj, LeighM,medelec35,
First of all I would like to thank to replying me. I tried it according to your instruction. The counting value just 0. Here also attached it. Is there any wrong with variable and timer. Please help me to get the pulse duration. Can u please correct this.
Thankyou
PK.
First of all I would like to thank to replying me. I tried it according to your instruction. The counting value just 0. Here also attached it. Is there any wrong with variable and timer. Please help me to get the pulse duration. Can u please correct this.
Thankyou
PK.
- Attachments
-
- Speed sensing1.fcfx
- (18.26 KiB) Downloaded 259 times
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: MIAC for pulse duration measuring
The timer component does appear to have some issues, but it maybe because using on a Miac e.g. circuity which delays input by about 5ms?
For example if using an Ulong variable and reading a 1ms pulse, the timer value is 6443. If reading a 2ms pulse the reading is 7443
I will look at an alternative method tomorrow.
What RPM range are you interested in?
You still have not updated Flowcode.
Select help, Check for updates.
Change files in-use to Full database then click download.
For example if using an Ulong variable and reading a 1ms pulse, the timer value is 6443. If reading a 2ms pulse the reading is 7443
I will look at an alternative method tomorrow.
What RPM range are you interested in?
You still have not updated Flowcode.
Select help, Check for updates.
Change files in-use to Full database then click download.
Martin
-
- Posts: 5
- Joined: Tue Mar 03, 2020 5:19 pm
- Has thanked: 4 times
- Contact:
Re: MIAC for pulse duration measuring
Hi medelec35,
Thankyou very much for helping me.The rotational speed is about 750rpm.
Thankyou,
PK
Thankyou very much for helping me.The rotational speed is about 750rpm.
Thankyou,
PK
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: MIAC for pulse duration measuring
Hi PK,
You're welcome.
There will be an issue with the amount of loops you had.
Reason being at the very start of the loop, the pulse could be 1/2 way through high or low, so need to wait for the first change from low to high.
Attached is something to get you going.
Looking at trying with INT instead of tight loop for increased accuracy.
You're welcome.
There will be an issue with the amount of loops you had.
Reason being at the very start of the loop, the pulse could be 1/2 way through high or low, so need to wait for the first change from low to high.
Attached is something to get you going.
Looking at trying with INT instead of tight loop for increased accuracy.
- Attachments
-
- Speed sensing1.fcfx
- (19.35 KiB) Downloaded 242 times
Martin
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: MIAC for pulse duration measuring
An alternative way using INT2.
Can't get it to work with INT2 and the timing component together.
Therefore, I have averaged the readings over 4 seconds instead of every second.
You just take into account the display will take a few seconds to settle.
Can't get it to work with INT2 and the timing component together.
Therefore, I have averaged the readings over 4 seconds instead of every second.
You just take into account the display will take a few seconds to settle.
- Attachments
-
- Speed sensing3.fcfx
- (15.88 KiB) Downloaded 195 times
Martin
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: MIAC for pulse duration measuring
Sorry forgot to mention.
As the latest version uses INT2, you Neen to conect pulse source to I8.
As the latest version uses INT2, you Neen to conect pulse source to I8.
Martin
-
- Posts: 5
- Joined: Tue Mar 03, 2020 5:19 pm
- Has thanked: 4 times
- Contact:
Re: MIAC for pulse duration measuring
Hi medelec35,
I was unable to check with MIAC just only flow-code simulation. According to simulated result it's not increment one by one.What is the meaning of the InSim. Is it int pin. I connected PB for I8 pin to give pulse signal. Also I need pulse width time. here I attached my calculation and flow code file.
Thankyou,
PK.
I was unable to check with MIAC just only flow-code simulation. According to simulated result it's not increment one by one.What is the meaning of the InSim. Is it int pin. I connected PB for I8 pin to give pulse signal. Also I need pulse width time. here I attached my calculation and flow code file.
Thankyou,
PK.
- Attachments
-
- Speed sensing3.fcfx
- (17.12 KiB) Downloaded 198 times
-
- rpm calculation.pdf
- (625.75 KiB) Downloaded 205 times
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: MIAC for pulse duration measuring
It is used to run Yes branch if you are running simulation, or only no branch on actual hardware.prasannak@123 wrote:What is the meaning of the InSim
IsSim Icon is on the 3D panel.
If you select it, then right clock & select Help, you will be taken to wiki help that will give further details
Looking at rpm calculation.pdf, Speed sensing1.fcfx uploaded on Thu Mar 05, 2020 8:29 am should work if you change the calculations.
Martin