Low duty cycle PWM and LED brightness

Status
Not open for further replies.
I currently have a 3W RGB LED hooked up to a 16F18326 and tried the following code using just the red LED.
Code:
int16_t bright=0;  
    while(1){
        while(bright<0b0000001111111111){
            if(bright==0)
                bright=1;
            else
                bright=(bright<<1)+1;
            PWM1_LoadDutyValue(bright);
            __delay_ms(250);
        }
        while(bright>0){
            bright>>=1;
            PWM1_LoadDutyValue(bright);
            __delay_ms(250);
        }
    }
You definitely see distinctive steps even when the value is going from 1 to 0 using 10 bits (0.1%).

Mike.
BTW, I used the code configurator for the first time yesterday to setup the chip. Very impressed - quick and easy.
 
Hey, Pommie, so would you say your LED is pretty darn bright for 0.4%? Subjectively speaking, of course.
 
It's hard to tell as it's a 3W LED so anything is bright. However, the final step (0.1% as 10 bit used) is very noticeable.

Mike.
 
Your LED is low enough current to allow sourcing and sinking from pins on the PIC. So you can simply apply power from your PWM pin and select a ground pin connected to a different current-limiting resistor that suits your needs.

This way you get 1-255 duty cycle on a 100 ohm resistor (30 mA), then switch the ground pin to an input, then switch another pin from input to and output low, that is connected to a 1000 ohm (or 22k ohm) resistor (3mA) for 1-255 duty cycle.

In pictures,




Or

 
So you are using a modern 3.3V to 4.1V green LED that is extremely bright. I have a solar garden light like that that lights up my entire neighbourhood at night.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…