- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I need read switch that change status on both edges of input. I placed interrupt but can't solve problem with spikes.
Any of code that make debounce is appreciate.
- Labels:
-
PSoC 4 Architecture
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
There is a Debouncer component in some PSoC 4 devices which you can make use of.
Please refer following application note which provides more information-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I use PROC so I can't use components
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The application note also provides code for debouncing in firmware. Please refer section 5.
-Rajiv
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
chaplin.u,
Debouncing a switch can be a tricky thing. I recommend approach called 'vertical counter':
https://www.compuphase.com/electronics/debouncing.htm
The code is very short and effective. For detecting press / depress events look for last paragraph "A refined debouncing routine".
/odissey1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'll try. I see many strange symbols that I don't familiar ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That vertical counter is a classic , I've used in the past and it works very well.
Using an interrupt is usually a good idea only for some types of signals, latched or that don't ever change "on its will". Nowadays, for simple buttons, I usually check for button state change at periodic intervals and when I detect a change, I read the state again ~50ms after and assume that's the state.
If you insist in using interrupts, for what ever reason (power saving?), then I would set the interrupt on state change and, on interrupt, disable the pin change interrupt, set a timer to wakeup in ~50ms, read the state and then, if you want some hold-off time, set another ~50ms timer before re-enablig the interrupt. The switch bounce will typically occurr within the 1st 50ms, so the interrupt is disabled to make the CPU "blind" to the bounces.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
An approach is to disable the state-change interrupt, setup a small timer to either poll the button state for debouncing, or to delay 50 ms until bouncing is done, and then to re-enable the interrupt on state change once the state of the button has been determined.
With my own application, I was able to leave the interrupt on state-change enabled, and merely add another timer-interrupt for polling the button. I then perform button debouncing whenever either one interrupts until a steady-state is achieved, and then use the results in the application. This allows for multiple button interrupts within the debouncing time period without missing them, and/or having to debounce for longer than necessary (saving up to a full debounce time period of activity, which is up to 50% power savings based on randomness).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
chaplin.u,
Attached is a demo project showing single button debouncind using vertical counters approach. The button is continuously polled at about 250 Hz, and flags are updated on button pressed an released events. This is bare code, not a component, thus should run on PRoC as well.
/odissey1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried all previous variants and it's was not as good as need.
Let's try this.
Thanks !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Did this one work?
/odissey1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
not yet. I'm in vacation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I use PROC so I can't use UDB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can replace the T-Flip-Flop with just a simple WDT to debounce at a fixed polling rate instead, as I believe that is the only thing using UDBs in the picture.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I see that it's make interrupts continuously so it can finish battery very fast.
No good for me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Change it so that the button interrupts fire an ISR directly. Then, when a button interrupt occurs, you can set a 1 ms timer to check the button for 10 presses or so and determine if the button is bouncing or not. Then, once you determine whether the button is no longer bouncing, you can turn off the 1 ms timer and the device can go back into deep sleep.