This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP430F5419A: LED FLICKERING

Expert 1165 points
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);

}

}
}

  • > TBCCR6 = x;
    > P4SEL = BIT2;
    This looks like a mistake. You're enabling TB0.2, but manipulating TB0.6. I would expect the sequence to just halt for 20 seconds (out of 60), but maybe that constitutes a "blink"?
    Anyway replace that first line with this (2 cases) and see whether it's different:
    > TBCCR2 = x;

    Unsolicited: Once you set P4SEL, it stays set, so you can just set it once before the first loop of the sequence.
  • #include <msp430f5419a.h>
    #include <stdio.h>
    #include <math.h>

    void main(void)
    {
    WDTCTL = WDTPW + WDTHOLD; //Disable the Watchdog timer for convenience.
    unsigned int x;

    P4DIR |= BIT2;

    /*** Timer0_A Set-Up ***/
    TBCCR0 = 1000; //Set the period in the Timer B Capture/Compare 0 register to 1000 us.
    TBCCTL2 = 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.

    __enable_interrupt();
    while (1)
    {
    for (x = 10; x < 1000; x = x + 5)
    {
    TBCCR2 = x;
    P4SEL |= BIT2;
    __delay_cycles(50000);
    }

    for (x = 1000; x > 10; x = x - 5)
    {
    TBCCR2 = x;

    __delay_cycles(50000);
    }
    }

    }

    Even if i do the dimming effect on only one led it flickers when it fade out, what could be the problem?
  • I don't have your equipment, but when I constructed something analogous I didn't see any flicker. Maybe my LEDs aren't bright enough.

    That said, you might try using the CLLD bits:
    > TBCCTL2 = OUTMOD_7 | CLLD_1; // Reset/Set, reload at EQU0

    The CLLD feature provides synchronization with the timer, and can avoid anomalous cycles. I wouldn't expect those anomalies to be visible at 1kHz, but doing this should be harmless at worst.

**Attention** This is a public forum