01-05-2017 11:38 PM
Hello all,
I have an application in which I need multiple timers.
There are 18 digital inputs (may go up to 24 in future). Each digital pin can give a pulse at any moment of time. Each pulse is treated as cycle finish. I want to measure the time difference between the current pulse and the previous pulse on the same digital pin and plot it on a graph.
All the 18 pins can receive pulse at any time. Time accuracy required is around 100-200 ms.
Following are the things I was thinking to use:
1. Multiple timers in 1 while loop.
2. Generating a different file for different inputs, storing the time of previous pulse and then using it to subtract when the new pulse occurs.
I am not sure which one is the best way to program. Or if there is any other better way, suggestions are most welcome.
Also is there any way to have multiple x axis for the same graph/chart?
Thanks in advance.
01-06-2017 12:07 AM
You don't need multiple timers, and you certainly don't want to save data to a file.
Create a functional global variable that stores an array of time values, 18 elements, each corresponds to an input. When a digital input turns true, grab the time and call the FGV feeding in the channel number and the time. The FGV will update the corresponding element of the array and return the difference between the new time and the old time.
Maybe it should store the previoius time value and the new time value so you can always have the difference between the last two, but also hold the last time stamp. When it is updated, the most recent moves to the old spot, and the new time stamp goes in the new timestamp slot.
01-06-2017 06:27 AM
RavensFan wrote: When a digital input turns true, grab the time and call the FGV feeding in the channel number and the time. The FGV will update the corresponding element of the array and return the difference between the new time and the old time.
My thought it is just pass the digital values (I assume an array of boolean) into the FGV and let it do all of the work (get curent time, go through each value and see if the value changed, update whatever time values needed, etc). Since we are using arrays and FOR loops inside of the FGV, it is very expandable.
01-06-2017 08:57 AM
@crossrulz wrote:
RavensFan wrote: When a digital input turns true, grab the time and call the FGV feeding in the channel number and the time. The FGV will update the corresponding element of the array and return the difference between the new time and the old time.My thought it is just pass the digital values (I assume an array of boolean) into the FGV and let it do all of the work (get curent time, go through each value and see if the value changed, update whatever time values needed, etc). Since we are using arrays and FOR loops inside of the FGV, it is very expandable.
That should work also. I think the difference between yours and mine is that I was thinking more of an event driven situation, (Hey, input #X just changed, do something) and yours would be for a polling type situation (Let's check on all inputs at once and do something.)
01-11-2017 04:33 AM
Thanks guys, I will certainly try it out.
Meanwhile, I will be needing 36 D I/O's for this particular timer vi to reset timers.
I was thinking of using 2 NI USB 6501. I will be accessing these 2 devices simultaneously.
Is there any care I need to take so that the functionality of above methods don't get affected?
Thanks!
01-11-2017 09:01 AM
Personally, I would use a 6509 (96 DIO lines!). Then you can read everything with a single task. Otherwise, I don't see any issues.
02-01-2017 11:35 PM
Hello,
I tried implementing the FGV. But it seems, the value in my indicator is 1 iteration behind to that of the source.
Now I do not understand how to avoid it or if I am going wrong somewhere with the code.
I am attaching my code with this post.
Thanks
02-02-2017 05:59 AM - edited 02-02-2017 06:00 AM
Hi rk,
it seems, the value in my indicator is 1 iteration behind to that of the source.
How do you know it's exactly 1 iteration? There is NO timing in your example VI…
And yes: your consumer cannot read the latest value not at the very same time the producer is writing it into the FGV.
One loop writes new data as fast as possible into the FGV, the other reads as fast as possible. You don't know which one of the loops is executing currently nor the order. It might be possible both loops iterate alternately - atleast one loop will block the other because of the non-reentrant FGV!
What's your goal here? All your FGV does is providing a buffer for a value with NO timing or history involved: you might use notifiers for the same task.
When you need to make sure your consumer receives ALL values from producer you should use a queue instead…
02-02-2017 10:45 PM
Thank you GerdW for clarifying my doubt.
I will try to implement things you said.
Regards,