Skip to main content
17 events
when toggle format what by license comment
Nov 9, 2022 at 14:56 comment added Justme Well, the answer would depend on what other things the MCU does and how, and whether you can even use interrupts, as if there is a long I2C transaction going on to some other devive, you must wait it complete before reading the buttons and then it will be too late already.
Nov 9, 2022 at 13:44 history edited Nick Bolton CC BY-SA 4.0
added 137 characters in body
Jul 30, 2022 at 0:29 vote accept Nick Bolton
Jun 24, 2022 at 17:50 comment added Nick Bolton Oh cool, didn't know that. It's a PCF8574AN, but I can use whatever works.
Jun 24, 2022 at 16:56 comment added Justme Which I2C chip you use to read the buttons? Some I2C chips might have specialized features to assist with this.
Jun 24, 2022 at 13:16 comment added Nick Bolton @TonyM Good point, that'll save adding extra circuitry and components.
Jun 24, 2022 at 13:11 comment added TonyM Don't get the switches to generate the interrupt. Instead, run a timer interrupt to poll the switches. Simplifies the wiring. The interrupt rate would be between, say, 5 and 15 ms depending on what else you've got going on. Debounce the switches by only passing on a switch level when it's been the detected at the same level for three interrupts in succession. The well-written Interrupt Service Routine (ISR) will be very short so add tiny execution overhead and power consumption to the MCU unless it's already loaded to the absolute max.
Jun 24, 2022 at 12:23 answer added Nick Bolton timeline score: 2
Jun 24, 2022 at 12:14 comment added Nick Bolton @Andyaka Ah, now I remembered. It's because the buttons are connected to a shift register (I2C in my case). Perhaps I could connect all buttons to the same interrupt pin, to trigger polling of the shift register? Perhaps that's what you meant.
Jun 24, 2022 at 12:11 comment added Nick Bolton Damn, yes I did think interrupt but not sure why that idea went out of my head! I'll follow this guide: randomnerdtutorials.com/…
Jun 24, 2022 at 12:10 comment added Andy aka Generate an MCU interrupt.
Jun 24, 2022 at 12:09 comment added Bruce Abbott When power consumption is really important, I use the button to turn on the MCU.When it's slightly less important I use wake up on pin change. But your buttons are behind an I2C 'shift register', so I'm not how sure how that would work. Which MCU and which I2C 'shift register' do you have? How low does your power consumption have to be when just waiting for a buuton press?
Jun 24, 2022 at 11:56 comment added Nick Bolton Yeah, but it's because the code is not very efficient. It sounds like you'd propose that the loop speed of the MCU is as fast as possible, and the code should be optimised in this case. I did notice that the faster the loop, the more power-hungry the MCU, so if power conservation was important, would your proposal still be the case?
Jun 24, 2022 at 11:36 comment added Bruce Abbott "Even with a faster loop, it's still possible to miss the pulse from the button press if pressed quickly enough, since the MCU has it's speed limitations, especially if it's doing some intense operation then the loop delay is increased unpredictably." - You can't press and release a button faster than about 10 times per second, so a loop frequency of 50 Hz should be plenty fast enough. Do you have 'intense' operations taking much longer than 20ms that cannot be interrupted?
Jun 24, 2022 at 11:24 history edited Nick Bolton CC BY-SA 4.0
added 86 characters in body
Jun 24, 2022 at 11:18 history edited Nick Bolton CC BY-SA 4.0
added 86 characters in body
Jun 24, 2022 at 11:13 history asked Nick Bolton CC BY-SA 4.0