I have seen several posts about PWM in order to make a one phase inverter, (I want to do the pic based model over 16F628A and with a 12 MHz crystal)

and most of them use a long values table calculated to get the sine wave, but what if it calculates the duty value each time?

In the graph can be seen some details,

There I see I will have to compensate about 1/7 of cicle time due to the calculation time.

The core of program:

----------------- picbasic pro:

counter=0

loop:

duty=sin[(counter/100)] ' to compensate decimal handle in above lines PWM

pin,duty,1 ' PWM pin,duty,cycle at 11,718 Hz (the table 9-3 of this pic relates the PWM frequencies for a 20 MHz clock)

counter=counter + n ' 127 cicles n=1, n= 127/195= 0.65 -> n =65 (since it doesn't handle decimals)

if counter= 19500 then counter=0

goto loop

-----------------

So, What do you think about it?

Thank you in advance for your answer

L.J.

and most of them use a long values table calculated to get the sine wave, but what if it calculates the duty value each time?

In the graph can be seen some details,

There I see I will have to compensate about 1/7 of cicle time due to the calculation time.

The core of program:

----------------- picbasic pro:

counter=0

loop:

duty=sin[(counter/100)] ' to compensate decimal handle in above lines PWM

pin,duty,1 ' PWM pin,duty,cycle at 11,718 Hz (the table 9-3 of this pic relates the PWM frequencies for a 20 MHz clock)

counter=counter + n ' 127 cicles n=1, n= 127/195= 0.65 -> n =65 (since it doesn't handle decimals)

if counter= 19500 then counter=0

goto loop

-----------------

So, What do you think about it?

Thank you in advance for your answer

L.J.

## Comment