0
votes

I'm trying to write code in C to fade an off-board LED using PWM and the MSP430f2618. I can get the LED to turn on but it stays at full intensity. I am trying to read in an array of frequency values and fade the LED based on the frequency values.

int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;   // Stop watchdog timer
    int array_size = 0, i = 0, delay = 0;
    double frequency[50] = {0.0};

    array_size = sizeof(frequency);

    frequency [0] = 60.0;

    for (i = 1; i < array_size; i++)
    {
        if (frequency[i - 1] < 61)
        {
            frequency[i] = frequency[i-1] + 0.1;
        }
        else
        {
            frequency[i] = 60.0;
        }
    }

    P4OUT &= 0;
    P4DIR |= (BIT1 + BIT2); //P4.1 and P4.2 output
    P4SEL &= ~(BIT1 + BIT2);    //P4.1 and P4.2 TBx options, timer select
    TBCCR0 = 512-1;

    TBCCTL1 = OUTMOD_7;
    TBCCTL2 = OUTMOD_7;

    for (i = 0; i < array_size; i++)
    {
        P4OUT &= 0;
        if ((frequency[i] < 60.2) && (frequency[i] >=60.0))
        {
            //TBCCR1 = 3200;
            TBCCR1 = 384;
        }

        else if ((frequency[i] < 60.4) && (frequency[i] >=60.2))
        {
            //TBCCR1 = 2560;
            TBCCR1 = 256;
        }

        else if ((frequency[i] < 60.6) && (frequency[i] >=60.4))
        {
            //TBCCR1 = 1920;
            TBCCR1 = 128;
        }

        else if ((frequency[i] < 60.8) && (frequency[i] >=60.6))
        {
            //TBCCR1 = 1280;
            TBCCR1 = 64;
        }

        else if ((frequency[i] < 61) && (frequency[i] >=60.8))
        {
            //TBCCR1 = 640;
            TBCCR1 = 32;
        }

        else
        {
            TBCCR2 = 512;
        }

        P4OUT ^= BIT1;
        for (delay = 0; delay < 32000; delay++);

    }
    TBCTL = TBSSEL_2 + MC_1;                  // ACLK, up mode



    __bis_SR_register(LPM0_bits);             // Enter LPM3
    return 0;
}
1

1 Answers

0
votes

The timer is not running until you start it by setting the MC field. That initialization must be done at the beginning.