Debouncing multiple inputs

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

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

0 Likes
23 Replies
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Please post your program so we can check it. Also what device are you using?

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Here you go.

   

I am using PSOC 4100 series. (CY8C4124PVI-432)

   

Rick

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

0 Likes
Anonymous
Not applicable

If I use a timer interrupt can I ready frequencies within the range of .3hz-1khz?

   

Rick

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

0 Likes
Anonymous
Not applicable

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

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Did you check with a scope or logic analyzer if and how long the signals bounce?

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I dont see the noise on the flow sensors only the rain sensor. Rain sensor noise ranges from 1-2ms.

   

Rick

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

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. 

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Here are some examples of rain sensors.

   

   

0 Likes
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Here is the CapSense design guide.

0 Likes
Anonymous
Not applicable

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

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

0 Likes
Anonymous
Not applicable

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

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Here is a circuit you just need to add these components on to your project.

   

   

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Here is some software Debouncing examples.

   

0 Likes
Anonymous
Not applicable

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

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

@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

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Its a digital signal. Might have noise when there are low frequencies around .3 - 4 hz.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

0 Likes
Anonymous
Not applicable

Do you have an example project for this?

   

Thanks,

   

Rick

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

In Creator right click on the comparator component in the component catalog and select "Find code example".

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Bob,

   

Thank you for your help.

   

 

   

Rick

0 Likes