Hi. I am trying to write a program that outputs on P1.0 an adjustabla PWM. This is obtained using a function "void setSpeed(unsigned long speed)". The problem that I encounter is that the argument "speed" does not pass to the "Timer A0 interrupt service routine". While debugging, when the compiler gets to the Timer A0 ISR, the value of "speed" is always reset back to 0.
Here is the code:
#include <msp430.h>
long counter;
unsigned long speed;
void setSpeed(speed);
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
// Configure GPIO
counter=0;
P1DIR |= BIT0; // P1.0 output
P1OUT |= BIT0; // P1.0 high
P5DIR |= BIT0; // P5.0 output
P5OUT |= BIT0; //P5.0 high
P8DIR |= BIT0; //P8.0 output
P8SEL0 |= BIT0; //P8.0 selected as SMCLK
// Disable the GPIO power-on default high-impedance mode to activate
// previously configured port settings
PM5CTL0 &= ~LOCKLPM5;
setSpeed(10);
}
void setSpeed(speed)
{
TA0EX0 &= ~(BIT0 + BIT1 + BIT2); //SMCLK divided by 1 => 1 tick = 1us
TA0CCTL0 |= CCIE; // TACCR0 interrupt enabled
TA0CCR0 = 4; // every 4 us
TA0CTL = TASSEL__SMCLK | MC__UP; // SMCLK, UP mode
__bis_SR_register(LPM0_bits | GIE); // Enter LPM0 w/ interrupt
__no_operation(); // For debugger
}
// Timer A0 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(TIMER0_A0_VECTOR))) Timer_A (void)
#else
#error Compiler not supported!
#endif
{
counter++;
if (counter == speed) //here, speed always is reset to 0
{
P1OUT ^= BIT0;
P5OUT ^= BIT0;
counter = 0;
}
}
There is also a warning for the setSpeed function:
93-D identifier-list parameters may only be used in a function definition
Can anyone help me correct my code?
Thank you.