MIAC for pulse duration measuring

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

Moderators: Benj, Mods

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

MIAC for pulse duration measuring

Postby prasannak » Tue Mar 03, 2020 6:03 pm

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 21 times

Thank you,
PK

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8812
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2558 times
Been thanked: 3712 times
Contact:

Re: MIAC for pulse duration measuring

Postby medelec35 » Tue Mar 03, 2020 10:40 pm

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.
These users thanked the author medelec35 for the post (total 3):
kersing (Tue Mar 03, 2020 11:04 pm) • AbhijitR (Wed Mar 04, 2020 6:54 am) • prasannak@123 (Wed Mar 04, 2020 10:25 am)
Rating: 15%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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

Re: MIAC for pulse duration measuring

Postby prasannak@123 » Wed Mar 04, 2020 8:15 am

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 33 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8812
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2558 times
Been thanked: 3712 times
Contact:

Re: MIAC for pulse duration measuring

Postby medelec35 » Wed Mar 04, 2020 8:55 am

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.
These users thanked the author medelec35 for the post:
prasannak@123 (Wed Mar 04, 2020 9:25 am)
Rating: 5%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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

Re: MIAC for pulse duration measuring

Postby prasannak@123 » Wed Mar 04, 2020 10:19 am

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 30 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8812
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2558 times
Been thanked: 3712 times
Contact:

Re: MIAC for pulse duration measuring

Postby medelec35 » Wed Mar 04, 2020 11:02 am

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.
These users thanked the author medelec35 for the post:
LeighM (Wed Mar 04, 2020 11:33 am)
Rating: 5%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
LeighM
Matrix Staff
Posts: 2009
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 480 times
Been thanked: 688 times
Contact:

Re: MIAC for pulse duration measuring

Postby LeighM » Wed Mar 04, 2020 11:33 am

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.
These users thanked the author LeighM for the post:
medelec35 (Wed Mar 04, 2020 11:36 am)
Rating: 5%
 

User avatar
Benj
Matrix Staff
Posts: 14786
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4750 times
Been thanked: 4358 times
Contact:

Re: MIAC for pulse duration measuring

Postby Benj » Wed Mar 04, 2020 12:16 pm

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.
These users thanked the author Benj for the post:
medelec35 (Wed Mar 04, 2020 1:04 pm)
Rating: 5%
 

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

Re: MIAC for pulse duration measuring

Postby prasannak@123 » Wed Mar 04, 2020 6:58 pm

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 22 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8812
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2558 times
Been thanked: 3712 times
Contact:

Re: MIAC for pulse duration measuring

Postby medelec35 » Thu Mar 05, 2020 12:02 am

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

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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

Re: MIAC for pulse duration measuring

Postby prasannak@123 » Thu Mar 05, 2020 7:45 am

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

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8812
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2558 times
Been thanked: 3712 times
Contact:

Re: MIAC for pulse duration measuring

Postby medelec35 » Thu Mar 05, 2020 9:29 am

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 23 times
These users thanked the author medelec35 for the post:
prasannak@123 (Thu Mar 05, 2020 11:12 am)
Rating: 5%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8812
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2558 times
Been thanked: 3712 times
Contact:

Re: MIAC for pulse duration measuring

Postby medelec35 » Thu Mar 05, 2020 1:00 pm

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 20 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8812
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2558 times
Been thanked: 3712 times
Contact:

Re: MIAC for pulse duration measuring

Postby medelec35 » Thu Mar 05, 2020 9:23 pm

How is the testing gong?
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8812
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2558 times
Been thanked: 3712 times
Contact:

Re: MIAC for pulse duration measuring

Postby medelec35 » Fri Mar 06, 2020 6:04 am

Sorry forgot to mention.
As the latest version uses INT2, you Neen to conect pulse source to I8.
These users thanked the author medelec35 for the post:
prasannak@123 (Fri Mar 06, 2020 8:10 am)
Rating: 5%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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

Re: MIAC for pulse duration measuring

Postby prasannak@123 » Fri Mar 06, 2020 7:39 am

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 14 times
rpm calculation.pdf
(625.97 KiB) Downloaded 29 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8812
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2558 times
Been thanked: 3712 times
Contact:

Re: MIAC for pulse duration measuring

Postby medelec35 » Fri Mar 06, 2020 8:41 am

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

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.