- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I have multiple inputs I need to debounce. All inputs are measured by GPIO Interrupt rising edge. I'm essentially counting the positive edges (or pulses) to determine the frequency. I have implemented a debouncer that takes in data for 10 states and outputs a debounced value. My problem is that it does not debounce accurately. Any help?
Here is my ISR subroutine:
CY_ISR(PortZeroISR){
uint8 i,j;
State[Index] = PortZero_INTSTAT & (0x07u << PortZero_SHIFT);
++Index;
j=0xFF;
for(i=0; i<10 ;i++)
j = j & State;
Debounced_state = j;
if(Debounced_state == 0x01)
FrequencyCounter++;
if(Index >= 10)
Index = 0;
// Clear Pending Interrupt
isr_PortZero_ClearPending();
// Clear Pin I nterrupt
PortZero_ClearInterrupt();
}
Thank you,
Rick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please post your program so we can check it. Also what device are you using?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
At first: missing
isr_PortZero_StartEx(PortZeroISR);
Keep in mind: All global variables that are changed in an interrupt handler must be declared as "volatile"!!! Explanation here.
I had best experiences with a different approach: I used a timer and checked for a defined number of consecutive states of a pin before it was considered debounced.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If I use a timer interrupt can I ready frequencies within the range of .3hz-1khz?
Rick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Probably not. Debouncing usually needed for mechanical switches only, not for frequencies in the kHz range.
Can you tell us a bit more about your signals and what you want to perform.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have 3 input signals. 2 signals are water flow meters and the other signal is a pulse input signal for measuring rain. I don't need to measure at 1KHz but it would be nice to get around 700 to 1KHz range.
Rick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Did you check with a scope or logic analyzer if and how long the signals bounce?
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I dont see the noise on the flow sensors only the rain sensor. Rain sensor noise ranges from 1-2ms.
Rick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Are you using the Rain sensors that they use for lawns with the micro switch? You should use CapSense to measure the rain. You can also make a pattern of lines on a pc board and check for a change in resistance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here are some examples of rain sensors.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Bobgear,
Thanks for the advice but I am already using a tipping bucket. The bucket tips and sends out a pulse to the micro but there is some noise involved. I want to debounce this using a timer interrupt.
Rick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is a difference between "noise" and "bouncing" which require different actions.
Digital noise can be canceled using a comparator with hysteresis, analog noise by using a (software) filter (averaging).
Bouncing is for digital signals only and describes the switching between two states for a given time until a steady state is reached.
De-bouncing can be made only by waiting for the bouncing time to expire and re-read the digital state. Since bouncing appears at switching on and switching off, both actions have to be solved by the algorithm.
So what are your "noise" and "bouncing" signals?
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for clarifying that for me. I have 2 Noisy signals (Flow sensors) and 1 bouncy signal (Rain Tip bucket). I know how to go about debouncing. For the noise, would filtering out noise be a simple while loop like so?
unsigned char x;
x = 50;
while(x--) {};
Rick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is a circuit you just need to add these components on to your project.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is some software Debouncing examples.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Bobgear,
Thank you for your valuable input. I now know the difference between debouncing and noise related to my signals. I've been trying to debounce all of my signals when in fact it should just be the rain sensor (tip bucket). The flow sensors contain noise so would filtering noise like this work?
unsigned char x;
x = 50;
while(x--){};
Rick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Rick
I cannot see how your while-loop will influence the noise on your signal.
Just for verification: Do the flow sensors deliver a noisy analog signal or a noisy digital signal? A link to the flow sensor datasheet would be helpful.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So use a comparator component with hysteresis and a global signal reference component (to catch comparator's interrupt).
Reference for comparator could be set to 1.6 resp. 2.5V using two resistors. Take care that the sensor's input to PSoC does not exceed Vdda.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Do you have an example project for this?
Thanks,
Rick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In Creator right click on the comparator component in the component catalog and select "Find code example".
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Bob,
Thank you for your help.
Rick