Part Number:MSP430F5419A
Tool/software: Code Composer Studio
hello,
I'm doing pulse width modulation for fading effect in RGB led. I'm using a timer B of MSP430f5419A. LEd flickers sometimes when fading out. I'm alternating the color between red, green and blue and I'm doing PWM at 1khz. RGB light works at 12v and I'm using my own supply circuit for it. what could be the problem? below is the code:
#include <msp430f5419a.h>
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; //Disable the Watchdog timer for convenience.
P4DIR |= (BIT2 + BIT3 + BIT6); //Set pin 4.2, 4.3 and 4.6 to the output direction.
/*** Timer B Set-Up ***/
TBCCR0 = 1000; //Set the period in the Timer B Capture/Compare 0 register to 1000 us.
TBCCTL2 = OUTMOD_7 ;
TBCCTL3 = OUTMOD_7;
TBCCTL6 = OUTMOD_7;
TBCTL = TBSSEL_2 + MC_1; //TBSSEL_2 selects SMCLK as the clock source, and MC_1 tells it to count up to the value in TBCCR0.
while (1)
{
int x, z, y;
// fading effect in red light
for (z = 0; z < 1000; z = z + 5)
{
TBCCR6 = z;
P4SEL = BIT6;
__delay_cycles(50000);
}
for (z = 1000; z > 0; z = z - 5)
{
TBCCR6 = z;
P4SEL = BIT6;
__delay_cycles(50000);
}
//fading effect in green light
for (y = 0; y < 1000; y = y + 5)
{
TBCCR3 = y;
P4SEL = BIT3;
__delay_cycles(50000);
}
for (y = 1000; y > 0; y = y - 5)
{
TBCCR3 = y;
P4SEL = BIT3;
__delay_cycles(50000);
}
// fading eefect in blue light
for (x = 0; x < 1000; x = x + 5)
{
TBCCR6 = x;
P4SEL = BIT2;
__delay_cycles(50000);
}
for (x = 1000; x > 0; x = x - 5)
{
TBCCR6 = x;
P4SEL = BIT2;
__delay_cycles(50000);
}
}
}