A slicker way to be constantly changing the duty cycle?


Results 1 to 15 of 15

Threaded View

  1. #15
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: A slicker way to be constantly changing the duty cycle?

    Quote Originally Posted by rmteo View Post
    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)
    Last edited by HankMcSpank; - 24th April 2011 at 22:26.

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