sinusoidal PWM


Results 1 to 40 of 84

Thread: sinusoidal PWM

Threaded View

  1. #8


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    sine[1]=0
    .
    .
    .
    sine[128]=255

    Excel can do that. The first number is the angle (1->128, like 0-360°), the second is the result of the sine (0->255, like 0-1).

    For each interruption, the command duty=sine[counter] will read the sine value located in the array and the position of this value in the array is determined by the "counter" variable. The result of this command is stored in the "duty" variable.

    A little example:

    Code:
    counter=128
     
    loop:
     
    duty=sine[counter]
     
    PWM pin,duty,cycle
     
    counter=counter-1
    if counter=0 then counter=128
     
    goto loop
    In each loop the counter value is decremented by one, and when the step value equals 0, the counter is reinizialized to 128.

    So in this case, to make a complete sine, it will take 128 loops. If you want a 1Hz sine, you have to repeat this loop exactly 128 times per second.
    Last edited by Ioannis; - 8th May 2011 at 15:33.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts