MIAC for pulse duration measuring

For MIAC users to discuss projects, applications, and any other issues related to the MIAC unit.

Moderators: Benj, Mods

Post Reply
prasannak
Posts: 1
Joined: Wed Sep 25, 2019 4:47 pm
Contact:

MIAC for pulse duration measuring

Post 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 230 times
Thank you,
PK

medelec35
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

Post 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.
Martin

prasannak@123
Posts: 5
Joined: Tue Mar 03, 2020 5:19 pm
Has thanked: 4 times
Contact:

Re: MIAC for pulse duration measuring

Post 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:
Attachments
Speed sensing.fcfx
(14.92 KiB) Downloaded 232 times

medelec35
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

Post 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.
Martin

prasannak@123
Posts: 5
Joined: Tue Mar 03, 2020 5:19 pm
Has thanked: 4 times
Contact:

Re: MIAC for pulse duration measuring

Post 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
Attachments
Speed sensing.fcfx
(17.79 KiB) Downloaded 239 times

medelec35
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

Post 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.
Martin

User avatar
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

Post 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.

User avatar
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

Post 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.

prasannak@123
Posts: 5
Joined: Tue Mar 03, 2020 5:19 pm
Has thanked: 4 times
Contact:

Re: MIAC for pulse duration measuring

Post 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.
Attachments
Speed sensing1.fcfx
(18.26 KiB) Downloaded 231 times

medelec35
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

Post 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.
Martin

prasannak@123
Posts: 5
Joined: Tue Mar 03, 2020 5:19 pm
Has thanked: 4 times
Contact:

Re: MIAC for pulse duration measuring

Post by prasannak@123 »

Hi medelec35,
Thankyou very much for helping me.The rotational speed is about 750rpm.
Thankyou,
PK

medelec35
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

Post 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.
Attachments
Speed sensing1.fcfx
(19.35 KiB) Downloaded 216 times
Martin

medelec35
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

Post 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.
Attachments
Speed sensing3.fcfx
(15.88 KiB) Downloaded 172 times
Martin

medelec35
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

Post by medelec35 »

How is the testing gong?
Martin

medelec35
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

Post by medelec35 »

Sorry forgot to mention.
As the latest version uses INT2, you Neen to conect pulse source to I8.
Martin

prasannak@123
Posts: 5
Joined: Tue Mar 03, 2020 5:19 pm
Has thanked: 4 times
Contact:

Re: MIAC for pulse duration measuring

Post 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.
Attachments
Speed sensing3.fcfx
(17.12 KiB) Downloaded 169 times
rpm calculation.pdf
(625.75 KiB) Downloaded 177 times

medelec35
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

Post 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.
Martin

Post Reply