Finchnixer
- 30th June 2008, 08:01
Hi!
I have only recently started playing around with picbasic and the software-command for pwm. I know people say it's "useless", cause the program hangs while the pwm-command is run, but it's a good place to start. Besides I'm using pic 12f629, without hpwm-module.
Anyways, I'm having problems understanding this bit of code:
loop:
for i = 1 to 256
value = 128 + sin i
pwm PortA.0,value,1
next i
goto loop
This creates a lovely sinus-fading action from off to nice and bright on. But how on earth does it work? Sinus is a value between -1 and +1, and I don't see how that can affect the duty-cycle to such a degree, i.e. from 0 to 255 for completely off and completely on. :-)
Can anyone please shed some light on this, as I can't find any further documentation on the pwm command explaining this.
Thanks!
I have only recently started playing around with picbasic and the software-command for pwm. I know people say it's "useless", cause the program hangs while the pwm-command is run, but it's a good place to start. Besides I'm using pic 12f629, without hpwm-module.
Anyways, I'm having problems understanding this bit of code:
loop:
for i = 1 to 256
value = 128 + sin i
pwm PortA.0,value,1
next i
goto loop
This creates a lovely sinus-fading action from off to nice and bright on. But how on earth does it work? Sinus is a value between -1 and +1, and I don't see how that can affect the duty-cycle to such a degree, i.e. from 0 to 255 for completely off and completely on. :-)
Can anyone please shed some light on this, as I can't find any further documentation on the pwm command explaining this.
Thanks!