LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a better way to do this function?

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.

I may not be perfect, but I'm all I got!
0 Kudos
Message 1 of 17
(3,436 Views)

A simple ms wait will do the same.

 

Felix

0 Kudos
Message 2 of 17
(3,429 Views)

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

I may not be perfect, but I'm all I got!
0 Kudos
Message 3 of 17
(3,410 Views)

It's hard t say with just a part of the diagram (you specify there was an overall while loop) but for better result the read counter value function could be in a timed loop set to  250 ms.

 

Ben64

0 Kudos
Message 4 of 17
(3,404 Views)

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

I may not be perfect, but I'm all I got!
0 Kudos
Message 5 of 17
(3,398 Views)

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

0 Kudos
Message 6 of 17
(3,375 Views)

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


You have alot of Coercion dots, change the representation of the constants to remove them (and optimally add a few conversion blocks) so the program dont have to decide and adapt at runtime.

/Y
G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 7 of 17
(3,352 Views)

@ yamaeda what do you mean by coercion dots? Can you explain in simpler terms.? Thanks!

 

V

I may not be perfect, but I'm all I got!
0 Kudos
Message 8 of 17
(3,270 Views)

Is this better than the way it was done before?

 

V

I may not be perfect, but I'm all I got!
0 Kudos
Message 9 of 17
(3,236 Views)

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.

0 Kudos
Message 10 of 17
(3,223 Views)