Hello,
peg wrote:
I have often wondered (haven't experienced it, I don't think) whether if you have a bouncy switch and use KBI when you read the state of the port in the isr it might be "bounced" at that instant and you miss it. You could immediatly re-enable ints I guess to try again.
This could be worse if you have throttled back the CPU to save power while nothing much was happening (waked up by the KBI).
If the switch status is read a few microseconds after the initial closure is detected, as would be the case with a normal KBI, I would guess that the result should be valid since mechanical resonances within the switch contacts (the presumed cause of the bounce) are unlikely to act that quickly.
However, it would be a different story if the MCU needed to wake up from stop mode in response to the switch closure, with perhaps one millisecond, or more, of oscillator stabilisation delay. In this case, a more sluggish response would be necessary, with the switch status read after debounce.
In the first case, the de-bounce delay would be non-critical, provided it is sufficiently large. For the second case, the user will notice the delay if it is made too long.
Regards,
Mac