I'm having a problem implementing and interrupt function in my already existing code. Basically I want the interrupt to trigger either when a certain output is triggered or when the counter that triggers the output reaches the threshold.
Equipment:
Micro: MSP430F5522
CCS: 5.5.0.00077
Compiler: TI v4.1.9
The device is supposed to scan for a light, and if the light is detected a certain amount of times in a row, an output is turned on that lights up a green LED. If it fails a certain amount of times in a row, a red LED is supposed to turn on.
The problem with this code is that the red LED does not stay on long enough to show that there was a high amount of consecutive misses when scanning for the light. The solution was to come up with an interrupt function that uses a different clock within the processor so the test cycle is not delayed and the red LED stays on long enough for the operator to know about the misses.
The RED/GREEN_LED_ON/OFF are bit wise output controllers defined earlier in the file.
This is the original function before I put the interrupt function within it:
#define PASSCOUNTERTHRESHOLD 40//20 void display( char event , char test ) { int j,i; static int maxConsecPassingCount=0; static int consecPassingCount=0; static int passingCount=0; static int timeLimit=0; // amount of time allowed for non detection before failure is asserted. static int consecFails=0; if ( event == DETECTED ) { if ( stardata.outputOptions & DUALED ) { if( ++consecPassingCount > 99 && !(EXT_INPUT)) // if no detection for long period , assume no motion and just reset counter { RED_LED_OFF; GREEN_LED_ON; return; } if( timeLimit > 0 && !(EXT_INPUT)) { // evaluate whether the time limit has been violated by stopping timer and reading counter, reset counter for next time. if limit exceeded turn on red led // else turn on green led TA0CCR0 = 0; i=TA0R; if ( i > timeLimit ) { RED_LED_ON; GREEN_LED_OFF; } else { GREEN_LED_ON; RED_LED_OFF; } } else { RED_LED_OFF; GREEN_LED_ON; timer_us(50); GREEN_LED_OFF; } consecFails=0; } } else if ( event==NOT_DETECTED) { passingCount+=consecPassingCount; if ( consecPassingCount > maxConsecPassingCount ) // find maximum string of consecutive passing tests out of a group <PASSCOUNTERTHRESHOLD> of tests to estimate the speed. { maxConsecPassingCount = consecPassingCount; } consecPassingCount=0; if ( passingCount > PASSCOUNTERTHRESHOLD) // we should have enough data to predict the speed, so now calculate the maximum failing time allowed before we set the fail led. { passingCount=0; timeLimit= maxConsecPassingCount * stardata.starLimits[test].hiTestLimit2; //150; // amount of time which is allowed between non detect intervals. maxConsecPassingCount=0; } if ( timeLimit > 0 && consecFails == 0 ) // start timer { TA0R=0; TA0CCR0 = 5000; } if ( consecFails > 100) { GREEN_LED_OFF; RED_LED_ON; return; } //consecFails=0; else ++consecFails; } }
I defined the timer used in the interrupt function in the main.c file as follows:
TA2CCTL0=CCIE;
TA2CTL=TASSEL_2+MC_3+ID__8;
TA2CCR0=125000;
This is the code with the interrupt function replacing RED_LED_ON output:
void display( char event , char test )
{
int j,i;
static int maxConsecPassingCount=0;
static int consecPassingCount=0; //kg 8/16
static int passingCount=0; //kg 8/16
static int timeLimit=0; // amount of time allowed for non detection before failure is asserted.
static int consecFails=0;
if ( event == DETECTED )
{
if ( stardata.outputOptions & DUALED )
{
if( ++consecPassingCount > 99 && !(EXT_INPUT)) // if no detection for long period , assume no motion and just reset counter
{
RED_LED_OFF;
GREEN_LED_ON;
return;
}
if( timeLimit > 0 && !(EXT_INPUT))
{
// evaluate whether the time limit has been violated by stopping timer and reading counter, reset counter for next time. if limit exceeded turn on red led
// else turn on green led
TA0CCR0 = 0;
i=TA0R;
if ( i > timeLimit )
{
#pragma vector=TIMER1_A1_VECTOR //kg
__interrupt void TIMER1_A1ISR (void)
{
RED_LED_ON;
GREEN_LED_OFF;
}
}
else
{
GREEN_LED_ON;
RED_LED_OFF;
}
}
else
{
RED_LED_OFF;
GREEN_LED_ON;
timer_us(50);
GREEN_LED_OFF;
}
consecFails=0;
}
}
else if ( event==NOT_DETECTED)
{
passingCount+=consecPassingCount;
if ( consecPassingCount > maxConsecPassingCount ) // find maximum string of consecutive passing tests out of a group <PASSCOUNTERTHRESHOLD> of tests to estimate the speed.
{
maxConsecPassingCount = consecPassingCount;
}
consecPassingCount=0;
if ( passingCount > PASSCOUNTERTHRESHOLD) // we should have enough data to predict the speed, so now calculate the maximum failing time allowed before we set the fail led.
{
passingCount=0;
timeLimit= maxConsecPassingCount * stardata.starLimits[test].hiTestLimit2; //150; // amount of time which is allowed between non detect intervals.
maxConsecPassingCount=0;
}
if ( timeLimit > 0 && consecFails == 0 )// start timer
{
TA0R=0;
TA0CCR0 = 5000;
}
if ( consecFails > 100)
{
#pragma vector=TIMER1_A1_VECTOR //kg
__interrupt void TIMER1_A1ISR (void)
{
RED_LED_ON;
GREEN_LED_OFF;
}
}
//consecFails=0;
else ++consecFails;
}
}
I can't get the code to compile and I can't find a forum that discusses adding interrupts that are controlled in the same way I am using them. Does anyone have any ideas as to what I am doing wrong?
void display( char event , char test ){int j,i;
static int maxConsecPassingCount=0;static int consecPassingCount=0; //kg 8/16static int passingCount=0; //kg 8/16static int timeLimit=0; // amount of time allowed for non detection before failure is asserted.static int consecFails=0;
if ( event == DETECTED ){
if ( stardata.outputOptions & DUALED ){
if( ++consecPassingCount > 99 && !(EXT_INPUT)) // if no detection for long period , assume no motion and just reset counter{RED_LED_OFF;GREEN_LED_ON;return;}
if( timeLimit > 0 && !(EXT_INPUT)){// evaluate whether the time limit has been violated by stopping timer and reading counter, reset counter for next time. if limit exceeded turn on red led// else turn on green ledTA0CCR0 = 0;i=TA0R;
if ( i > timeLimit ){
#pragma vector=TIMER1_A1_VECTOR //kg__interrupt void TIMER1_A1ISR (void){RED_LED_ON;GREEN_LED_OFF;}
}else{GREEN_LED_ON;RED_LED_OFF;}}else{RED_LED_OFF;GREEN_LED_ON;timer_us(50);GREEN_LED_OFF;}
consecFails=0;}
}else if ( event==NOT_DETECTED){passingCount+=consecPassingCount;if ( consecPassingCount > maxConsecPassingCount ) // find maximum string of consecutive passing tests out of a group <PASSCOUNTERTHRESHOLD> of tests to estimate the speed.{maxConsecPassingCount = consecPassingCount;}consecPassingCount=0;
if ( passingCount > PASSCOUNTERTHRESHOLD) // we should have enough data to predict the speed, so now calculate the maximum failing time allowed before we set the fail led.{passingCount=0;timeLimit= maxConsecPassingCount * stardata.starLimits[test].hiTestLimit2; //150; // amount of time which is allowed between non detect intervals.maxConsecPassingCount=0;}if ( timeLimit > 0 && consecFails == 0 )// start timer{TA0R=0;TA0CCR0 = 5000;}
if ( consecFails > 100){#pragma vector=TIMER1_A1_VECTOR //kg__interrupt void TIMER1_A1ISR (void){RED_LED_ON;GREEN_LED_OFF;}}//consecFails=0;else ++consecFails;}
}