to bwaxing:
My advice : read this great post with exemples, the sine is stored in an array :
http://www.picbasic.co.uk/forum/cont...-DT-interrupts
to bwaxing:
My advice : read this great post with exemples, the sine is stored in an array :
http://www.picbasic.co.uk/forum/cont...-DT-interrupts
Last edited by Ioannis; - 8th May 2011 at 15:32.
thanks for the advice,i read examples from that post and I've not understand how to create the lookup table.From that post sine is stored in the array and i don't understand how the value for a particular step have been determined.for example i want to use 8-bit resolutions (256 steps),how will i determine the value of each step?is there a formula or something?
thanks again.
Last edited by Ioannis; - 8th May 2011 at 15:32.
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:
In each loop the counter value is decremented by one, and when the step value equals 0, the counter is reinizialized to 128.Code:counter=128 loop: duty=sine[counter] PWM pin,duty,cycle counter=counter-1 if counter=0 then counter=128 goto loop
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.
Bookmarks