Hmm, I am using the GHI button module, assuming it uses the interrupt port.
Consider the case where you press the button really quickly 10 times, and every click triggers the button-press event code where there is a write to a log-file on SD-card with sleeps and all that stuff. I dont see all presses.
I think they queue hardware interrupts somewhere internally, and sooner or later, they will all fire. Even if the MCU core is stopped, hardware interrupts are saved — at least that’s what I observe with my CAN bus. If the CAN traffic is high and I stop the core for some debugging, later I have to wait until thousands of RXOVER events are raised…
Interesting. So why move the heavy stuff into a separate thread. I don’t care about speed at all - as long as I press five times and there are five events…
@ njbuch - I would have an interrupt handler that all it did was record the button event in a Queue. Then in a separate thread process the events. This way you wont loose any events and it doesn’t matter that much how long it takes to process each event. Asynchronous events are best handled using interrupts and queues. If not you always stand a chance of missing one.
Thanks everybody. I have coded a seperate thread for the events, and a seperate worker thread. The events just enqueue a number, and the worker thread just takes a task from the queue. Works better, but not 100%
It works best with the event thread having highest priority.
I have realized that holding the button down for longer time, not only waiting for the click, but really holding it, ensures the button press. Users wont do that.
My guess is that I am catching about 90% of button presses.
So I am left with the following questions:
What is a good quality button? And where to buy it?
I don’t know for sure but I suspect the button handler is running as a thread and not an interrupt and therefore your losing some of the events because of the time slicing. I use an interrupt on an IR input which has a burst of 40 k hz and I don’t miss any. If I get some time I will code up a interrupt on a button and see if its any different.
Actually “Buttons” are easy if the button has form C contacts tied to a latch where the NO is tied to the set input and NC is tied to the reset of the latch. This takes care of the bounce. Then you just tie it to an interrupt and your done.