Search code examples
cembeddedinterruptpsoc

PSoC timer interrupt


It seems to me that my timer interrupt does not work correctly. Problem is that counter inside interrupt function increments only once. Here is my code from main and timer settings.

#include <m8c.h>
#include "PSoCAPI.h"
#include <stdio.h>
#include <stdlib.h>

char theStr[] = "PSoC LCD";
static char tmp[3];
static int counter = 0;

void main(void){

    LCD_Start();
    LCD_Position(0,5);
    LCD_PrString(theStr);
    M8C_EnableGInt;
    Timer8_EnableInt();
    Timer8_Start();
    while (1);
}

#pragma interrupt_handler myTimerInt
void myTimerInt(void){
    counter ++;
    LCD_Position(1,0);
    itoa(tmp, counter, 10);
    LCD_PrString(tmp);
}

Solution

  • Most interrupt service routines need to re-arm the interrupt (sometimes called "acknowledging the interrupt) which called it. Otherwise, the ISR is only called once. Typically, this is done after the critical part of the ISR is complete.

    In the case of the 503418, I think the reenabling is done by reading the counter register. See the code at the bottom of this.