Other Parts Discussed in Thread: MSP-FET, MSP430F6659, MSP430F2274, MSP430WARE
Tool/software: Code Composer Studio
I have a small program for the MSP430i2041 chip that has some bizarre
behavior in its timer interrupt service routine (ISR). I am using CCS
version 9.2.0.00013 to which I have only recently upgraded. The timer ISR
is shown in its entirety at the end of this post.
The problem concerns the value of a global variable at interrupt-time.
I have an unsigned integer global variable named "sCountdown_dS" to which
I assign the value 100 at compile time.
When I run this program under the debugger, and examine the value of
sCountdown_dS as soon as the debugger stops at the entry-point of the
program, the variable does indeed contain the value 100. However, when
I let the debugger run to the first instruction in the ISR, the variable
sCountdown_dS contains the value ZERO. Oddly, the ISR has another
global variable (named sInitDelay_dS) that DOES have the correct value
upon entry to the ISR. It's apparently just sCountdown_dS that has the
problem.
The ISR also does not work properly, and it should, so I conclude that
this is a problem with the compiler or linker, not the debugger.
It seems as if sCountdown_dS is not being treated as a global variable,
even though sInitDelay_dS is. Strange! Any ideas? Are there any known
bugs associated with this?
-eNick
-------------------------------------------------------------------------
// TimerGen.c
//General program timer ISR for program CCSi2041
#include <msp430.h> //include TI definitions
#include "CCSi2041.h" //include my own program definitions
//Begin definition of global variables
//
U16 sInitDelay_dS = INIT_DELAY_DS; //program-initialization delay in dS
U16 sInitDoneFlag = 0; //will be non-zero JUST ONCE at end of program-initialization
U16 sCountdown_dS = 100; //countdown to next dS
U16 sAckhold_dS = 0; //"Ack Holddown" time in dS
U16 sAckHoldFlag = 0; //if non-zero, "Ack" held down long enough to clear counters
U16 sAckNowFlag = 0; //non-zero when "Ack" pushbutton is pressed
//
//End definition of global variables
//Begin references to external global variables
//
//
//End references to external global variables
#pragma vector=TIMER0_A0_VECTOR
__interrupt void TA0_ISR(void)
{
//get here 1,000 times per second
//will now countdown towards the next dS
sAckNowFlag = 0; //zzzz superfluous 1st instruction in ISR
sCountdown_dS--; //countdown towards the next dS
if (sCountdown_dS != 0) return; //all done if not at next dS yet
//will now perform everything that must be handled each dS
sCountdown_dS = 100; //reload the dS countdown
FlashI (); //handle the Error-LED flashing
//will now handle the program-initialization delay
if (sInitDelay_dS) //if the initialization-delay timer is still running
{
sInitDelay_dS--; //count this additional dS
if (!sInitDelay_dS) //if the timer has just now timed out
{
sInitDoneFlag = 1; //flag this for MainLoop
}
}
//will now handle the "Ack" pushbutton
if ((ACK_PB_PORT & ACK_PB_BITP) == 0) //if the "Ack" pushbutton is pressed
{
sAckNowFlag = 1; //flag this condition
FlashNum (0); //stop Error-Flashing upon "Ack"
sAckhold_dS++; //count this dS
if (sAckhold_dS >= ACK_HOLD_DS) //if "Ack" PB held down long enough
{
sAckHoldFlag = 1; //set the "Ack-held-down" flag
sAckhold_dS = 0; //clear the "Ack Holddown" timer
}
}
else //but if "Ack" is not pressed
{
sAckNowFlag = 1; //flag this condition
sAckhold_dS = 0; //clear the "Ack Holddown" timer
}
}