ArmBASIC - contact debouncing

Questions about the BASICtools and MakeItC
Post Reply
KeepItSimpleStupid
Posts: 7
Joined: Fri Nov 30, 2012 5:47 am

ArmBASIC - contact debouncing

Post by KeepItSimpleStupid » Thu Jun 13, 2019 7:43 pm

It might be a good idea to discuss contact debouncing in ARMBASIC.pdf with an example.

e.g.
Use interrupts
Detection of a long and short press.

It's also too basic of a function to not be included. Maybe something like:

e.g. On BUTTON(port, rise/fall, duration) goto <label>

or even

ON BUTTON (port, rise|fall, duration(500,5000,10000)) goto labels(SHORTPRESS, LONGPRESS, REALLYLONG PRESS)

Times are in mS; max of 3 terms, minimum of one term.

Or maybe be able to define a port as a BUTTON

I didn't deal with HOLD.



basicchip
Posts: 956
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: ArmBASIC - contact debouncing

Post by basicchip » Sat Jun 15, 2019 12:45 am

Rather than put everything in firmware (which would require updates all the time), it is better to build BASIC libraries to do that.

Debounce time depends on the type of switch and it can vary a lot.

In our pong example we basically check the button every 15 ms.

viewtopic.php?f=4&t=672&p=2145&hilit=pong

You can interrupt on every change of a switch, or just look for change, then ignore the state for a certain period of time.

basicchip
Posts: 956
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: ArmBASIC - contact debouncing

Post by basicchip » Wed Jun 19, 2019 7:15 pm

We have moved away from the builtin ON type statements, as they are too limiting.

In the blog and forum are now examples of multitasking that can easily handle button debounce.

Another new example in the blog and forum shows an example of generating interrupts on a pin transition.

For a debounce for example a falling edge can generate an interrupt, and then the interrupt can changed to rising edge, but for the debounce time, transitions would be ignored.

Are you looking to debounce a simple button, or something more complex like a scanned keyboard?

PS - glad to hear from you again (KISS)

Post Reply