Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How to generate Four PWM pulses with NI-6259

I need to generate simultaneously four independent continuous PWM pulse.
The 1st square wave is 50hz with 50% duty cycle.
The 2nd square wave is 100hz with 50% duty cycle.
The 3nd square wave is 185hz with 50% duty cycle.
and the 4th square wave is 128hz with dynamical duty cycle from 5% to 75%.
 
can i do it with NI-6259?
 
BELOW is my initial method:
the Ni-6259 have 4 Analog Output and 2 Counter Analog Output. So I try to generate the 1-3 waveform with AO1-3, thengenerate the 4th dynamical duty waveform with CTR0 .
 
 
0 Kudos
Message 1 of 6
(3,590 Views)

Assuming that your AO output signals are electrically compatible with the devices you're driving with PWM, it should be possible.  You just have to think through your old math lessons on factors and multiples carefully.  (The

1. All the AO channels will share the same update/sample clock.  So you first need to find a sample rate that allows you to generate the desired frequencies.  Bear in mind that at 50% duty cycle, you need to define samples at a minimum of 2x the listed freqs to create both the rising and falling edges.

2. So the minimum candidate freq is 2x 185 = 370 Hz.  That's a cycle time (period) of 2.7027027.... msec.  Here's our first little hitch.  You can't produce an exact 370 Hz sample clock because the period is an infinitely repeating decimal.  Let's see how close we get with a period of 2.70 msec -- ok, that'll be an update rate of 370.37 Hz which is only 0.1 % away from our target.

3. Next question.  If we have a 2.70 msec update interval, can we properly define our 50 hz and 100 hz PWM signals?  Well, following similar reasoning as above, they'll need an update rate that'll divide evenly into 5.00 msec.  At a quick glance, it appears that we'd better pick a sample clock interval of 0.10 msec or 10 kHz.  Then we can define integer #'s of samples to land on either 2.70 msec or 5.00 msec boundaries as needed.  So, for the 185.185 Hz PWM signal, you'll make an alternating pattern of 27 low samples followed by 27 high samples.  For the 100 Hz signal, the pattern will be 50 lows followed by 50 highs.  For the 50 Hz signal, the pattern is 100 lows followed by 100 highs.

4. Next we need to determine a least multiple of all the PWM's period times.  That'll let us define a single buffer which contains exact integer quantities of each PWM.  So, least multiple of 54 samples and 200 samples is 5400 samples.  With a total buffer size of 5400 samples, we'll fit exactly 100 cycles of the 185.185 Hz PWM (each cycle is 27 low and 27 high) and we'll fit exactly 27 cycles of the 50 Hz PWM(each cycle is 100 low and 100 high).  Similarly, we'll get exactly 54 cycles of the 100 Hz PWM.

5. What I'd do (if you can spare another counter).  I'd generate the 185 Hz with the other counter and only generate 50 and 100 Hz with AO.  That'd save all the math above.  All you'd need is a 4 sample repeating buffer for AO.  The 100 Hz channel would go low,high,low,high while the 50 Hz channel would go low,low,high,high.  Then set your AO output rate for 200 Hz.  Done.

-Kevin P.

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 2 of 6
(3,573 Views)
Thank you, Kevin.
But the 4th Output is still not resolved.
0 Kudos
Message 3 of 6
(3,549 Views)
You can refer to the following website:
 
Best wishes!
0 Kudos
Message 4 of 6
(3,538 Views)

Not sure what you mean about the 4th output being "unresolved".  Do you mean the 128 Hz with variable duty cycle?  I didn't discuss that since you seemed to have already solved that part by planning to use CTR0 out.  If you can spare CTR1 out for the 185 Hz output, then your solution for Analog Out gets much simpler as described in the step #5 I outlined.

-Kevin P.

 

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 5 of 6
(3,529 Views)

Thank you, flybear. I've downloaded the VI you recommended and finish the 4th  output with AO. With this method I can output -10~10v square wave, not -5v~5v with crt0.

and thank you, Kevin. I received much help from you. 

but now I have a new problem. I can not output the four AO together with a device(NI 6259). For all I know, man can create only one task with a device. but now I cannot  put the four OUTPUT(the duty of a OUTPUT is variable) into one task. 

In addition,  I want to output two independent-variable-frequency square wave, one is 2hz~235hz, the other is 0~270hz. Can I do it with USB-6259?

0 Kudos
Message 6 of 6
(3,470 Views)