⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.xmece.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
4 posts / 0 new
Last post
dx3gerst
Offline
Last seen:3 years 9 months ago
加入:2017-03-29 13:35
Debounce push button

Hi Dialog,

is there already any example for debouncing pushbutton K1 on the Basic Development Board? In my application I want to call different functions depending on the button pressure time.

Thank you!

Device:
MT_dialog
Offline
Last seen:2 months 1 week ago
工作人员
加入:2015-06-08 11:34
Hi dx3gerst,

Hi dx3gerst,

Debouncing and measuring the time that a button stays pressed isn't something that isn't close in implementation, debouncing can measure a few ms (63ms to be more exact), i suppose that you would like to measure how long the button stays pressed when you get an wake up interrupt. In that case you will need additional implementation, most probably with additional timers that will count on press and as soon as you start the timer you should also change the polarity of the interrupt in order to stop the timer counting as soon as the key releases. To be more exact,

  • set up your interrupt in a specific polarity low for instance.
  • as soon as the button gets pressed send a notification to your task in order to start a periodic timer and change the polarity that triggers the interrupt.
  • the timer will count periodically while the button is pressed and count the periods while the button stays pressed.
  • as soon as the button gets released the interrupt will trigger once more and you should send a notification to stop timer and check the value of the timer.

Thanks MT_dialog

dx3gerst
Offline
Last seen:3 years 9 months ago
加入:2017-03-29 13:35
Thanks, with your help I

Thanks, with your help I managed to get the button press time function to work. So now it is possible to run two different functions depending on the button press time.

MT_dialog
Offline
Last seen:2 months 1 week ago
工作人员
加入:2015-06-08 11:34
Hi dx3gerst,

Hi dx3gerst,

There are many ways to do this, as mentioned above an idea would be to set a timer counting periodically and in every timer callback increment a counter and either reset the timer in order to keep counting or have the timer run periodically and keep incrementing the counter every time the timer triggers. When you release the button instruct the timer to stop and check the counter in order to see how long the button was pressed and invoke the corresponding function.

Thanks MT_dialog