Page 1 of 1

MIAC for pulse duration measuring

Posted: Tue Mar 03, 2020 6:03 pm
by prasannak
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. :?: :?:
Flowcode1.fcfx
(11.01 KiB) Downloaded 259 times
Thank you,
PK

Re: MIAC for pulse duration measuring

Posted: Tue Mar 03, 2020 10:40 pm
by medelec35
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.

Re: MIAC for pulse duration measuring

Posted: Wed Mar 04, 2020 8:15 am
by prasannak@123
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. :cry:

Re: MIAC for pulse duration measuring

Posted: Wed Mar 04, 2020 8:55 am
by medelec35
prasannak@123 wrote: it's increment by 15. here the example I tried.
The only other way I can think of is measure the time period between pulses rather than the pulse width.
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.

Re: MIAC for pulse duration measuring

Posted: Wed Mar 04, 2020 10:19 am
by prasannak@123
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

Re: MIAC for pulse duration measuring

Posted: Wed Mar 04, 2020 11:02 am
by medelec35
prasannak@123 wrote:I tried to get pulse time with using timer component. But can't get the time
What value are you getting for 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.

Re: MIAC for pulse duration measuring

Posted: Wed Mar 04, 2020 11:33 am
by LeighM
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.

Re: MIAC for pulse duration measuring

Posted: Wed Mar 04, 2020 12:16 pm
by Benj
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.

Re: MIAC for pulse duration measuring

Posted: Wed Mar 04, 2020 6:58 pm
by prasannak@123
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. :cry: :cry:
Thankyou
PK.

Re: MIAC for pulse duration measuring

Posted: Thu Mar 05, 2020 12:02 am
by medelec35
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.

Re: MIAC for pulse duration measuring

Posted: Thu Mar 05, 2020 7:45 am
by prasannak@123
Hi medelec35,
Thankyou very much for helping me.The rotational speed is about 750rpm.
Thankyou,
PK

Re: MIAC for pulse duration measuring

Posted: Thu Mar 05, 2020 9:29 am
by medelec35
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.

Re: MIAC for pulse duration measuring

Posted: Thu Mar 05, 2020 1:00 pm
by medelec35
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.

Re: MIAC for pulse duration measuring

Posted: Thu Mar 05, 2020 9:23 pm
by medelec35
How is the testing gong?

Re: MIAC for pulse duration measuring

Posted: Fri Mar 06, 2020 6:04 am
by medelec35
Sorry forgot to mention.
As the latest version uses INT2, you Neen to conect pulse source to I8.

Re: MIAC for pulse duration measuring

Posted: Fri Mar 06, 2020 7:39 am
by prasannak@123
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.

Re: MIAC for pulse duration measuring

Posted: Fri Mar 06, 2020 8:41 am
by medelec35
prasannak@123 wrote:What is the meaning of the InSim
It is used to run Yes branch if you are running simulation, or only no branch on actual hardware.
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.