+ Post New Thread
Results 1 to 20 of 20

29th January 2016, 20:32 #1
 Join Date
 Dec 2015
 Posts
 298
 Helped
 7 / 7
 Points
 2,007
 Level
 10
Sine wave lookup table
Hello,I'm in the process of writing the code for a MCU controled sine wave inverter. I'm using a unipolar modulation scheme. The PWM sampling frequency is 16kHz thus there will be 160 samples per half wave (100 Hz), the maximum pulse width being 62.5us. This is an example of the lookup table for an attenuation of 50%:
Code:{ 6, 12, 18, 25, 31, 37, 43, 49, 55, 61, 67, 73, 79, 85, 91, 97, 102, 108, 114, 120, 125, 131, 136, 142, 147, 153, 158, 163, 168, 174, 179, 184, 189, 193, 198, 203, 208, 212, 217, 221, 225, 229, 234, 238, 242, 245, 249, 253, 256, 260, 263, 266, 270, 273, 276, 278, 281, 284, 286, 289, 291, 293, 295, 297, 299, 301, 302, 304, 305, 306, 308, 309, 310, 310, 311, 312, 312, 312, 312, 313, 312, 312, 312, 312, 311, 310, 310, 309, 308, 306, 305, 304, 302, 301, 299, 297, 295, 293, 291, 289, 286, 284, 281, 278, 276, 273, 270, 266, 263, 260, 256, 253, 249, 245, 242, 238, 234, 229, 225, 221, 217, 212, 208, 203, 198, 193, 189, 184, 179, 174, 168, 163, 158, 153, 147, 142, 136, 131, 125, 120, 114, 108, 102, 97, 91, 85, 79, 73, 67, 61, 55, 49, 43, 37, 31, 25, 18, 12, 6, 0},

29th January 2016, 21:12 #2
 Join Date
 May 2015
 Location
 Melbourne, Australia
 Posts
 2,213
 Helped
 754 / 754
 Points
 13,005
 Level
 27
Re: Sine wave lookup table
Go ahead and do it that way, it will work fine.
All of the samples are only very close approximations anyway, very few will work out to exact integer values.
As you will be filtering the PWM output, all the slight sample to sample variations should just about average out, and the results will be perfectly o/k.
Here is a very handy sine wave lookup table calculator for producing lookup tables of any size:
http://www.daycounter.com/Calculator...lculator.phtmlCheers, Tony.

Advertisement

29th January 2016, 22:05 #3
 Join Date
 Dec 2015
 Posts
 298
 Helped
 7 / 7
 Points
 2,007
 Level
 10
Re: Sine wave lookup table
At voltage zerocrossing points, the current has the maximum value thus I was afraid of large current spikes if I turn on/off mosfets for just a short period (100nS or so).
I was also concerning about core saturation due to output DC component (if I'm going to modify the sine wave shape).
Thank you very much for your advices. I'll give it a try using the modified values.

29th January 2016, 22:10 #4
 Join Date
 May 2015
 Location
 Melbourne, Australia
 Posts
 2,213
 Helped
 754 / 754
 Points
 13,005
 Level
 27
Re: Sine wave lookup table
Both voltage and current should be minimum at the zero crossing point (with a resistive load).
Even with a reactive load, the current should not be very high.Cheers, Tony.

29th January 2016, 22:35 #5
 Join Date
 Dec 2015
 Posts
 298
 Helped
 7 / 7
 Points
 2,007
 Level
 10
Re: Sine wave lookup table
The load is a low frequency transformer thus its primary inductance is fully "loaded" at zero crossing.
(I'm talking about a +1000W sine wave inverter)

29th January 2016, 22:51 #6
 Join Date
 May 2015
 Location
 Melbourne, Australia
 Posts
 2,213
 Helped
 754 / 754
 Points
 13,005
 Level
 27
Re: Sine wave lookup table
Primary inductance of your low frequency transformer at zero load should hopefully be fairly high, and the inductive reactance at the PWM switching frequency much higher than that again.
Cheers, Tony.

30th January 2016, 03:53 #7
 Join Date
 Apr 2007
 Location
 Nigeria
 Posts
 244
 Helped
 16 / 16
 Points
 3,191
 Level
 13
Re: Sine wave lookup table
Hi, sorry to jump in your post. but i would like to know how to implement feedback voltage compensation by modifying the sine look up table.
thanks

30th January 2016, 05:27 #8
 Join Date
 May 2015
 Location
 Melbourne, Australia
 Posts
 2,213
 Helped
 754 / 754
 Points
 13,005
 Level
 27
Re: Sine wave lookup table
You would first need to store the original calculated fixed lookup table into read only memory, so its always there.
Next thing would be to make a copy of that fixed lookup table into a block of ram memory and use that to start up the inverter initially.
The ram version can then be modified gradually (bit by bit) to make all the values either slightly larger or slightly smaller, depending if you wish to increase or decrease the output amplitude.
That can be done by taking each original value from read only memory, and multiplying it by a constant to make it either larger or smaller in proportion.Cheers, Tony.
1 members found this post helpful.

Advertisement

30th January 2016, 05:36 #9
 Join Date
 Dec 2015
 Posts
 298
 Helped
 7 / 7
 Points
 2,007
 Level
 10
Re: Sine wave lookup table
You're welcome! I've just post a quote from a Texas Instruments application note about this procedure in this thread (post #17).
You could search online for the full content of that app note ("800VA Pure Sine Wave Inverter’s Reference Design"). Basically, they are dinamically multiplying the values from the lookup table by a factor to get a regulated voltage output.
We could further discuss the matter in the above mentioned thread (or here, as you wish).
   Updated   
@Warpspeed, we did post simultaneously. ;)
You're right about that procedure. A convenient variant could be to store in your code/RAM an extended (multidimensional array) lookup table (with all those attenuated values) then read them directly at run time.
A multiplying operation could be time (CPU clocks) consuming at run time.

Advertisement

30th January 2016, 05:44 #10
 Join Date
 May 2015
 Location
 Melbourne, Australia
 Posts
 2,213
 Helped
 754 / 754
 Points
 13,005
 Level
 27
Re: Sine wave lookup table
The reference lookup table you use to start off with needs to be slightly small.
If your peak value is originally set to (say) FF, you cannot easily make it larger.
The other thing is, multiplication can be slow, and doing it for every switching cycle can use up a huge proportion of processor time, so its better to construct a second lookup table that then only has to be read. Its much faster that way !!Cheers, Tony.

30th January 2016, 05:50 #11
 Join Date
 Dec 2015
 Posts
 298
 Helped
 7 / 7
 Points
 2,007
 Level
 10
Re: Sine wave lookup table
I'm sure you have more knowledges than me but we're lost in terms, I believe. I was not talking about zero load current but zero crossing voltage level.
For example, I start the inverter at zero load current but full voltage (90 degree). As the lookup table advance, the voltage across primary inductance decrease but the current it's increasing. It reach a maximum at voltage zero crossing, when I switch the hbridge active leg. Now the (reversed) voltage start to rise and the primary inductor current it's getting lower. When the voltage reaches the (negative) peak value, the inductor current will be zero.
Do you agree with that?
   Updated   
Yes, I'm already using a 75 rows lookup table.

30th January 2016, 06:02 #12
 Join Date
 May 2015
 Location
 Melbourne, Australia
 Posts
 2,213
 Helped
 754 / 754
 Points
 13,005
 Level
 27
Re: Sine wave lookup table
Even at full maximum load, where is all this current going if the output voltage is zero at the zero crossing point ?
Are you driving a pure inductive load to 1,000 Var where its all reactive power ?
I hope not, because your PWM is going to have a heart attack.
Just stop and think for a moment. Output voltage at maximum, current zero.
Is the PWM at maximum or minimum duty cycle ?
Now at zero output voltage and maximum peak output current, is the PWM at maximum or minimum ?
It cannot be both !!Cheers, Tony.

30th January 2016, 06:15 #13
 Join Date
 Dec 2015
 Posts
 298
 Helped
 7 / 7
 Points
 2,007
 Level
 10
Re: Sine wave lookup table
The "zero crossing" point is refering to the filtered 50 Hz output voltage. The inductor (transformer primary winding) is driven by the PWM signal with sharp pulses (variable duty cycle).
At that "zero crossing", the inductor (that already stores that accumulated energy) current is flowing through the body diodes or mosfets (when both of lowside ones are turned on).

30th January 2016, 09:05 #14
 Join Date
 Nov 2012
 Posts
 3,147
 Helped
 777 / 777
 Points
 17,223
 Level
 31
Re: Sine wave lookup table
You will need 16 bits to store the table values; perhaps it is easier to scale them to 0255 (equally spaced) so that you can use a 8 bit uint table. Your calculations will be both simpler and faster. For values that are smaller than 3, put them equal to zero.
0255 will be giving you a better than 1% accuracy. It will be a very portable code.

30th January 2016, 12:17 #15
 Join Date
 Jan 2008
 Location
 Bochum, Germany
 Posts
 45,436
 Helped
 13823 / 13823
 Points
 260,175
 Level
 100
Re: Sine wave lookup table
Here comes my problem: the first and the last samples (after and before zero crossing) are smaller than the hbridge deadtime (1uS) thus there should be a very narrowed pulse or no pulse at all (once again, for the samples around zero crossing).What should I do to overcome this situation? May I increase those samples values from 6 to 10, to get a pulse duration of at least 1us? Would that affect the 50 Hz signal?
Generally speaking, the commutation time and instantaneous output voltage between turningoff one transistor and turningon the other will depend on the polarity and to some extent also on the magnitude of output current. This causes a systematical output voltage error which can be corrected under circumstances, but only if either the output current or the commutation time is monitored. Just offsetting the table entries won't work.

30th January 2016, 13:31 #16
 Join Date
 Nov 2012
 Posts
 3,147
 Helped
 777 / 777
 Points
 17,223
 Level
 31
Re: Sine wave lookup table
You need to have a plan for the software side too!
Sine look up table need not be so big. 32 points are good enough. You can increase to 128 points later.
I think 8 bit values are good enough. All values will be 0255. Can be stored as uint.
Decide a switching frequency. Software will appear clean if you select a frequency 2^n.
Decide a sample frequency. You will be reading the feedback voltage so often. I suggest 2^m where m
Decide the scale factor. This will be the integer that will take the value from the look up table and convert to pulse width.
Decide the correction factor: start with a linear correction for small errors. You can use quadratic terms later.
Decide the dead time factor. Do not forget to keep the headroom.
Of course it will take some time. It is simple but not trivial.

Advertisement

30th January 2016, 14:12 #17
 Join Date
 Dec 2015
 Posts
 298
 Helped
 7 / 7
 Points
 2,007
 Level
 10
Re: Sine wave lookup table
I'm using some interrupt routines where I can set the delay (duty cycle) in microseconds, that's why is more convenient for me to store those larger values in the lookup table.
As I have enough memory available, I'm using a 75 rows X 160 cols array to store (uint16) the duty cycle values (from 0 to 620). It might not look like a very optimized code but it's running much faster.

30th January 2016, 14:20 #18
 Join Date
 Nov 2006
 Location
 Brazil
 Posts
 8,858
 Helped
 1114 / 1114
 Points
 29,619
 Level
 41
 Blog Entries
 9
Re: Sine wave lookup table
Once you have enough memory, as FvM mentioned, the load factor would interfere on the generated output, therefore in my oppinion you should consider storing sinewave tables for different maximum dutycycles, in order to allow feedback control for compensation of deviations from the expected value at each point of the curve. In addition, as c_mitra has mentioned, just 8bit values is pretty enough. In power electronics we usually cannot reach results so accurate.

Part of the world that you live in, You are the part that you're giving ( Renaissance )

30th January 2016, 19:00 #19
 Join Date
 Dec 2015
 Posts
 298
 Helped
 7 / 7
 Points
 2,007
 Level
 10
Re: Sine wave lookup table
Sorry, I wasn't clear enough: that's why I have those 75 rows. One single row stores 160 samples (steps) for a half wave (10 ms). For each row I increased those values with 1% thus I could generate the sine wave with an attenuation range from 25% to 100% by reading the corresponding row.

30th January 2016, 19:57 #20
 Join Date
 Nov 2006
 Location
 Brazil
 Posts
 8,858
 Helped
 1114 / 1114
 Points
 29,619
 Level
 41
 Blog Entries
 9
Re: Sine wave lookup table
As yourself had informed at the beggining of this thread, the level of accuracy is lying within the magnitude of delays of the driver itself, and may also even suffer interference from other circuits.
I believe that an alternative deed to overcome this situation, is you read the output in process control closed loop using an accuracy of 1% ( just acting on the driver if the error exceeds determined threshold ) but in the wave generation use an only 8bit resolution. To achieve that you could for instance use the same table used for the reading, but for driving switches devices should interleave samples.
Part of the world that you live in, You are the part that you're giving ( Renaissance )
1 members found this post helpful.
+ Post New Thread
Please login