Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

SPWM using digital I/o

I m trying to do SPWM(Sinusoidal pulse width modulation ) in Labview using digital I/o .But i m getting an error saying external source required.Plz can anybody suggest smething ,I m attaching my VI for reference

0 Kudos
Message 1 of 7
(4,462 Views)

Take a look at the attached and see if it does what you want.  It uses a counter and varies the duty cycle on the fly to generate the PWM.  Fastest update rate for me was about 20 ms (50 Hz).

 

Make sure you set the frequency to 1000 Hz before you start (pulse freq).  To get your 2 Hz sinusoid modulation you will have to set the number of samples for the sinusoid to 25.

 

 

Randall Pursley
0 Kudos
Message 2 of 7
(4,444 Views)

Sir,

   Thank u so much ,the code is working properly .Could u jst tell wht is the actual logic behind this in short ,i m enable to understand why 0.5 is added to o/p of sinusoidal and all.How to change the duty ratio and wht is relation between frequecy and no. of samples,is it smething related to normalized freq.

0 Kudos
Message 3 of 7
(4,434 Views)

When writing this code, I found that the loop would not run faster than about every 20 ms.  This sets your update rate to a maximum of 50 samples/second.  The ratio between this rate and the number of points in your sinusoid sets the frequency of the sinusoid (i.e. (50 samples/second) / (25 samples) = 2 /second (or 2 Hz)).  So if you wanted a 1 Hz sinusoid, you would set the number of samples to 50, etc.

 

The duty cycle input ranges from a number almost 0 to a number almost 1 and generates an error if it is out of this range.  By setting the amplitude to 0.49 and setting the offset to 0.5, the sinusoid output range will be from 0.01 to 0.99, which will translate straight to 1% to 99% duty cycle.  Reducing the amplitude will just reduce the range that the duty cycle will change.  0.45 will probably work pretty will (5% to 95%).

 

Sorry I didn't make it more clear.

Randall Pursley
0 Kudos
Message 4 of 7
(4,424 Views)

Sir, 

   Thankz a lot,i got how the freq and samples are related .But i have doubt regarding that offset part,and the duty ratio.How to change the duty ratio i.e how to change the amplitude of the sine wave irrespective of the change in the range of duty ratio.Do u mean change in range implies change in duty ratio.Awaiting a response from ur side.

0 Kudos
Message 5 of 7
(4,416 Views)

The amplitude of the sinusoid determines the range that the duty cycle can change and the offset would be the middle of that range.

 

For example, if you wanted the duty cycle to go from 20% to 80%, the amplitude of the sinusoid would be 0.30 and the offset would be 0.50.

 

If you wanted the duty cycle to go from 40% to 80%, the amplitude of the sinusoid would be 0.20 and the offset would be 0.60.

 

Amplitude = (DCmax - DCmin)/(2*100)

 

Offset = (DCmax + DCmin)/(2*100)

Randall Pursley
0 Kudos
Message 6 of 7
(4,413 Views)

Sir, 

     I need the frequency of switching to be 2Khz that would be the counter frequency ,while the frequency of the sine wave to be 50Hz that would be fundamental frequency of the output PWM pulses.I tried it with no.of samples/second=50 and no.of samples =1 ,but i m nt getting desired output.Plz suggest smething 

Thanking You

0 Kudos
Message 7 of 7
(4,359 Views)