LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Cycling analog output on and off

Solved!
Go to solution
Hello all,
   
I am not a programmer at heart, so please bear with me Smiley Happy I am trying to create a VI that generates a sine wave (analog output) for a certain defined time, followed by a defined period of no output. Also, I would like my VI to repeat this on-off cycle for N amount of times as defined by the user, but I haven't figured out how to do this. I have tried modifying one of the example files (Cont Gen Voltage Wfm-Int Clk- Non Regeneration.vi) to include the timing aspect, but I have noticed that when I run it, the timing seems a bit off, especially in the first on-off cycle. Can anyone let me know why this is happening, and also how to control the number of times my on-off cycles repeat? Thank you in advance.
0 Kudos
Message 1 of 24
(4,542 Views)

Hi choc,

As it happens, I have a piece of code I worte for a previous forum post that I think will do just what you want with a few minor modifications! 

It generates a sinewave of user defined frequency, amplitude, and number of sinewave cycles.  It then appends a pause period defined in seconds.  Currently the code will output the signal continuously, but if you replace the larger while loop with a for loop and set the number of times you want to output the signal you should be able to achieve your goal.

let me know how this goes

Sheela Sujeeun

Applications Engineer
National Instruments UK
Message 2 of 24
(4,500 Views)

Hi SheelaS,

Thank you for your VI, but I can't open it as it was written in LabView 8.5 and I am running 8.2.

0 Kudos
Message 3 of 24
(4,489 Views)

ah, my apologies choc.

here is a copy for 8.2

 

Sheela Sujeeun

Applications Engineer
National Instruments UK
Message 4 of 24
(4,480 Views)

Hi Choc,

Just wondering how you're getting on?

Sheela Sujeeun

Applications Engineer
National Instruments UK
Message 5 of 24
(4,432 Views)

Hi SheelaS,

Sorry for the delay. I have been tinkering with the VI you gave me, adding things that I need. What is frustrating me beyond belief is that I can't figure out why the program is running slowly. For instance, if I enter a 1 second ON - 1 second OFF pattern on the front panel, when I look at the waveform chart (as well as an external oscilloscope connected to the analog output), it seems that what comes out of the AO is a (approximately) 2 second ON - 2 second OFF pattern. Also, entering a frequency of 80 Hz on the front panel results in the produced waveforms not looking 'smooth', but I don't know how to rectify this, as changing the rate on the timing loop from 1000 Hz (default) to 4000 Hz results in an error in the DAQmx Stop VI. Have I modified the VI correctly for an analog output? What could explain the timing issues? I have a USB-6259 (mass-term), and am running LabView 8.2, if that helps.

0 Kudos
Message 6 of 24
(4,423 Views)
Sorry, here is the modified VI.
0 Kudos
Message 7 of 24
(4,411 Views)

Hi Choc,

 

I am afraid you have implemented the AO aspect incorrectly.

The timing loop only works in software, and this is why the front panel is correct.

However, the timing of the loop doesn't give the hardware output any timing.

 

To setup timing in the hardware you need to setup a DAQmx timing vi in your AO task. There are examples on how to do this (and the model in general) for AO generation in the example finder within labview, help>>example finder>>Hardware Input and Output>>DAQmx>>Analog Generation>Voltage>>Cont Gen Voltage Waveform.vi and the timing vi would use the sample clock.

 

I would also recommend removing the timing loop, and using the while loop (as shown in the example) by writing the whole waveform to the Write DAQmx vi buffer outside the loop. 

 

Another point: the non smooth results are caused by the number of samples being too low. It is currently set to the default 1000 (Fs). If you turn this into a control, you can alter it. 

 

let me know how you get on,

Regards

Kind Regards
James Hillman
Applications Engineer 2008 to 2009 National Instruments UK & Ireland
Loughborough University UK - 2006 to 2011
Remember Kudos those who help! 😉
Message 8 of 24
(4,355 Views)

Hi Choc,

 

I was wondering how your getting on, if you want to discuss anything, please post back.

 

Regards

Kind Regards
James Hillman
Applications Engineer 2008 to 2009 National Instruments UK & Ireland
Loughborough University UK - 2006 to 2011
Remember Kudos those who help! 😉
0 Kudos
Message 9 of 24
(4,314 Views)

Hi Hillman,

 

Sorry for the delay. I found a DAQmx tutorial on the NI website, and have been trying to educate myself somewhat by going through it many times (it was made by a "Hillman" working at NI...is that you? Smiley Surprised ) Anyways, I have modifed the VI, and I think it pretty much works! I am having a little problem with the STOP button on the front panel however. I want it so that when I click it while the VI is running, the VI stops immediately (this is very important to me, as the AO is controlling a motor that is attached to human subjects), but as it is now the VI will stop only after the iteration proceeding the one in which I click it. When the AO part of the VI was not incorporated, the way I wired the STOP button worked, but I am hoping you can help me with this.

 

On a related AO note, I have been trying to create another VI that generates a RAMP-HOLD-RAMP signal. I thought it would be simple enough just to modify the current VI I have to incorporate 2 ramp pattern VIs, but while I can see the pattern out on the waveform graph, when I look at the AO signal on an external oscilloscope, its running extremely slow. This confuses me, as I have used the DAQmx timing VI the same way as the ON-OFF VI (which is attached, and it works). Any thoughts?

 

BTW, I have been incredibly impressed at the level of customer support NI offers via their engineers in this forum, as well as in general (I recently bought a DAQ system). Thank you so much....this newbie appreciates all the help he can get!

0 Kudos
Message 10 of 24
(4,258 Views)