Sine wave look-up table

1. Sine wave look-up 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 look-up 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},
The PWM duty cycle (in microseconds) is computed from a number above times 0.1. Here comes my problem: the first and the last samples (after and before zero crossing) are smaller than the h-bridge 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? 2. Re: Sine wave look-up 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.phtml •

3. Re: Sine wave look-up table

At voltage zero-crossing 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. 4. Re: Sine wave look-up 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. 5. Re: Sine wave look-up 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) 6. Re: Sine wave look-up 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. 7. Re: Sine wave look-up 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 8. Re: Sine wave look-up 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.

1 members found this post helpful. •

9. Re: Sine wave look-up table Originally Posted by babatundeawe 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
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 look-up 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) look-up 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. •

10. Re: Sine wave look-up 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 !! 11. Re: Sine wave look-up table Originally Posted by Warpspeed 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.
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 look-up 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 h-bridge 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 - - - Originally Posted by Warpspeed 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 !!
Yes, I'm already using a 75 rows look-up table. 12. Re: Sine wave look-up 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 !! 13. Re: Sine wave look-up table Originally Posted by Warpspeed Even at full maximum load, where is all this current going if the output voltage is zero at the zero crossing point ?
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 low-side ones are turned on). 14. Re: Sine wave look-up table

You will need 16 bits to store the table values; perhaps it is easier to scale them to 0-255 (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.

0-255 will be giving you a better than 1% accuracy. It will be a very portable code. 15. Re: Sine wave look-up table

Here comes my problem: the first and the last samples (after and before zero crossing) are smaller than the h-bridge 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?
If you analyze the actual switching behaviour of an inverter which dead time and finite switching speed with varying load, you realize that there's a much more general problem behind the question.

Generally speaking, the commutation time and instantaneous output voltage between turning-off one transistor and turning-on 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. 16. Re: Sine wave look-up 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 0-255. 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. •

17. Re: Sine wave look-up 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 look-up 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. 18. Re: Sine wave look-up 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 duty-cycles, 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 8-bit values is pretty enough. In power electronics we usually cannot reach results so accurate. 19. Re: Sine wave look-up table Originally Posted by andre_teprom you should consider storing sinewave tables for different maximum duty-cycles, in order to allow feedback control for compensation of deviations from the expected value at each point of the curve.
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. 20. Re: Sine wave look-up 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 8-bit resolution. To achieve that you could for instance use the same table used for the reading, but for driving switches devices should interleave samples.

1 members found this post helpful. --[[ ]]--