Hello everyone,
I'm working with IAR workbench, and I'm utilizing the TimerB with the
MSP430F2619. Though I realize that the simulator cannot simulate the clock
signals, I'm trying to simulate multiple different interrupts to ensure
that every thing works relatively smoothly.
First, the trouble I'm running into is that the interrupts seems to trigger
multiple times in a given setting (i.e. if it's supposed to trigger with a
system clock of 40000 and an interval of 40000, it'll trigger at 40000 and
40006).
Second, and more importantly, some of the interrupts just don't seem to run
the service routine despite triggering.
Here's my IAR C-Spy Macro:
__var _interruptID1;
__var _interruptID2;
__var _interruptID3;
__var _interruptID4;
__var _interruptID5;
__var _interruptID6;
__var _breakID;
execUserSetup()
{
__message "execUserSetup() called\n";
_interruptID1 = __orderInterrupt( "TIMERB1_TBCCR1_VECTOR", 40000, 40000, 0, 1,
0, 100 );
if( -1 == _interruptID1 )
{
__message "ERROR: failed to order interrupt 1";
}
_interruptID2 = __orderInterrupt( "TIMERB1_TBCCR2_VECTOR", 45000, 40000, 0, 1,
0, 100 );
if( -1 == _interruptID2 )
{
__message "ERROR: failed to order interrupt 2";
}
_interruptID3 = __orderInterrupt( "TIMERB1_TBCCR3_VECTOR", 50000, 40000, 0, 1,
0, 100 );
if( -1 == _interruptID3 )
{
__message "ERROR: failed to order interrupt 3";
}
_interruptID4 = __orderInterrupt( "TIMERB1_TBCCR4_VECTOR", 55000, 40000, 0, 1,
0, 100 );
if( -1 == _interruptID4 )
{
__message "ERROR: failed to order interrupt 4";
}
_interruptID5 = __orderInterrupt( "TIMERB1_TBCCR5_VECTOR", 60000, 40000, 0, 1,
0, 100 );
if( -1 == _interruptID5 )
{
__message "ERROR: failed to order interrupt 5";
}
_interruptID6 = __orderInterrupt( "TIMERB1_TBCCR6_VECTOR", 65000, 40000, 0, 1,
0, 100 );
if( -1 == _interruptID6 )
{
__message "ERROR: failed to order interrupt 6";
}
// Set up the immediate breakpoint
_breakID = __setSimBreak( "TBIV", "R", "Access()" );
}
And here's an excerpt of my code:
int main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
BCSCTL1 = CALBC1_1MHZ; // Set BCS to 1 MHz
DCOCTL = CALDCO_1MHZ; // Set DCO to 1 MHz
P4DIR = 0x00; // Set Direction to Input
P4SEL = 0x7F; // Set utilization to alternate;
//Set Capture on rising edge, CCIxB, Synchronous capture, Load on write,
//Capture mode, and enable interrupt.
TBCCTL1 = CM_1 + CCIS_1 + SCS + CLLD_0 + CAP + CCIE;
TBCCTL2 = CM_1 + CCIS_1 + SCS + CLLD_0 + CAP + CCIE;
TBCCTL3 = CM_1 + CCIS_1 + SCS + CLLD_0 + CAP + CCIE;
TBCCTL4 = CM_1 + CCIS_1 + SCS + CLLD_0 + CAP + CCIE;
TBCCTL5 = CM_1 + CCIS_1 + SCS + CLLD_0 + CAP + CCIE;
TBCCTL6 = CM_1 + CCIS_1 + SCS + CLLD_0 + CAP + CCIE;
TBCTL = TBCLGRP_0 + CNTL_0 + TBSSEL_1 + ID_3; // Latch TBCL independently,
use 16 bits
// Use ACLK for source, and
divide by 8
TBCTL |= TBIE + MC_2; // Enable Interrupt and go
into Continous mode
for (;;) {
_BIS_SR(LPM3_bits + GIE); // Enter LPM3 w/ interrupt
}
return 0;
}
#pragma vector=TIMERB1_VECTOR
__interrupt void Timer_B (void)
{
static unsigned short overflow = 0, last_timestamp = 0;
static unsigned char event_count = 0;
unsigned short current_timestamp;
//Check buffer size to see if it can handle another event, if not flush
buffer
//and start the next buffer
switch (TBIV) {
case TBIV_TBCCR1:
event_count++;
current_timestamp = TBCCR1;
break;
case TBIV_TBCCR2:
event_count++;
current_timestamp = TBCCR2;
break;
case TBIV_TBCCR3:
event_count++;
current_timestamp = TBCCR3;
break;
case TBIV_TBCCR4:
event_count++;
current_timestamp = TBCCR4;
break;
case TBIV_TBCCR5:
event_count++;
current_timestamp = TBCCR5;
break;
case TBIV_TBCCR6:
event_count++;
current_timestamp = TBCCR6;
break;
default:
overflow++;
current_timestamp = last_timestamp;
break;
}
if ( (overflow == 0) && (current_timestamp > last_timestamp) ) {
saveTimeStamp(current_timestamp, event_count);
}
last_timestamp = current_timestamp;
}
IAR simulator interrupt question
Started by ●March 26, 2009