|
DETAIL FOR OTHERS further below.
Thanks, SRIM. This got me past the hang, but the timing is still not correct. Please help me some more, if you will please.
My code appears below. It runs and my DEBUG pin toggles. But it toggles every 140ms, not every 16ms as expected. Due to the SleepTimer_1_SetInterval(SleepTimer_1__CTW_16_MS);, I would think it would toggle every 16ms. Is the clock save and restore causing this? Note that I have a 20MHz Crystal and so defined in Creator, with a 30MHz PLL output. I don't know exactly where the CTW gets its clock from. Researching, perhaps it's the ILO. My ILO has the default configuration of 1kHz.
So, bottom line, why is my DEBUG pin toggling every 140ms rather than every 16ms???
Thanks.
#include <device.h>
uint8 DEBUG_PIN_VALUE = 0;
void init()
{
// Initialize debug output pin to 0
DEBUG_Write(DEBUG_PIN_VALUE = 0); // Clear desired pin value and write to pin
// Initialize Sleep Timer
SleepTimer_1_Start(); // Turn on the sleep timer
SleepTimer_1_SetInterval(SleepTimer_1__CTW_16_MS); // Set CTW to 16ms
SleepTimer_1_EnableInt(); // Enable sleep timer interrupt
ISR_SleepTimer_StartEx(ISR_SleepTimer_Interrupt);
}
void main()
{
init();
CyGlobalIntEnable; // Enable global interrupts
for(;;)
{
// Sleep until next SleepTimer interrupt
CyPmSaveClocks(); // Save clock configuration before entering sleep
CyPmSleep(PM_SLEEP_TIME_NONE, PM_SLEEP_SRC_NONE); // Go to sleep for CTW time, previously set to 16ms. Note PSOC5 requires CTW set up previously and pass NONE to two arguments
CyPmRestoreClocks(); // Restore clock configuration after exiting sleep
// DEBUG - Twiddle a pin to show we have woken up from sleep
DEBUG_Write(DEBUG_PIN_VALUE = ~DEBUG_PIN_VALUE); // Toggle desired pin value and write to pin
}
}
DETAIL FOR OTHERS:
Note that you can't simply call SleepTimer_GetStatus( ) or CyPmReadStatus( ) from your main loop. It must be called from the ISR. And, I guess depending on how you use the Creator, you can't simply define CY_ISR as SRIM's example implies.
Instead, here's what I had to do. First, my SleepTimer was routed to an ISR component named "ISR_SleepTimer". I had to go find the auto-generated ISR_SleepTimer.c and find the auto-generated CY_ISR() inside there. It has provision to add lines of code. Inside that region, I added the CyPmReadStatus(CY_PM_CTW_INT);.
In addition, it's important not to miss SRIM's "isr_1_StartEx(MY_ISR);". For my naming, this becomes ISR_SleepTimer_StartEx(ISR_SleepTimer_Interrupt);, which I put right after my other SleepTimer init stuff.
|