This example will output a 0-5V ramp in 1.5s, then set the output back to 0V. It is written using DAQmx and designed for a USB-6008 or USB-6009 but will work with any DAQ device that supports software timed analog output.
The desired ramp output is generated by using a Sawtooth waveform with an amplitude of 2.5V, an offset of 2.5V, and a phase of -180 degrees. The default sawtooth waveform with an amplitude of 2.5V goes from 0V to 2.5V, then jumps to -2.5V. Therefore an offset of 2.5V is needed. This changes the output to begin at 2.5, ramp to 5V, and jump down 0V. Adding a phase shift of 180 degrees starts the waveform halfway through, when it is at 0V, and then ramps to 5V. See the images below for what each step looks like.
Default Sawtooth Waveform:
Sawtooth Waveform with Offset:
Sawtooth Waveform with Offset and Phase:
LabVIEW 2012 (or compatible)
DAQmx 12.0 (or compatible)
Steps to Complete
Open the attached VI.
Specify the desired Physical Channel and Min / Max Values (±5V for USB-6008/6009)
Specify the desired Software Loop Time (in millisecond intervals)
Specify the desired waveform signal type, frequency, amplitude, phase and offset.
Specify the desired sampling information. Fs must equal the inverse of the Loop Time.
Run the VI
Additional Information or References
This example was designed to output a ramp from 0 to 5V in 1.5s, therefore the desired parameters are:
Frequency = 1/1.5 = 0.67 Hz
Amplitude = 2.5V
Offset = 2.5V
Phase = -180 degrees
Loop Time = 10ms
Fs = 100 Hz (1/Loop Time)
#s = 151
The number of samples (#s) is one more than the number of samples it takes to ramp up to 5V. This is because the output needs to go back to 0 after finishing the ramp. It takes 1.50 seconds (150 samples @ 100 S/s) to ramp up to 5V, and need one more sample of the waveform to output zero as the last value.
**This document has been updated to meet the current required format for the NI Code Exchange.**
Eric S. AE Specialist | Global Support National Instruments