Soft PWM for RGB LEDS
Posted: 05 Dec 2009 21:17
Hello
I want do fade to RGB LEDS with my MCU - PIC12F683
My problem is that :
In the end of the loop - (Duty cycle 0% --> 100%)
the line ends with '1' but jump to low state '0' for a 1 mSec
and from end of the second loop - (Duty cycle 100% --> 0%)
the line ends with '0' but jump to high state '1' for a 1 mSec
All the way every thing is OK but in the end of the loop I got
somthing I don't want
My code :
What can be the problem with line
why the line jump to '0' \ '1' in the end of the loop ??
Thanks
I want do fade to RGB LEDS with my MCU - PIC12F683
My problem is that :
In the end of the loop - (Duty cycle 0% --> 100%)
the line ends with '1' but jump to low state '0' for a 1 mSec
and from end of the second loop - (Duty cycle 100% --> 0%)
the line ends with '0' but jump to high state '1' for a 1 mSec
All the way every thing is OK but in the end of the loop I got
somthing I don't want
My code :
Code: Select all
int i, PWN_COUNTER = 600;
void main(void)
{
ANSEL = 0x00; // Digital I/O
CMCON = 0x07; // Comparator is Off digital IO
OPTION_REG.F7 = 0; // pull-ups are enabled
WPU = 0xFF; // Pull-up enabled
TRISIO = 0x00; // output
while(1)
{
// PWM_FADE_0_TO_1();
for (i = 0; i < PWN_COUNTER; i++)
{
GPIO = 0xff;
Delay(i);
GPIO = 0x00;
Delay(PWN_COUNTER - i);
}
// in the end of loop the port should be '1' - but the line jump to '0' for a 1 msec
Delay_ms(1000);
// PWM_FADE_1_TO_0();
for (i = 0; i < PWN_COUNTER; i++)
{
GPIO = 0xff;
Delay(PWN_COUNTER - i);
GPIO = 0x00;
Delay(i);
}
// in the end of loop the port should be '0' - but the line jump to '1' for a 1 msec
}
} // End of main
void PWM_FADE_0_TO_1(void) // Duty cycle growing 100%
{
for (i = 0; i < PWN_COUNTER; i++)
{
GPIO = 0xff;
Delay(i);
GPIO = 0x00;
Delay(PWN_COUNTER - i);
}
}
void PWM_FADE_1_TO_0(void) // Duty cycle grow smaller 0%
{
for (i = 0; i < PWN_COUNTER; i++)
{
GPIO = 0xff;
Delay(PWN_COUNTER - i);
GPIO = 0x00;
Delay(i);
}
}
why the line jump to '0' \ '1' in the end of the loop ??
Thanks