- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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