- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I need a one shot 30 sec timer in my project with an interrupt on terminal count.
I think the timer component is configured correctly and it works as expected (counts for 30 sec and fires interrupt), when I attach the interrupt component to the "tc" output of the timer.
However, if I attach the interrupt component to the "interrupt" output, the interrupt never get fired (the ISR method is never being entered) although the counter counts down to zero and stops counting as expected being a one shot timer.
What do I miss?
Here is my design (part): https://www.dropbox.com/s/1ndrfp3wzxlobil/one-shot-timer.png?dl=0
Here is my timer config: https://www.dropbox.com/s/zx4625z1thdabub/one-shot-timer-conf.png?dl=0
Here is my code, attached you will find my test project as well:
#include <stdio.h>
#include "project.h"void readData();
void logMsg();
static char logMsgLine[255];
static uint8 isr_flag_timer_tc = 0;/**
* Timer ISR
*/
CY_ISR( Timer_Int_Handler )
{
if (Timer_ReadStatusRegister() & Timer_STATUS_TC_INT_MASK) {
isr_flag_timer_tc = 1;
}
sprintf(logMsgLine, "Interrupt %d looking for %d\n\r", Timer_ReadStatusRegister(), Timer_STATUS_TC_INT_MASK);
logMsg( logMsgLine );
}int main(void)
{CyGlobalIntEnable; /* Enable global interrupts. */
UART_Start();
Timer_Int_StartEx( Timer_Int_Handler );
for(;;)
{
readData();
}}
void readData(){
// Start the 30 sec timer
isr_flag_timer_tc = 0; // will be set to 1 on tc interrupt
Timer_Start();
Timer_Trigger_Write( 1 );// loop until 30 sec timer terminal count
while(!isr_flag_timer_tc){
// do something until 30 sec are over
sprintf(logMsgLine, " timer count %d\n\r", Timer_ReadCounter());
logMsg( logMsgLine );
CyDelay(1000);
}if (isr_flag_timer_tc) {
isr_flag_timer_tc = 0;
// stop timer
Timer_Stop();
}}
/**
* write a message to some terminal/chanel
*/
void logMsg(char* msg)
{
UART_UartPutString( msg );
}/* [] END OF FILE */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The interrupt signal is killed by the reset signal. When you set (as a test only) the reset input to logic zero you'll see that the interrupt handler gets called (only once).
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, you are right. This must be it.
Now I skipped the tc->reset connection and connected trigger and reset to the same output of the control register.
Now its one shot timer, triggered + reset at once.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
One more question, I do not use an sync blocks between timer and control register, but have seen multiple examples of one shot timer using them. Do I need some in my scenario? It seems to work just fine now with 1kHz clock attached.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You will get a warning when you need syncing some signals. Your project builds without any warnings.
Bob