Timer dropping out too soon

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

cross mob
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

 I am using the code below (copied from an example on the web) to provide a timeout feature for a routine.

   

However, whatever value I use when calling the routine (100, 1000, 5000), the timeout seems to happen immediatly and not at 100ms or 1000 ms or 5000 ms.

   

The timer component is set up as 32 bit timer with 24MHz clock and interrupt on TC.

   

Help much appreciated

   

 

   

CY_ISR(TimerINT){

   

    Timer_ReadStatusRegister();

   

    Timer_Flag = 1;

   

}

   

 

   

void ms_delay (uint32 ms) {

   

    Timer_Init(); // config but don't start the timeout counter

   

    isr_Timer_StartEx(TimerINT);

   

    uint32 period = 24000000/1000*ms;

   

    Timer_WritePeriod(period);

   

    Timer_Enable(); // start the timeout counter

   

    while(!Timer_Flag){};

   

    Timer_Stop();

   

        Timer_Flag = 0;

   

}

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Some corrections: volatile for the flag is mandantory, program will fail when compiled with "Release" setting

   

INT should be "Rising Edge" for UDBs

   

Flag was not initialized.

   

Period was set, but counter has value from initialization or last stop

   

_StartEx() for interrupt was called within loop, same for Timer_Init()

   

 

   

Happy coding

   

Bob

   

PS: I changed the target to PSoC5, please reverse to PSoC4 4247

View solution in original post

0 Likes
14 Replies