Debouncing in PIC18F4520....

Status
Not open for further replies.

mohideen

Member level 2
Joined
Jan 19, 2011
Messages
45
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,580
Hi all,
I am given a task to create a program in PIC18F4520 which
uses 3 switches (toggle switch or push button)
to on 4 LEDs(in any sequence), which at the same time cancels out debouncing.
Hope u guys can help me asap.
Thank you.
 

Hi friend

What you mean for debouncing.
For switch debouncing problem,

You can control switch debouncing by software as well as Hardware.

What is you requirement?

Shyam
 

Hi,

There are 2 methods to cancel out signal bouncing on such switches.
Hardware de-bounce:
This method uses a resister, a capacitor and a schmitt-trigger. Schematic and description can be found on following link; Electronics Tips: Contact Bounce and De-Bouncing

Software de-bounce:
In uC code, when you poll switch, if it is pressed you can allow 10ms~20ms delay and check the situation of switch again; if it is still pressed you may consider switch-pressed, else neglect the situation.

Thank you,
 

You can also use polling in fixed intervals,
for example use a timer and check the buttons port every 50ms to see if a button is presses,
that way you avoid detecting a button as pressed multiple times because of bouncing.

The other solution is to add a delay


I don't think there is a need for hardware solution when mce can do this very easily and without additional expense.

Alex
 

I need to cancel out the bouncing of switch using delay and then i need to light up the LEDs.
Thanks shyam.

---------- Post added at 22:01 ---------- Previous post was at 22:00 ----------

When can i find this program?
 

Hi friend

For code of debouching of switch,
I give you one sample code below

/***************************

#define SwitchA PORTBbits.RB0

char KEY = 0;

if(Switch == 1) //if Switch is pressed(here 1 = 5V,
// if your pin is 0V when switch is pressed than take Switch == 0)
{
delay(5) // delay of 5 milisecond, Neglect to debouching
if(Switch == 1) //Again check Switch is till pressed
{
KEY = 1; //Switch press is OK
}

}

Hope this is help you

Shyam
 
Denouncing means that you avoid reading spike when polling the switch. When you push a simple switch the signal is not clean as in step signal, it is full with spikes(up and down). The simples method is to poll the pin and validate the level of the switch after several samples.
Regarding canceling the denounce, I did not understand how do you intend to active.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…