# Thread: PWM calculated?, not table

1. ## PWM calculated?, not table

I have seen several posts about PWM in order to make a one phase inverter, and most use a long values table calculated to get the sine wave, but what if it calculates the duty value each time?

I have a graph where can be seen some details, but I don't see the way to attach it. There I see I will have to compensate about 1/7 of cicle time due to the calculation time.
-----------------
counter=0
loop:
duty=sine[(counter/100)] ' to compesate decimal handle in above lines PWM
pin,duty,1 ´ PWM pin,duty,cycle at 11,718 Hz
counter=counter+ n ' 127 cicles n=1, n= 127/195= 0.65 -> 65
if counter= 19500 then counter=0
goto loop
-----------------
So, What do you think about it?
L.J.

2. ## Re: PWM calculated?, not table

I would use table.
It is simpler and quicker, than calculating. And once you have one table, you can use same table for 3 phase.
If you want to have less data points for some reason, use linear interpolation to get approximate values between data points.
Melanie wrote post about that. You can get sine value with 2 decimal places, using simple table and linear interpolation.