- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm using the evaluation kit for PRoC BLE. I've added a timer counter on the schematic and set it up for continuous run, capture mode, interrupt on terminal count. My goal is to have a 60 Hz interrupt routine.
In my ISR, I increment a global variable and print a message on the debug port on every 60th count. I then clear the interrupt using TCPWM_ClearInterrupt().
The problem I'm experiencing is that it seems that when the interrupt flag clear is included in the ISR, it causes the timer to freeze. However, when I remove the interrupt clear, I get the debug messages much more frequently than I expect. I assume this is because the flag is never cleared and so it re-enters the ISR every time it exits. So my conclusion is that I'm pretty sure I need to clear the interrupt flag.
So my question is, why is my timer freezing when I have the interrupt clear call in the ISR? How do I fix this?
- Labels:
-
BLE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Welcome in the forum.
"In my ISR, I increment a global variable and print a message on the debug port on every 60th count" Printing a message in the interrupt handler can cause errors: The underlying UART can use interrupts also, which may be blocked by the previous interrupt or the sending of the message takes longer than the 1/60s which would then skip a count.
I would suggest you just to set a volatile uint8 msgflag in your handler and -as you already did- remove the interrupt cause of the TCPWM. In your main - loop check the msgflag, when set, reset it and send your message.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried using a message flag as you suggested and still have the problem. 😞
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Post your code so we can check it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I won't post all of the subroutines just to save you guys from having to read alot of extra code. I started with the "Proximity" example code so most of what's here is related to the bluetooth functionality. Here is the ISR I'm having trouble with:
CY_ISR(Update_Int)
{
if (timecount%60 == 0)
{
Dbg_time = 1;
}
timecount++;
UpdateTimer_ClearInterrupt(UpdateTimer_INTR_MASK_TC);
}
And here is the main body:
int main()
{
CYBLE_API_RESULT_T apiResult;
CYBLE_BLESS_PWR_IN_DB_T txPower;
int8 intTxPowerLevel;
CyGlobalIntEnable;/* Turn off all of the LEDs */
Disconnect_LED_Write(LED_OFF);
Advertising_LED_Write(LED_OFF);
Alert_LED_Write(LED_OFF);/* Start CYBLE component and register generic event handler */
CyBle_Start(AppCallBack);Turn_Int_StartEx(&Turn_Int);
/* Register the event handler for LLS specific events */
CyBle_LlsRegisterAttrCallback(LlsServiceAppEventHandler);/* Register the event handler for TPS specific events */
CyBle_TpsRegisterAttrCallback(TpsServiceAppEventHandler);WDT_Start();
/* BLUETOOTH STUFF REMOVED FOR POSTING!!!*//* Start Clocks */
Clock_1_Start();
Clock_2_Start();
DBG_PRINTF("Clocks Started.\r\n");
/* Start Timers */
//NP_Sig_Timer_Start();
UpdateTimer_Start();
DBG_PRINTF("Timers Started.\r\n");
//NP_Sig_Int_StartEx(&NP_Sig_Int);
Update_Int_StartEx(&Update_Int);
UpdateTimer_SetInterrupt(UpdateTimer_INTR_MASK_TC);
DBG_PRINTF("Interrupts Started.\r\n");
while(1)
{
/* CyBle_ProcessEvents() allows BLE stack to process pending events */
CyBle_ProcessEvents();
if (Dbg_time == 1)
{
DBG_PRINTF("Timereport: second # %d.\r\n", (timecount/60));
Dbg_time = 0;
}/* To achieve low power in the device */
LowPowerImplementation();if((CyBle_GetState() != CYBLE_STATE_CONNECTED) && (CyBle_GetState() != CYBLE_STATE_ADVERTISING))
{
/* BLUETOOTH STUFF REMOVED FOR POSTING!!!*/
}
}
else
{
/* Decrease Tx power level of BLE radio if button is pressed */
if(buttonState == BUTTON_IS_PRESSED)
{
DBG_PRINTF("Update Counter: %ld\r\n", UpdateTimer_ReadCounter());
//UpdateTimer_Start();
/* BLUETOOTH STUFF REMOVED FOR POSTING!!!*/
/* Reset button state */
buttonState = BUTTON_IS_NOT_PRESSED;
}
}HandleLeds();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you please post your complete project, so that we all can have a look at all of your settings. 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
Your NP_Sig_Timer fires interrupts with more than 2MHz, this will not work. Processing an interrupt (saving the registers, entering the handler, resetting the interrupt cause, restoring the registers) will take some more time. I experienced interrupt frequencies up to 1kHz without disturbing the system, especially when there are other sources for interrupts as UART interfaces etc.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried removing that other timer and it didn't help. I even tried starting a new project from scratch and I'm still having this problem. There's got to be something very basic that I'm not doing right.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you again upload your actual project?
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
Before entering deep sleep mode you should call UART_DEB_Sleep() and when back again UART_DEB_Wakeup().
Later do the same with the other components that use HFCLK.
Set UART_DEB byte mode and increase Rx and Tx buffer to 16
Bob