2023-06-21 06:36 AM
Please some one help me to how to get controller from sleep the configuration I made is not working.The below given code working fine and putting the controller in sleep but controller not waking up.The condition depends on mains (ADC Input channel 5)when it detects a value other than zero in mains voltage my controller should wake-up
while(MV<100)
{
ADC_Read1(&MV);
delay_ms(100);
Set_LED(0);
idle_counter++;
if (idle_counter>=300)
{
EnterSleepMode();
}
}
// rest of the code//
void TIM2_Config(void)
{
TIM2_TimeBaseInit(TIM2_PRESCALER_32768, 244);
TIM2_ClearFlag(TIM2_FLAG_UPDATE);
TIM2_ITConfig(TIM2_IT_UPDATE, ENABLE);
TIM2_Cmd(ENABLE);
AWU_DeInit();
/* auto wake up at 32ms */
AWU_Init(AWU_TIMEBASE_32MS);
/* enable auto wake up*/
AWU_Cmd(ENABLE);
enableInterrupts();
}
INTERRUPT_HANDLER(TIM2_UPD_OVF_BRK_IRQHandler, 13)
{
if (TIM2_GetITStatus(TIM2_IT_UPDATE) != RESET)
{
// Increment the idle_counter every 500ms
idle_counter++;
// Enter sleep mode if idle for approximately 30 seconds (60 * 500ms)
if (idle_counter >= 300)
{
EnterSleepMode();
}
TIM2_ClearITPendingBit(TIM2_IT_UPDATE);
}
}
void EnterSleepMode(void)
{
// Disable TIM2 interrupt
TIM2_ITConfig(TIM2_IT_UPDATE, DISABLE);
// Disable ADC peripheral
ADC1_Cmd(DISABLE);
// Disable GPIO inputs
GPIO_Init(GPIOD, GPIO_PIN_3, GPIO_MODE_IN_PU_NO_IT);
GPIO_Init(GPIOD, GPIO_PIN_5, GPIO_MODE_IN_FL_IT);
GPIO_Init(GPIOC, GPIO_PIN_4, GPIO_MODE_IN_PU_NO_IT);
halt();
// Re-enable ADC peripheral
}
void Inc500mSCounter(void)
{
if (_500ms_tick < 500)
{
_500ms_tick++;
}
else
{
_500ms_tick = 0;
idle_counter++;
}
}