- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It is always advisable to upload a complete project showing the error, there are a bunch of settings that may influence the timer's behaving. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Note: I did also try with Timer-Flag set as volatile
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Took me some time to find that "counter-bug", but I'd like you to tell how:
When you start the debug-session and the program stops at the first executable instruction of your program
Debug -> Windows -> Components -> Check the timer and watch relevant timer registers.
When setting a BP at the right place you will see that the counter of the timer runs amok.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your "ms_delay" function is blocking. It already has standard implementation in Creator:
CyDelayUs( 1000*ms);
odissey1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No, I am not using it as blocking timer in my application. The project uploaded only contains the timer part.
In the actualy project it does this
Start Timer();
while(!Timeout){
do stuff;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Bob,
The code works fine. I could not determine from the datasheet that you have to set up the counter and timer registers to reset count.
Also, the rising edge on the interrupt was something I was not aware of.
By the way, how to you see if the Interrupts are enabled? Is there a register you can watch.
Regards
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is an icon in the Creator menu to switch interrupts on and off. The Icon always shows the current state.
Bob
PS: When do you sleep???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Bob,
I was just about to ask you when you sleep.
Thanks again.
I know this question is regarding a different issue than this thread but I am hoping you could help while I "have you" here.
I have a PSOC 4 project with digital inputs on P4[2] and P4[0] that I want to set up interrupt on rising edge.
However, it appears these pins cannot be "used for routed connections". Referring to the PINS technical guide I see you can access the pins directly but I am not sure how you attach interrupt to them.
A while ago I had a similar issue and tech support advised to change the Input Synch mode. This time it does not appear to make any difference. Would using the Pins own INTERRUPT method solve the issue?
At the moment I enabled hardware connection and attached isr component
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I cannot get that to run, too. Best for you is to try to call the technical support again.
Bob (Local Time 10:15 pm)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Will do thanks Bob,
The night is but young in your neck of the woods.
Local time here is 8:30 am
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think you need to set the input sync mode to "transparent". The default of "double-sync" needs an UDB which is not available on port 4.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, I have tried transparent node also.
I have looked at the incoming waveform on a scope and it is correct but I cannot seem to properly read the pins.
After not being able to detect high going, I tried the cypins_readpin and can detect the clock going high but not data
Attached is the waveform. It is fairly slow (clock period is 2ms), data is supposed to be read on high clock.