Debounce for microcontroller in sleep (Halt) Mode - Page 1
Forum section: electronics / general

author: Leo86
author_rank: Contributor
timestamp: August 31, 2020, 02:02:55 pm
content: Hi everyone!I have an application where my microcontroller STM8L stay in Halt mode for saving energy. And is wake-up with an extern interrupt (BUTTON), to transmit a code by RF.The problem is debounce in moment that microcontroller wake-up by BUTTON for transmit code RF.Depending on the noise of the debounce the microcontroller does not transmit because I was unable to make a debounce deal.I already debounce by firmware but with the microcontroller running, using this: (https://my.eng.utah.edu/~cs5780/debouncing.pdf). But not with him sleeping.Does anyone have an aplication note that can help me?

author: PCB.Wiz
author_rank: Super Contributor
timestamp: August 31, 2020, 09:07:23 pm
content: Quote from: Leo86 on August 31, 2020, 02:02:55 pmYou need to be clearer here.Does it always fail, or only sometimes ?When it does fail, does it txmit twice, or never ?In any Halt mode MCU, you cannot debouncewhileit is asleep, as the clocks are stopped, and the first level change is what wakes the MCU up & starts the clocks.After the wake-up delay, now you have full SW activity, and from here, you can check the pin any number of times to debounce as needed.

author: bson
author_rank: Unknown
timestamp: August 31, 2020, 09:38:17 pm
content: Just determine the time point at which you can send the next code. If you get woken multiple times before then, due to button noise or any other spurious cause, it's no big deal as long as you don't send another code. Since you can't send a code there's no point even checking the button, just go back to sleep.

author: Mecanix
author_rank: Frequent Contributor
timestamp: August 31, 2020, 11:32:01 pm
content: Scope shots of the actual behavior under several interrupt priority levels are required for us to debug this remotely.

author: Leo86
author_rank: Contributor
timestamp: September 01, 2020, 04:27:14 am
content: it'is my logic for debounce in interrupt external, when the microcontroller wake up.Basictly i have a timer (TIMER 4 STM8L), that overflow 1ms. is only activated when an external interruption occurs.INTERRUPT_HANDLER(EXTI1_IRQHandler,9){debounceTimerSet(TIMEOUT_DEBOUNCE); // Load timeout 30ms. TIMEOUT_DEBOUNCE = 30TIM4_Cmd(ENABLE); // Enable timer 4 (overflow 1ms)EXTI_ClearITPendingBit(EXTI_IT_Pin1); // Clean flag}While there is a variation in the key, the timer is being loaded. if end variation, the timeout will overflow.INTERRUPT_HANDLER(TIM4_UPD_OVF_TRG_IRQHandler,25) //1ms{debounceTimerProc();TIM4_ClearITPendingBit(TIM4_IT_Update);}void debounceTimerProc(void){if(timeOutDebounce){if(!(--timeOutDebounce) ){readButtons();TIM4_Cmd(DISABLE); // timer off}}}// When call readbutton dont has VARIATIONS.void readButtons (void){if(GPIO_ReadInputDataBit(GPIOA, BTN1_PIN) == 0){btn |= BTN_D0;}if(GPIO_ReadInputDataBit(GPIOB, BTN2_PIN) == 0){btn |= BTN_D1;}if(GPIO_ReadInputDataBit(GPIOC, BTN3_PIN) == 0){btn |= BTN_D2;}if(GPIO_ReadInputDataBit(GPIOB, BTN4_PIN) == 0){btn |= BTN_D3;}if( (GPIO_ReadInputDataBit(GPIOA, BTN1_PIN))&&(GPIO_ReadInputDataBit(GPIOB, BTN2_PIN))&&(GPIO_ReadInputDataBit(GPIOC, BTN3_PIN))&&(GPIO_ReadInputDataBit(GPIOB, BTN4_PIN)) ){btn = 0; // Without press}}That's the logic to debounce. Has something wrong?

author: Mecanix
author_rank: Frequent Contributor
timestamp: September 01, 2020, 08:08:48 am
content: Depending on what else is being triggered in your program I'd look into priority levels for your interrupt(s) (one, or more, might be blocking the other). Start there and see if this helps a bit.ps. although you've cleverly done it the right way in your code, interrupt delay logic doesn't work very well with noisy external button. Needs to be fitted/debounced with capable hardware at the first place e.g. schmitt trigger inverter. If integrity isn't too important, a cap & a resistor and good software priority level practices is often sufficient...

author: hamster_nz
author_rank: Super Contributor
timestamp: September 03, 2020, 08:03:52 am
content: Why not wake on button, send the signal then sleep on just a timer for the rest of the debounce period.Once that timer goes off, then sleep on button again.

author: SiliconWizard
author_rank: Super Contributor
timestamp: September 03, 2020, 03:50:23 pm
content: Why would you need to debounce for a wake-up condition, to begin with?A typical pushbutton will "bounce" when you press on it, but when you leave it alone, it won't (otherwise choose something else really.)The first detected press on the button will wake up the MCU. Once it wakes up, I don't think it's hard at all to ignore further presses for a while anyway. As I got it, you transmit something through RF: then just ignore button presses while it transmits. What's the problem really? Not sure I got it.