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.
Bookmarks