04-28-2010 01:05 PM
Hi,
I was just wondering if someone can suggest a better way of doing the function I have attached below. Basically, it is counting pulses (falling edges) over a 250ms time period and converting that to speed. There seems to be some cases where it counts lesser pulses for a longer period than 250ms which results in lower speeds, but physically the device doesnt run any slower. Or sometimes speed is higher. This code was written by someone else and I am trying to work it better.
V
P.S. There is an overall master While loop.
04-28-2010 01:09 PM
A simple ms wait will do the same.
Felix
04-28-2010 01:22 PM
Sometimes, when the computer hangs up, the time increases and hence accordingly, the number of pulses should be higher to result in the same speed. Will this method ensure that the wait time is always 250ms?
V
04-28-2010 01:25 PM
04-28-2010 01:28 PM
Thanks Ben! Yes, the program is sequential and I am using state machines to modify it. If I got what you said, I should have the timer ticking and at the same time read the counter daqmx within the same loop? If not, would you mind giving me a simple example to take home?
Thanks
04-28-2010 01:45 PM
I didn't focus on the best way to solve 'the problem', but a fix with minimal impact. The loop is spinning at max CPU usage, which is bad. If you want to preserve the existing code, you can place the Tick Count function in an sequence frame between Wait and Pulse Counter.
You can further improve the code using OpenG Timing functions, they just wrap the timing functions with the error wire, so you won't need the sequence. Even nicer, the wait won't be executed in case of an error (which doesn't hurt with 250 ms).
Felix
04-28-2010 02:20 PM
Quick tip: The Flat sequence does nothing but possibly delay a couple of constant reads, remove it and it'll work the same (and look better and possibly run a couple of cpu cycles faster).
05-06-2010 11:53 AM
@ yamaeda what do you mean by coercion dots? Can you explain in simpler terms.? Thanks!
V
05-06-2010 03:53 PM
Is this better than the way it was done before?
V
05-06-2010 04:02 PM
VeeJay wrote:@ yamaeda what do you mean by coercion dots? Can you explain in simpler terms.? Thanks!
V
coercion dots are those red dots on your arithmatic functions. That means you are dividing data of different types. For instance I32 and U8 would give you a coercion dot. What you will want to do is right click your constants, choose representation->[data type]. Either that, or you can go to the numeric-> conversion pallette (i think) thats where it is and convert numbers using the primitives there.