Author Topic: To Calculate PWM instead of a table  (Read 12 times)

ljille

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
To Calculate PWM instead of a table
« on: August 09, 2019, 08:48:29 AM »
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?   

It's though for 16F628A because it has PWM capability and I have one now.    12 MHz because I have one now.  Table 9-3 of pic gives us a 20 MHz PWM option clock but I converted to 12 MHz: 11,718

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. 
-----------------     for picbasic pro
counter=0 
loop: 
duty=sin[(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?  Do it give us a sinus PWM?
Thank you in advance for your answer
L.J. 

 

Sitemap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71