
Originally Posted by
rmteo
No all you have to do is get it to ramp 0>255>0 and you will be one step closer to your original intent - specifically wanting leds to fade niceley without any flickering.
Oh, I've done that bit (& that wasn't the intent of my little bit of code above....which was simply to help others that may want to explore setting the HPWM registers manually)...
Code:
Main:
decrement:
if duty > 20 then
duty = duty -1
gosub Change_PWM
pause 3
goto decrement
endif
if duty >8 then
duty = duty -1
gosub Change_PWM
pause 15
goto decrement
endif
if duty >1 then
duty = duty -1
gosub Change_PWM
pause 25
goto decrement
endif
pause 100
increment:
if duty <10 then
duty = duty +1
gosub Change_PWM
pause 25
goto increment
endif
if duty <20 then
duty = duty +1
gosub Change_PWM
pause 15
goto increment
endif
if duty <255 then
duty = duty +1
gosub Change_PWM
pause 3
goto increment
endif
goto Main
now I'm sure that's ugly to those who program regularly ....I'm a self confessed 'kludger', but it works (what I found was that simply increasing the duty linearly didn't result in a linear fade .....in particular the lowest 20 of the 8 bit resolution has the most dramatic change in brightness, hence the longer pauses as the duty value approaches zero)
There's no flickering of the LEDS ...but then again I'm not sure there was using HPWM command...this was a mini project to mainly wrap my head around the HPWM registers as I had an inkling that using the HPWM command was doing far more 'under the covers' each time I called the command than I really wanted)
Bookmarks