From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

CO Pulse Frequency doesn't actually generate 1 Pulse per Second?

Solved!
Go to solution

Hello all,

 

I have a VI layed out in the attachment below.  I seem to have a lack of understanding on how to program this VI here.  I just don't understand what is possibly going wrong.

 

The VI is very basic.  The frequency has been set to 1, and the units are Hertz.  To me, this means that the program should send one pulse to my linear actuator ONCE per second.  I have a simple pulse counter set up in the VI as well to count how many pulses are actually being sent (using the DAQ assistant).  Why is it that when I run the program, I get around 300 pulses per second?  Raising the value makes it goes slightly faster, but lowering the value doesn't really make it go any slower.  There seems to be no real correlation between the input frequency and the actual number of pulses that are sent.

 

I just simply want a program that I can input "1 pulse per second" or however many pulses I want per second and have the card send ONE pulse per second (or however many is input).  Where do I start?  I have a whole program written out and ready to go, but this basic concept here completely eludes me. 

 

Thanks,

James

 

Attached:  1) Picture of concept that I'm completely baffled about  2) VI of my program which said concept is being used in

 

Download All
0 Kudos
Message 1 of 4
(3,364 Views)
Solution
Accepted by topic author jpturne

In the simple image, you are running a loop as fast as possible (there's no timing mechanism).  Inside that loop, you configure the pulse task, start it, then immediately stop and clear it.  You need to create the channel and configure the timing outside the while loop, before it starts, and you need to clear the task outside the loop as well, after the while loop terminates.  Depending on what you want to do, you may be able to move the task start outside the loop as well, or just let the task auto-start.

 

You'll need to restructure your VI a bit.  I can't tell if you want to clear the task after each step, or just change the frequency.  If it's just the frequency, you can use DAQmx Write to change it; if you need to start and stop the task, you'll need some logic to do that once each time you want to restart (you may get an error if you start a task that's already running).  There's no need for "Is Task Done?" since you're not using the output for anything.

 

EDIT: Also, it is always a good idea to put a wait inside loops that execute indefinitely.  Otherwise they will spin as fast as possible, consuming all available processor time and preventing other code from running.  If you configure your counter task properly the loop timing won't affect the pulse rate (because that's done in hardware) but there's no need to run the loop that fast.

Message 2 of 4
(3,361 Views)

Thanks a bunch kind sir.

 

I am curious as to your edit though.  I will put a wait in the loop, but how should that be done?  And for how long do I need to make the wait?  Will that affect the timing (i.e. will my inputted wait time decrease the number of pulses per second?)

 

Thanks again,

James

0 Kudos
Message 3 of 4
(3,343 Views)

The wait time in your loop will have no effect on the pulse timing.  The pulses are generated by the counter hardware, not by your code.  You will get an error if you try to update the duty cycle or frequency more than once in a single period, so your wait should be at least as long as the pulse rate.  For example if you have a pulse frequency of 1Hz and you write new values to the counter more than once in a one-second span you're likely to generate an error (depending on the exact timing of the writes within the pulse period).  The easiest way to wait is to put the standard "Wait (ms)" function in your loop.  It's found in the timing palette and looks like a watch in a pale yellow box.

0 Kudos
Message 4 of 4
(3,339 Views)