LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Generating a pulse without a counter

Solved!
Go to solution

I'd like to generate a pulse (or pulse train) using the computer's timing, but I can't seem to tease out how. Of course, I've read through Learn 10 Functions, I've explored the NI examples for Counters and Digital Output, and finally I've read all that I can find on pulse generation in the help section. In addition, I found this post/response helpful, but alas, after all of these sources, I cannot work out how to generate an output pulse (or pulse train) to generate an "on/off" signal for an output module without using, what seems to me to be, an external Counter.

 

In short: I'd like to generate a pulse at 50 Hz with a 50% duty cycle (10ms "High/On", 10ms "Low/Off") continuously. I'd like this signal to output to a NI-9923 to use as a trigger. However, I can't quite tell whether I should be trying to generate a digital output or a counter output. It seems that a counter output requires an external (physical channel) counter of some sort, but a digital output does not. However, I can't really suss out what "data" is actually being written by the digital output (in the examples, it is an array, but that doesn't help me, I think).

 

As a cherry on top, I'd love to use the exact same high/low signal to select a case for another part of the program: deciding which input signal to take the RMS value of. So, if there is a way to accomplish both, that would be super!

 

I've included an image of the suggested VI in the post that I thought was helpful below for convenience. Thank you in advance for any pointers!

0 Kudos
Message 1 of 7
(2,384 Views)
Solution
Accepted by topic author curiositas

Since you wanted "software timed" pulse generation "you" have to handle the timing and pulse generation and hence there is no example.

 

If you think about it, software timed pulse generation is nothing but toggling the Digital output state at precisely timed intervals - but the term "precisely time" term is completely dependent on the OS. If your OS was busy doing something else and missed to change the digital output state, your pulse shape would be incorrect.

 

Anyway, here is an example of implementing software timed pulse generation.

santo_13_0-1639011625878.png

 

VI in 2018 format attached.

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
Message 2 of 7
(2,360 Views)

Of course there's a flip side to the timing.

 

OS timing will introduce a latency and\or jitter. But (when done right) it won't drift. At least not in relation to the OS clock.

 

If the hardware has independent timing, it's clock will not be your OS clock. The HW clock will drift over time. This could be seconds per day. Solving this can be hard and expensive.

 

Note that this problem can safely be ignored 90% of the time, and is in fact ignored 95% of the time 😁.

Message 3 of 7
(2,326 Views)

@curiositas wrote:

As a cherry on top, I'd love to use the exact same high/low signal to select a case for another part of the program: deciding which input signal to take the RMS value of. So, if there is a way to accomplish both, that would be super!


A quick and dirty way would be to use locals in santo_13's solution, and read them in the 2nd loop.

 

Performance will be horrible, as this adds even more jitter and latency. You'd have to toss the beginning and end of the RMS data, as the pulse just isn't accurate.

 

A better way would be to route the pulse output to an input, and read the signal with the other data. This would reduce the jitter and latency to 1 or 2 samples.

Message 4 of 7
(2,325 Views)

@santo_13 wrote:

Since you wanted "software timed" pulse generation "you" have to handle the timing and pulse generation and hence there is no example.

 

If you think about it, software timed pulse generation is nothing but toggling the Digital output state at precisely timed intervals - but the term "precisely time" term is completely dependent on the OS. If your OS was busy doing something else and missed to change the digital output state, your pulse shape would be incorrect.


Thank you for your insight, and especially for your helpful VI example. I'm glad to know that I can time my own pulse, and since I don't need an extreme amount of accuracy, that should be a viable option for me.

 

I'm curious, however... is it possible to perform other tasks during this pulse generation? Unfortunately, I don't have enough equipment with me at the moment to test it, but it seems like the High Resolution Polling Wait VIs might cause my while loop to be waiting, preventing other operations from occurring. I am still grappling with understanding how LV handles its operations (I come from text-based programming).

 

I have attached my current VI in which I have implemented your example. Basically, I'd like to have 2 inputs (say, Input1 and Input2) and 1 output. I would like my VI to continuously do the following: (1) for 10ms, sample Input1, calculate its RMS value and output a High signal to the output, then (2) for 10ms, sample Input2, calculate its RMS value and output a Low signal to the output. Lather, rinse, repeat. Do you think that it is possible to use your example in such a way that I can "simultaneously" read from an input and display its RMS value while outputting part of the pulse signal, or will that require a more complex diagram.

0 Kudos
Message 5 of 7
(2,289 Views)

I'm no DAQ expert, but it seems the NI-9923 is just a connector.

 

You're module might be able to output a PWM.

 

Pulse Width Modulation (PWM) with NI-DAQmx and LabVIEW - National Instruments

 

Doing this in hardware would be a much, much better solution.

Message 6 of 7
(2,281 Views)

@curiositas wrote:

@santo_13 wrote:

Since you wanted "software timed" pulse generation "you" have to handle the timing and pulse generation and hence there is no example.

 

If you think about it, software timed pulse generation is nothing but toggling the Digital output state at precisely timed intervals - but the term "precisely time" term is completely dependent on the OS. If your OS was busy doing something else and missed to change the digital output state, your pulse shape would be incorrect.


Thank you for your insight, and especially for your helpful VI example. I'm glad to know that I can time my own pulse, and since I don't need an extreme amount of accuracy, that should be a viable option for me.

 

I'm curious, however... is it possible to perform other tasks during this pulse generation? Unfortunately, I don't have enough equipment with me at the moment to test it, but it seems like the High Resolution Polling Wait VIs might cause my while loop to be waiting, preventing other operations from occurring. I am still grappling with understanding how LV handles its operations (I come from text-based programming).

 

I have attached my current VI in which I have implemented your example. Basically, I'd like to have 2 inputs (say, Input1 and Input2) and 1 output. I would like my VI to continuously do the following: (1) for 10ms, sample Input1, calculate its RMS value and output a High signal to the output, then (2) for 10ms, sample Input2, calculate its RMS value and output a Low signal to the output. Lather, rinse, repeat. Do you think that it is possible to use your example in such a way that I can "simultaneously" read from an input and display its RMS value while outputting part of the pulse signal, or will that require a more complex diagram.


The waits on the PWM DO will stall the Input. This might cause a buffer overflow.

 

You'd need to make 2 loops. There's really no reason not to.

 

Or program a HW PWM (if possible).

Message 7 of 7
(2,280 Views)