To download NI software, including the products shown below, visit ni.com/downloads.
Overview
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.
Description
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:
Requirements
Steps to Complete
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.
VI Snippet
**This document has been updated to meet the current required format for the NI Code Exchange.**
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
How can you have a s/w loop of 1 ms when the o/p rate of the 6009 is 150 per second?
LManning,
You are correct. With a software loop of 1ms the output rate is 1000 samples per second which is far too high for the USB-6009. I've made some updates to the example where it instead uses a rate of 100 samples per second.