08-19-2010 05:11 AM
Hi,
I am using NI USB-6221 card.
Using the C API I need to generate 6 Digital Output channels, with diffrenet frequencies and duty cycles.
To be more precise, 2 are totaly identical, but I need them to be inverted, and the other 4 are similar to one another, but should be shifted in time (I.e. there is a delay between each of the channels).
I used the 2 CO channels that the USB-6221 supports for the first two signals, and it works fine (the two signals are synchronized, and are inverted).
Now I need an additional 4 DO channels for the other square waves.
I saw an articale in the NI web site by JohnP with the title:
The following example shows how one might build and generate a digital waveform using non-regeneration so that you can update frequency and duty cycle on-the-fly with M or X series DAQ devices. The example uses digital output rather than counters to achieve this, so if you need more outputs than counters available this would be a good option (note: on M Series devices an external sample clock must be provided, this can come from one of the counters if desired).
which seems to be exactly what I need, but the examples are for LabView which I don't have.
Can someone explain how to do this with the C functions?
Best Regards,
Danny.
Solved! Go to Solution.
08-19-2010
01:43 PM
- last edited on
11-07-2024
10:00 AM
by
Content Cleaner
Hi Danny,
The important thing to note is that you can clock out arbitrary digital waveforms (up to 1 MHz on the 6221). The actual DAQ programming is quite easy once you have the waveform. My LV Example used LabVIEW's Basic Function Generator VI, then converted it to a Digital Waveform to build the signal for each channel.
The LV functions helped immensely with enabling the waveforms to be updated on-the-fly (the Basic Function Generator keeps track of phase for you).
If you don't need to update on-the-fly, then building the waveform in C shouldn't be too bad. For example:
p0.0 [1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0] *1
p0.1 [0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0] *2
p0.2 [0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1] *4
p0.3 [1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1] *8
[9 9 9 9 9 3 3 3 3 3 6 6 6 6 6 12 12 12 12 12]
The above array of U8 would give you 4 outputs of 50% duty cycle waveforms at Fs/20, shifted 90 degrees from eachother. The lines would be p0.0 through p0.3 (the binary bit of the U8 corresponds to which line goes high).
Best Regards,