Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How best to vary pwm signal on four different channels independently

I am using the 7615 DAQ card.  What I would like to do is have four separate 50% duty cycle analog outputs AND be able to vary the frequency of each independantly.  I figured out how to created a task using Dev1/AO0:3, and by changing the sampling rate, I was easily able to change the  frequency, but only to all four simultaneously.  The next thing I tried was to manually create pulses using windows times... as expected, that was a disaster.  Even using the NI hi res timer was better, but didn't work correctly either.  Is there ANY way to control the frequency of four anolog outputs indepentantly?
TIA
Eric
0 Kudos
Message 1 of 6
(2,680 Views)
Eric,

Unfortunately, all DACs on this device are clocked with the same signal. It is not possible to run them at different rates. What sort of output frequencies are you trying to achieve? I have an idea which I think may work. You could create continuous voltage output channels of a certain (large) buffer size, running at the highest rate possible (650kS/s for 4 channels). In this buffer, you would repeat a certain number of cycles of your waveform (integer division). Whenever you wish to update the frequency of the output, you could rebuild your dataset, changing the number of cycles in the buffer of a single channel. Then, just call a DAQmx write with this new dataset. Does this sound like an option? Please let us know if you need any help implementing it!

Regards,
Ryan Verret
Product Marketing Engineer
Signal Generators
National Instruments
0 Kudos
Message 2 of 6
(2,662 Views)
Thanks for the reply Ryan,
I need frequencies from zero to only 1000 hz.  I think I may have tried what you were describing, but I couldn't get it to work correctly.  My idea was to populate a buffer with a series of waves, and as I needed to increase the frequency, populate a new buffer with an extra wave in it, etc..  Then use that buffer.  What I found was that I had to stop the task, clear it, and then rebuild the chanel, load the buffer, set the sampling rate, and start the task .  This lead to a very chopped up signal as I tried to vary it.  Is there a way to modify the buffer while the task is running?
What I am going to try to do is conrol three of the anolog outputs by changing the sampling rate, and create the fourth pwm signal with a counter ouput. I can create/set/run/kill the counter dynamically with new frequencies.  The resulting output isn't the smoothest, but it may work. What I am trying to do is simulate the four wheel speed sensors of a vehicle during an ABS stop where one wheel speed suddenly drops, as well as a traction control event where one wheel speed ramps up much faster than the other three.

Is paragraph 1 what you were describing?
Eric

0 Kudos
Message 3 of 6
(2,655 Views)
Eric,

Looks like you were almost there Smiley Tongue. This is exactly what I was describing, though to do it properly, it requires knowledge of some of the finer points of DAQmx programming. Actually, if 3 of you PWM signals are going to be identical, you could either use the 2nd counter on your board and wire it to 3 terminals on your device, or you could just control the update rate of your ADC. For instance, your data buffer could be [0, 1], set for continuous generation, and just change the clock to your ADC to vary the frequency. This can be done by setting the "Sample Clock Rate" frequency, even while the task is running.

As for the counters, just set up a continous pulse output (frequency) and start it. You can then control the frequency with a counter write (DAQmxWriteCtrFreq, if I recall). Please let us know if you need any additional help.

Regards,
Ryan Verret
Product Marketing Engineer
Signal Generators
National Instruments
0 Kudos
Message 4 of 6
(2,649 Views)
Isn't DAQmxWriteCtrFreq only used for the AO?  I think I have things figured out, except for how to smoothly change the frequency on the counter output.  Here is a text clip of what I did for a test case to ramp the frequence up to 1000 hz.
Is there any way to alter the frequency without killing the task first and interrupting the wave shape?  I next attempt may be to try to set the number of samples to a finite number, wait when the task is complete, then go through the process of recreating the task with a new frequencey, waiting... etc..

    while(value < 1000)
    {
       Sleep(100);
       CHECK_FOR_MESSAGES;
       value += 20;
       DAQmxStopTask(taskHandle2);
       DAQmxClearTask(taskHandle2);
       (DAQmxCreateTask("",&taskHandle2));
       (DAQmxCreateCOPulseChanFreq(taskHandle2,"Dev1/ctr0","",DAQmx_Val_Hz,DAQmx_Val_Low,0.0,value ,0.50));
       (DAQmxCfgImplicitTiming(taskHandle2,DAQmx_Val_ContSamps,1000));
       (DAQmxStartTask(taskHandle2));
    }

Thank for you help.  It certainly is appreciated!
Regards,
Eric

0 Kudos
Message 5 of 6
(2,637 Views)
Eric,

Actually, on a counter pulse output, you can change the frequency with DAQmxWriteCtrFreq. Just set the task up, then use this function to change the frequency. Note that this is a software-timed change. Also, you can only update the frequency once per period, so if your counter is operating at a low frequency, make sure that you do not make calls to this function too often. More info on this, and all other DAQmx C functions, can be found in the NI-DAQmx C Reference Help. It should be located in Start->Programs->National Instruments->NI-DAQ. Please let me know if you have any more questions.

Hope this helps,
Ryan Verret
Product Marketing Engineer
Signal Generators
National Instruments
0 Kudos
Message 6 of 6
(2,632 Views)