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.

TIMER ISSUE

Hi,

We are using MSP430G2432IN20. In this project we have two capture and compare,four switches and four led arrays are there. By pressing one switch we are increasing the two leds brightness and by pressing another switch we are decreasing led brightness.The issue related with our code is that initially the pwm changed properly.But after some time the pwm signal is changing not in the proper way.That means in the pwm signal high become low and low become high.For example in the code if I  have set the duty cycle limit as (8-62) then it automatically change to ((100-62)-(100-8)) ie.(38-92).so the switching action is not taking place properly.There is any mistake in my code?.Or it is because of controller instability?The following is my code

#include <msp430.h>
#define THRESHOLD0 0x0000
#define THRESHOLD1 0x0136
#define THRESHOLD2 0x026c
#define THRESHOLD3 0x03a2
#define hystyrisis 0x005D

#define TIM1 120

#define TIM2 560
#define VAR 1
int main(void)
{

WDTCTL = WDTPW + WDTHOLD; // Stop WDT

BCSCTL1 = CALBC1_16MHZ;
DCOCTL = CALDCO_16MHZ;

ADC10CTL1 = INCH_0; // Conversion code singed format, input A0
ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE; // ADC10ON, interrupt enabled
ADC10AE0 |= 0x00; // P1.0 ADC option select

// Set P1.0 LED on


P2DIR |= 0x0F; // P1.0 output
P2OUT |= 0x00;

CCTL1 = CCIE + OUTMOD_7; // CCR1 interrupt enabled
CCTL2 = CCIE + OUTMOD_7; // CCR2 interrupt enabled
CCR1 = 100;
CCR2 = 100;
CCR0 = 1000;
TACTL = TASSEL_2 + MC_3; // SMCLK, Contmode


for (;;)
{
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit


if((THRESHOLD3+0x003E) >= ADC10MEM && ADC10MEM > (THRESHOLD3-hystyrisis) & TACCR1>=TIM1)
{

CCR1 -= VAR;

_delay_cycles(350000);

}

else if((THRESHOLD2+hystyrisis) >= ADC10MEM && ADC10MEM > (THRESHOLD2-hystyrisis) & TACCR1<=TIM2)
{
CCR1 += VAR;

_delay_cycles(350000);

}
else if((THRESHOLD1+hystyrisis) >= ADC10MEM && ADC10MEM > (THRESHOLD1-hystyrisis) & TACCR2>=TIM1)
{
CCR2 -= VAR;


_delay_cycles(350000);

}
else if((THRESHOLD0+hystyrisis) >= ADC10MEM & TACCR2<=TIM2)
{
CCR2 += VAR;


_delay_cycles(350000);

}
else
{
CCR1=CCR1+0;
CCR2=CCR2+0;
_delay_cycles(350000);
}


}}

// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
_delay_cycles(1);
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}
// Timer_A3 Interrupt Vector (TA0IV) handler
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=TIMER0_A1_VECTOR
__interrupt void Timer_A(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(TIMER0_A1_VECTOR))) Timer_A (void)
#else
#error Compiler not supported!
#endif
{
switch( TA0IV )
{
case 2: // CCR1
{
P2OUT ^= 0x06; // Toggle P1.0
}
break;
case 4:
{
P2OUT ^= 0x09; // Toggle P1.
}
break;

case 10: break; // overflow not used
}}

**Attention** This is a public forum