Bebounce Switch for PIC

Status
Not open for further replies.
Hello Guys,

I am building a preamp controlled by a PIC using the PGA2310 for volume. I am having some problems with my buttons.
I have momentary push buttons connected directly to the PIC but I have serious debouncing issues. I have used the debounce circuit below but it does not work at all.
Does anyone have any solutions to this problem? I am ripping my hair out!!


Thanks

Lawrence



http://www.mines.edu/Academic/courses/physics/phgn317/lab1/debounce.gif
 
hi Lawrence,
i hate to here a guy ripping out his own hair, maby i can point you in the right direction.
its best to debounce the buttons in software, using a pull up resistor (or pull down) on each button.
you will find lots of examples/ tutorials for this with google.
i would do a seach with something like 'debounce buttons pic' as a starting point.
regards
bob
 
Could try the very simple cap input.

Look at the first page, after the 'start' button, which feeds into the 555 timer.

Depending on the size of the cap and pullup resistor, you control the pulse width. Regardless, it is a very tried and true method. You can hold the start button if you want, and will only get one pulse.

If you need a specific minimum pulse width, the 555 is perfect for that. Restrikes are eliminated.
 

Attachments

Honestly, I would not even contemplate hardware debouncing when using a micro. Why add extra components to a board when less will do. this is especially true of production (even small scale) items. code only costs the first time you do it, you could debounce ten buttons with virtually the same code as one, and you could use the same code for as many units as you like. hardware would require ten times the effort in each unit you assemble.
Easiest way in software is to count the button as pressed down only if two or three consecutive reads (whichever gives reliable debounce for your app) give the same state (either going from pressed to unpressed or vice versa). make readings every 5-10ms so it will seem virtually instantaneous to the user. if the debouncing is not quite good enough, use a longer time or more consecutive readings. depending on the switches, the close or open may bounce less, this can also be taken into account to give a better responce (say wait longer on press than release or vice versa).
 
I FIGURED IT OUT!!!

I didnt use hardware debouncing, I write some code for it and it works great. You should have heard me screaming when it actually worked :happy2:
All I did was to set a count from 0 to 255, 255 times. Then when the button was released the appropriate function was called, otherwise the counter would start again.


Now that one problem is solved now there is another one.
The SPI port on the PIC kicks out 8 bits at a time, the PGA2310 requires a straight 16 bits.
At first I used the SSPIF bit in the PIR1 register to tell me when the transmission was done, but by the time the bit is set SSPBUF goes to 0, and the volumes go crazy.

Does anyone know how to sent a steady 16 bit stream from a PIC to PDA2310?????


Thanks


BTW- the PIC I am using is: 16F877
 
why not write the bytes out manually
pull enable pin down
write first byte :
pull clk down
write first bit
pull clk up
pull clk down
write second bit...
...
write second byte :
...
pull enable pin up

that's how it's being done in my version (using jal), works flawlessly and there is no problem to cascade several chips as well, just make loops while writing out the different bytes

Note that 'my version' is not completely my own design/software, most credits go to Benjamin Hinrichs for that, I'm *still* in the process of modding the software to suit my needs, which involved learning jal in the first place !
 
hope it works for you.

LABEL?L _SHIFT
LOW?T _CS
PAUSEUS?C 064h
SHIFTDATA?T _SDI
SHIFTCLOCK?T _SCLK
SHIFTMODE?C 005h
SHIFTOUT?WC _VOL, 010h
HIGH?T _CS
PAUSEUS?C 064h
HIGH?T _SDI
RETURN?

and
LABEL?L _VOLUME
BUTTONPIN?T _UP
BUTTONDS?C 000h
BUTTONDEL?C 0FEh
BUTTONRATE?C 07Fh
BUTTONTS?C 001h

and
LABEL?L _UP
CMPEQ?BCL _VOL_L, 0FFh, _MAX_LIMIT
ADD?BCB _VOL_L, 001h, _VOL_L
ADD?BCB _VOL_R, 001h, _VOL_R
GOSUB?L _SHIFT
GOSUB?L _DB_VALUE
GOSUB?L _dB_LCD
GOSUB?L _MUTE_LCD
GOTO?L _VOLUME
this is the whole trick of shifting data to a PGA, not many would share it, however, you might check the chipamp section there have been number of threads there on making a pre around PGA including two by me.
Otherwise let me know and I ll try to help you out.
 
Status
Not open for further replies.