Tool/software: Code Composer Studio
Hello, i'm trying to brigtness in led while doing the dimming effect. for so i a'm using delay cycles. but the code get stuck at __delay_cycles() while getting an interrupt. below is the code: what could be the problem?
#include "msp430.h"
unsigned int Time_period, step, x, y, z;
typedef enum
{
GREEN = BIT2, RED = BIT3, BLUE = BIT4, WHITE = BIT2 | BIT3 | BIT4
} colors_e;
volatile colors_e currColor = RED;
volatile unsigned int Sw1, Sw3; //Counter
void PWMCLK(void)
{
TA0CCR0 = 512; // PWM Period
TA0CCTL1 = OUTMOD_7 | CLLD_1; //Green LED
TA0CCTL2 = OUTMOD_7 | CLLD_1; //Red LED
TA0CCTL3 = OUTMOD_7 | CLLD_1; //Blue LED
TA0CTL = TASSEL_2 | MC_1 | TACLR; // ACLK, up mode, clear TAR
}
void LED(unsigned int Brightnessbutton, unsigned int LEDcolorchange)
{
if (Brightnessbutton == 0)
{
Time_period = 0;
step = 0;
TA0CCR1 = 0;
TA0CCR2 = 0;
TA0CCR3 = 0;
P1SEL &= ~(BIT2 | BIT3 | BIT4);
}
else if (Brightnessbutton == 1)
{
Time_period = 128;
step = 1;
}
else if (Brightnessbutton == 2)
{
Time_period = 256;
step = 2;
}
else if (Brightnessbutton == 3)
{
Time_period = 384;
step = 3;
}
else if (Brightnessbutton == 4)
{
Time_period = 512;
step = 5;
}
if (LEDcolorchange == 1)
{
currColor = (colors_e) (P1SEL & WHITE);
switch (currColor)
{
case BLUE:
for (y = 0; y < Time_period; y = y + step)
{
TA0CCR2 = y;
P1SEL = RED;
__delay_cycles(2000);
}
for (y = Time_period; y > 0; y = y - step)
{
TA0CCR2 = y;
__delay_cycles(2000);
}
break;
case RED:
for (z = 0; z < Time_period; z = z + step)
{
TA0CCR3 = z;
P1SEL = BLUE;
__delay_cycles(2000);
}
for (z = Time_period; z > 0; z = z - step)
{
TA0CCR3 = z;
__delay_cycles(2000);
}
break;
default:
P1SEL = BLUE;
break;
}
}
else if (LEDcolorchange == 2)
{
currColor = (colors_e) (P1SEL & WHITE);
switch (currColor)
{
case BLUE:
for (x = 0; x < Time_period; x = x + step)
{
TA0CCR1 = x;
P1SEL = GREEN;
__delay_cycles(2000);
}
for (x = Time_period; x > 0; x = x - step)
{
TA0CCR1 = x;
__delay_cycles(2000);
}
break;
case GREEN:
for (z = 0; z < Time_period; z = z + step)
{
TA0CCR3 = z;
P1SEL = BLUE;
__delay_cycles(2000);
}
for (z = Time_period; z > 0; z = z - step)
{
TA0CCR3 = z;
__delay_cycles(2000);
}
break;
default:
P1SEL = BLUE;
break;
}
}
else if (LEDcolorchange == 3)
{
currColor = (colors_e) (P1SEL & WHITE);
switch (currColor)
{
case RED:
for (x = 0; x < Time_period; x = x + step)
{
TA0CCR1 = x;
P1SEL = GREEN;
__delay_cycles(2000);
}
for (x = Time_period; x > 100; x = x - step)
{
TA0CCR1 = x;
__delay_cycles(2000);
}
break;
case GREEN:
for (y = 0; y < Time_period; y = y + step)
{
TA0CCR2 = y;
P1SEL = RED;
__delay_cycles(2000);
}
for (y = Time_period; y > 0; y = y - step)
{
TA0CCR2 = y;
__delay_cycles(2000);
}
break;
default:
P1SEL = RED;
break;
}
}
else if (LEDcolorchange == 4)
{
currColor = (colors_e) (P1SEL & WHITE);
switch (currColor)
{
case RED:
for (x = 0; x < Time_period; x = x + step)
{
TA0CCR1 = x;
P1SEL = GREEN;
__delay_cycles(2000);
}
for (x = Time_period; x > 0; x = x - step)
{
TA0CCR1 = x;
__delay_cycles(2000);
}
break;
case BLUE:
for (y = 0; y < Time_period; y = y + step)
{
TA0CCR2 = y;
P1SEL = RED;
__delay_cycles(2000);
}
for (y = Time_period; y > 0; y = y - step)
{
TA0CCR2 = y;
__delay_cycles(2000);
}
break;
case GREEN:
for (z = 0; z < Time_period; z = z + step)
{
TA0CCR3 = z;
P1SEL = BLUE;
__delay_cycles(2000);
}
for (z = Time_period; z > 0; z = z - step)
{
TA0CCR3 = z;
__delay_cycles(2000);
}
break;
default:
P1SEL = BLUE;
break;
}
}
}
void INTERRUPT_CLK(void)
{
TA1CCTL0 = CCIE; // CCR0 interrupt enabled
TA1CCR0 = 50000;
TA1CTL = TASSEL_1 | MC_1; // SMCLK, countmode, clear TAR
//__bis_SR_register(LPM0_bits | GIE); // Enter LPM0, enable interrupts
// __no_operation(); // For debugger
}
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
P1DIR |= BIT2 | BIT3 | BIT4; // P1.2, P1.3 and P1.4 output
P1SEL &= ~(BIT2 | BIT3 | BIT4); // P1.2 and P1.3 options select
P3REN |= (BIT1 + BIT2 + BIT3); //Enables a puller-Resistor on the button-pin
P3OUT |= (BIT1 + BIT2 + BIT3); //Writes a "1" to the portpin, tellling the resistor to pullup
P3IES |= (BIT1 + BIT2 + BIT3); //Triggers when you PRESS the button :: Pick one...
P3IFG &= ~(BIT1 + BIT2 + BIT3); // Triggers when you RELEASE the button :: ...or pick the other
P3IE |= (BIT1 + BIT2 + BIT3); //Enables the selector-mask for generating interrupts on the relevant pin
PWMCLK();
INTERRUPT_CLK();
__enable_interrupt(); // Enable interrupts globally
while (1)
{
LED(Sw1, Sw3);
}
}
#pragma vector=PORT3_VECTOR
__interrupt
void Port_3(void)
{
switch (__even_in_range(P3IV, 0x10))
{
case 0x00: //None
break;
case 0x02: //Pin0
break;
case 0x04:
//BRI
{
if (Sw1 < 4)
{
Sw1++;
}
else
{
Sw1 = 0;
}
P3IFG &= ~BIT1;
}
break;
case 0x06:
//Fix color
break;
case 0x08:
//ALTcolor
{
if (Sw3 < 4)
{
Sw3++;
}
else
{
Sw3 = 1;
}
P3IFG &= ~BIT3;
}
break;
case 0x0A:
//pin4
break;
case 0x0C:
//pin5
break;
case 0x0E:
//pin6
break;
case 0x10:
//pin7
break;
}
}
#pragma vector=TIMER1_A0_VECTOR
__interrupt
void TIMER1_A0_ISR(void)
{
if (currColor == BLUE)
{
currColor = GREEN;
}
else if (currColor == GREEN)
{
currColor = RED;
}
else if (currColor == RED)
{
currColor = BLUE;
}
else
{
currColor = RED;
}
}