Announcements

Ever wondered how you could shape the future in collaboration with others? Join us at OktoberTech Asia Pacific and get inspired. Click here to sign up FREE of charge.

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

PSoC™ 5, 3 & 1 Forum Discussions

SuomyNonaPatri
Level 1
10 sign-ins 5 questions asked 5 sign-ins
Level 1

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);
}
0 Likes
1 Solution
SampathS_11
Moderator
Moderator 250 sign-ins 250 solutions authored 5 questions asked
Moderator

Hello @SuomyNonaPatri ,

Your code is correct for most part, except for calling functions from inside the ISR. PSoC1 has a very small stack, and it is not recommended to call functions from inside an ISR. Moving lines 2 to 4 to the main loop would solve the issue. You can use an additional variable for a flag indicating that myTimerInt has been invoked.

I request you to refer to PSoC1 Interrupts, section "Tips and Tricks" / "Avoiding function calls in the ISR" on page 18.

Best regards,

Sampath Selvaraj

View solution in original post

0 Likes
1 Reply
SampathS_11
Moderator
Moderator 250 sign-ins 250 solutions authored 5 questions asked
Moderator

Hello @SuomyNonaPatri ,

Your code is correct for most part, except for calling functions from inside the ISR. PSoC1 has a very small stack, and it is not recommended to call functions from inside an ISR. Moving lines 2 to 4 to the main loop would solve the issue. You can use an additional variable for a flag indicating that myTimerInt has been invoked.

I request you to refer to PSoC1 Interrupts, section "Tips and Tricks" / "Avoiding function calls in the ISR" on page 18.

Best regards,

Sampath Selvaraj

0 Likes