• AVR Freaks

Hot!Duty Cycle Subroutine Gamma Corrected

Author
Designer
Super Member
  • Total Posts : 454
  • Reward points : 0
  • Joined: 2007/11/20 20:28:41
  • Location: 0
  • Status: offline
2019/11/18 11:50:30 (permalink)
0

Duty Cycle Subroutine Gamma Corrected

I'm implementing a gamma corrected duty cycle routine (instead of a gamma lookup table) due to lack of program memory space available on my PIC12F629 I do not have enough space "64 plus" lines  of a "lookup table" to be inserted.
The below formula working nicely in computer software program.But I need to implent it to a small PIC with assembly language to find out the duty cycle values. Can this be simplified?
 
Gamma Factor = 1
PWM Steps= 160
Gamma Steps = 64 Levels
i = 0 to 63
 
Duty Cycle = INT(PWM Steps^((i+1)/Gamma Steps)+ Gamma Factor) 
#1

8 Replies Related Threads

    1and0
    Access is Denied
    • Total Posts : 10005
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Duty Cycle Subroutine Gamma Corrected 2019/11/18 12:19:40 (permalink)
    +2 (2)
    Designer
    I'm implementing a gamma corrected duty cycle routine (instead of a gamma lookup table) due to lack of program memory space available on my PIC12F629 I do not have enough space "64 plus" lines  of a "lookup table" to be inserted.
    The below formula working nicely in computer software program.But I need to implent it to a small PIC with assembly language to find out the duty cycle values. Can this be simplified?
     
    Gamma Factor = 1
    PWM Steps= 160
    Gamma Steps = 64 Levels
    i = 0 to 63
     
    Duty Cycle = INT(PWM Steps^((i+1)/Gamma Steps)+ Gamma Factor) 

    Is that ^ a power operator or the XOR operator? At first glance, assuming it's a power operator, that formula most likely will take more than 64 words of program memory. That being said, I'm willing to bet your assembly code can be optimized to get enough memory for that lookup table. ;)  Or use a PIC with more memory.
     
     
    #2
    Designer
    Super Member
    • Total Posts : 454
    • Reward points : 0
    • Joined: 2007/11/20 20:28:41
    • Location: 0
    • Status: offline
    Re: Duty Cycle Subroutine Gamma Corrected 2019/11/19 00:41:40 (permalink)
    0
    You got it.I can easily have space for a 32 level gamma table.But in lower duty cycles the LEDs gets some noticeable flicker due to lack of dimming steps.That is why I shifted it to a 64 level table to make smooth fades.
     
    The above formula, the power into XX part (^) needs bigger multiplication routine with floating points which will require more space than my complete 64 level table.
     
    This is for WS2811 pixel LED lights.My maximum brightness value is 160 & lowest is 1.I need to dim them smoothly.
    post edited by Designer - 2019/11/19 00:42:42
    #3
    1and0
    Access is Denied
    • Total Posts : 10005
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Duty Cycle Subroutine Gamma Corrected 2019/11/19 04:14:35 (permalink)
    0
    As I've said, start going over your assembly code and optimizing it to free some program memory space.
    #4
    jack@kksound
    code tags!
    • Total Posts : 3221
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: Duty Cycle Subroutine Gamma Corrected 2019/11/19 09:00:27 (permalink)
    +2 (2)
    Maybe linear interpolation between the 32 table values to get 64?
    #5
    1and0
    Access is Denied
    • Total Posts : 10005
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Duty Cycle Subroutine Gamma Corrected 2019/11/19 10:14:24 (permalink)
    +1 (1)
    It still requires program memory space to calculate the interpolation. ;)
    #6
    jack@kksound
    code tags!
    • Total Posts : 3221
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: Duty Cycle Subroutine Gamma Corrected 2019/11/19 12:20:51 (permalink)
    0
    1and0
    It still requires program memory space to calculate the interpolation. ;)


    Of course but possibly less then the larger table? Not sure as I have not tried it but was just a thought...
    #7
    1and0
    Access is Denied
    • Total Posts : 10005
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Duty Cycle Subroutine Gamma Corrected 2019/11/19 12:29:18 (permalink)
    0
    jack@kksound
     
    Of course but possibly less then the larger table? Not sure as I have not tried it but was just a thought...

    Possibly yes.
    #8
    bitdoctor
    Starting Member
    • Total Posts : 26
    • Reward points : 0
    • Joined: 2019/10/11 06:10:09
    • Location: 0
    • Status: offline
    Re: Duty Cycle Subroutine Gamma Corrected 2019/11/22 13:56:06 (permalink)
    0
    If you choose a gamma = 2, a simple square will give you a very decent LED gamma correction:
    // provide LED gamma correction
    uint8_t LED_gamma(uint8_t intensity) {
     unsigned int result = (intensity * intensity) >> 8;
     return (uint8_t) result;
    }

    It's running on my desk as we speak, and it looks great.
    #9
    Jump to:
    © 2019 APG vNext Commercial Version 4.5