Author Topic: Debounce for microcontroller in sleep (Halt) Mode  (Read 1258 times)

0 Members and 1 Guest are viewing this topic.

Offline Leo86Topic starter

  • Contributor
  • Posts: 25
  • Country: br
Debounce for microcontroller in sleep (Halt) Mode
« on: August 31, 2020, 02:02:55 pm »
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?
 

Offline PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 1546
  • Country: au
Re: Debounce for microcontroller in sleep (Halt) Mode
« Reply #1 on: August 31, 2020, 09:07:23 pm »
Depending on the noise of the debounce the microcontroller does not transmit because I was unable to make a debounce deal.
You 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 debounce while it 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.
 

Offline bson

  • Supporter
  • ****
  • Posts: 2270
  • Country: us
Re: Debounce for microcontroller in sleep (Halt) Mode
« Reply #2 on: August 31, 2020, 09:38:17 pm »
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.
 

Offline Mecanix

  • Frequent Contributor
  • **
  • Posts: 269
  • Country: cc
Re: Debounce for microcontroller in sleep (Halt) Mode
« Reply #3 on: August 31, 2020, 11:32:01 pm »
Scope shots of the actual behavior under several interrupt priority levels are required for us to debug this remotely.
 

Offline Leo86Topic starter

  • Contributor
  • Posts: 25
  • Country: br
Re: Debounce for microcontroller in sleep (Halt) Mode
« Reply #4 on: September 01, 2020, 04:27:14 am »
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 = 30           
    TIM4_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?
 

Offline Mecanix

  • Frequent Contributor
  • **
  • Posts: 269
  • Country: cc
Re: Debounce for microcontroller in sleep (Halt) Mode
« Reply #5 on: September 01, 2020, 08:08:48 am »
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...
 

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 2803
  • Country: nz
Re: Debounce for microcontroller in sleep (Halt) Mode
« Reply #6 on: September 03, 2020, 08:03:52 am »
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.
Gaze not into the abyss, lest you become recognized as an abyss domain expert, and they expect you keep gazing into the damn thing.
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14482
  • Country: fr
Re: Debounce for microcontroller in sleep (Halt) Mode
« Reply #7 on: September 03, 2020, 03:50:23 pm »
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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf