Hi,
I am using MSP430g2553 Timer A and I try to create multiple PWM signals using Timer_A3 for controlling multiple fans.
I wrote the following timer initialization and interrupt routine.I used Timer0_A0, Timer0_A1 and Timer1_A1 interrupt vectors to implement the required PWM generation code supporting P3.4,P3.5 and P3.1. I have used TA0CCR0 to create a 1ms interrupt as my events creation timer. but I used TA0CCR1 and TA0CCR2 and TA1CCR1 to create my PWMs. But only P3.4/TA0.1 shows a PWM signal, I do not have any PWM signal on port P3.5/TA0.0 and P3.1/TA1.0. Your response is highly appreciated.
void timera_init(void){
// setup the timer
TA0CCR0 = MSEC_INTERVAL;
TA0CTL = TASSEL_2 + MC_2; // SMCLK, countmode
TA0CCTL0 = CCIE; // CCR0 toggle,CCR0 interrupt enabled
runTime.msec = 0;
runTime.days = 0;
//initialize timer TA0.0/P3.4 and TA0.1/P3.5 for PWM generation
TA0CCTL1 &=0x00;
TA0CCTL1 = OUTMOD_7+CCIE; // CCR1 toggle,CCR1 interrupt enabled
TA0CCTL2 = OUTMOD_7+CCIE; // CCR2 toggle,CCR2 interrupt enabled
//initialize timer TA1.0/P3.1
TA1CTL = TASSEL_2 + MC_2; // SMCLK, countmode
TA1CCTL0 &=0x00;
TA1CCTL0 = OUTMOD_7+CCIE; // CCR1 toggle,CCR1 interrupt enabled
//initialize the pins on port 3
P3DIR |= BIT1+BIT4+BIT5; // Set pin as output
P3SEL |= BIT1+BIT4+BIT5; // Select alternate function for PWM
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void TIMER0_A0_ISR(void)
{
TA0CCR0 += MSEC_INTERVAL; // Add Offset to CCR0
runTime.msec++;
if (runTime.msec >= (long) 86400000) { // if we are at 24hours worth of msec
runTime.days++; // bump days
runTime.msec = (long) 0; // reset milliseconds
}
// turns off RS485 Transmit Enable when transmit buffer is empty and UART done with transmission
if((usart0_tx_buffer_count()==0) && !(UCA0STAT & UCBUSY)) {
P2OUT &= ~BIT7; // Turn off Transmit Enable to receive
}
}
#pragma vector=TIMER0_A1_VECTOR
__interrupt void TIMER0_A1_ISR(void)
{
switch(__even_in_range(TA0IV,14))
{
case 0: // CCR0
break;
case 2: // CCR1
#if 1
if(TA0CCTL1 & CCI) // If output currently high
{
TA0CCR1 += 200; // 60% high
}
else
{
TA0CCR1 += 600; // 40% low
}
#endif
break;
case 4: // CCR2
#if 0
if(TA0CCTL2 & CCI) // If output currently high
{
TA0CCR2 += 600; // 12.5% high
}
else
{
TA0CCR2 += 400; // 87.5% low
}
#endif
break;
default: break;
}
}
#pragma vector=TIMER1_A1_VECTOR
__interrupt void TIMER1_A1_ISR(void)
{
switch(__even_in_range(TA1IV,14))
{
case 0:
if(TA1CCTL0 & CCI) // If output currently high
{
TA1CCR0 += 600; // 12.5% high
}
else
{
TA1CCR0 += 400; // 87.5% low
}// CCR0
break;
case 2:
break;
case 4:
break;
}
}