Vista Normal

Hay nuevos artículos disponibles. Pincha para refrescar la página.
AnteayerSalida Principal

Button Debouncing With Smart Interrupts

4 Enero 2025 at 12:00

Debouncing button or switch inputs on microcontrollers can be a challenging problem for those first starting to program these devices. Part of the reason for this difficulty is that real-world buttons don’t behave like the idealized textbook components we first learn about, and therefore need special consideration to operate like one would expect. There are simple ways to debounce inputs like adding a delay after a button is pressed, but for more efficient use of computer resources as well as adding some other capabilities to inputs you might want to look at this interrupt service routine (ISR) method from [Lee] aka [stockvu].

The strategy with this debounce method is not simply to use a single ISR for the button input, but to activate a second timer-based ISR at that time that runs at a certain interval which timestamps any button press and checks the amount of time the button has been active. If it’s under a certain threshold the ISR assumes it’s caused by bounce and blocks the bounce. If the timestamp ages past another longer threshold it knows the button has been released. This method allows on-the-fly adaptation between long button presses and rapid button presses and is capable of debouncing both types.

For those wanting to try this out, [stockyu] has included some example Arduino code for others to use. It’s an interesting take on a solution for a common problem, and puts very little load on the microcontroller. There are about as many ways to debounce inputs as there are microcontroller platforms, though, and you can even use a 555 timer to get this job done which frees up 100% of the microcontroller’s CPU.

Flashy Paper Christmas Tree Does It With a 555

14 Diciembre 2024 at 00:00
Left: the traces of a flashy paper Christmas tree. Right: the finished tree on cardstock.

‘Tis the season for holiday hacks, and [Ben Emmett] is here to remind us that we don’t necessarily need a fancy microcontroller in order to make flashy fun things happen.

Smoothing down the copper traces with a guitar pick.
Smoothing down the copper traces with a guitar pick.

Take this Christmas tree for example, which uses a 555 timer and a CB4017 decade counter in order to drive some blinking LEDs. The ICs are through-hole, making the circuit fairly accessible to new players, but there are a few SMD components that need soldering as well. (More on that later.)

Here, the 555 acts like a clock and drives a square wave. Using the clock as input, the decade counter toggles the output pins one after the other, driving the LEDs to blink in turn. Since there are only eight lights, there is a pause in the light-up pattern, but that could be fixed by wiring decade counter output #9 to the reset pin.

Although function was the main focus circuit-wise, [Ben] managed to lay the traces in the shape of a Christmas tree, which looks great. Having done a similar project in the past, he discovered that the craft cutting machine prefers thick traces and wider spaces between them. This is largely why [Ben] chose to use through-hole ICs.

After laying everything out in KiCad, [Ben] exported the copper layer image for use on the cutting machine. Once it was all cut out, he put it on transfer tape to weed out the extra copper, and get the traces onto cardstock, the final substrate.

This is such a fun project, and we love that the CR2032 that powers it also acts as the stand in its vertical holder. Hit up GitHub if you want to make one for yourself. Want something even more 3D? Check out this hollow tree we saw a few years ago.

❌
❌