Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How can i generate SPWM array values for a specified samples

thannara123

Advanced Member level 5
Advanced Member level 5
Joined
Jan 7, 2010
Messages
1,597
Helped
122
Reputation
244
Reaction score
116
Trophy points
1,353
Activity points
10,551
Hi ,

How do I generate a SPWM (Sine Pulse Width Modulation) lookup table for a half-wave (10 milliseconds duration)?
I need to compare a 50 Hz sine wave (with a given amplitude) with a triangular or sawtooth wave.
I want the output to be an array of PWM values.
Could someone provide guidance or an example code for this?
 
Each step (phase position) of the waveform has a sine value associated with it. Generate each value (length of each pulse) by multiplying its sine by your chosen maximum (peak amplitude) length.

Example, sine waveform at 45 degrees has sine .707. Calculate pulse length at 45 de. by multiplying .707 by whatever is your length at 90 degrees.
 
Yes sir thanks for the reply ,
PWM-strategy-a-Sine-and-triangular-waveform-b-S1-S4-PWM-pulses-c-S3-S2-PWM-Pulses.jpg

How find the T1 , in practically i tried it to catch out the values by using Pspice as follows
g.png


It too much hard to findout mannually how to geneerate it with code or any other techniques ?

For example

To compare the 50 Hz sine wave and the 20 kHz triangular wave over a duration of 10 milliseconds with a
sample interval of 100 microseconds (0.1 ms),
the steps are as follows
sinewave = .8sin(2pi*50*t)
triangular wave = 20khz -1v to 1v
Compare the values of the sine wave and triangular wave for each sample.
If the sine wave is greater than the triangular wave during the 100 microseconds of
each sample, store the duration for which the sine wave stays greater.
The result will be an array of 200 samples (since 10 ms/100 µs = 200).
For each sample (every 100 µs), check how long the sine wave remains greater
than the triangular wave during that interval.
The duration for which the sine wave is greater than the triangular wave (out of 100 µs) will be stored.
,
.

I know its hard to understand what i am saying Sorry for my bad english ,
Any way, i am lookking to generate a LUT in a simple way with more than 500 samples (mannualy it is hard )

can i generete the LUT by using excel ?
 
Last edited:
By using math (sine values) it does exactly the same thing as electronic circuitry (via superimposed waveforms) does.

There is a subtle difference in whether you wish SPWM to include both polarities or whether one polarity only.

The scope trace below tells the story. For every location on the X scale (aka time scale), notice where the sawtooth intersects the sine wave and forms a triangle which automatically geometrically by the triangle's width indicates how far up the Y scale the sine is at that location. Timescale is 10 mSec.
This plot applies to one polarity only.
This plot is not the same as a plot that includes both polarities. Closer examination of a circuit's operation is needed to determine which SPWM values to use, whether the kind below or the kind in post #3.

geometric calculation of SPWM superimposing sine-n-sawtooh waveforms.png
 
Last edited:
I use "LibreOffice Calc" but it is almost identical to Excel.
Your image seems to demonstrate what you want, which I think is to simulate PWM by finding the crossing points of a sine signal with a triangle wave.

If you start with a blank spreadsheet, put the first time in the first cell (A1) then in the one below it put "=A1+x" where x is your time increment, you can then highlight cell A2 and drag down the 'A' column and it will automatically add the time increment to each cell as you move over it.

Then put "=sin(A1)" at the top of the next column (cell B1) and it will fill in the sine value of the number in cell A1. Highlight B1 and drag it down the column, it will fill in the sine values for the entry next to it in column A.

The next column 'C' is a little different because there is no formula to generate a triangle wave so you have to add your own. It isn't difficult and there are several methods. Probably the simplest is to use the 'MOD' (modulus) command to find the triangle points and then alternatively add or subtract to get the rising or falling slopes.

You can do the same to generate a square wave but just alternate fixed figures at the edges.

To simulate PWM, add another column and subtract the sine and triangle figures to see which is greater then make the result high or zero.

Brian.
 
I made the sinewave (50Hz ,.4v) and triangular wave (20Khz,.5v)
d.png


I need the comparission

Now need to compare . I dont know how exactly take the data
 
Last edited:
if you mean "how do I show which is greater", in other words what the PWM waveform would look like, use:
"=if(C1 > B1),0.5,0)"
meaning "if the sine value is greater than the triangle value, the result is 0.5, otherwise the result is zero".
You may have to reverse the comparison for negative values if you are using them.

Brian.
 

LaTeX Commands Quick-Menu:

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top