PDA

View Full Version : Oscillo - readings not clear to me



flotulopex
- 16th December 2006, 10:36
Hello,

As buttons present some difficulties with PICs (bouncing issue), I thought I could try to improve the situation by adding a kind of RC filter (Button_shematic.JPG).

I have connected my oscillo to the circuit and started measurements.

As I am not an expert, I have difficulties to understand what I am reading (I know, it sounds stupid but the oscillo's help file doesn't really help...).

I have setup the oscillo to trigger one button press (at least I think I did so).

Does someone feel comfortable with oscillos and tell me what this trace (Oscillo_Button.JPG) says?

sougata
- 16th December 2006, 11:29
Hi,

PBP takes care of your button debouncing problem. Use the BUTTON function. Besides debouncing it also does some neat autorepeat for you when use it in a loop.

mister_e
- 16th December 2006, 12:10
The oscillo trace show you exactly what is suppose to happen with any mechanical push-button.

theory and explanation bellow
http://www.elexp.com/t_bounc.htm

Solution... there's many different. Using PBP BUTTON command, use Timers interrupts, OR use a simple loop



PushButtonA VAR PORTA.0
'
'
'
'
IF PORTA.0=1 THEN
' Do your Stuff
'
WHILE PORTA.0=1 : Wend ' wait untill push button is release
PAUSE 50 ' Debounce delay
ENDIF

flotulopex
- 16th December 2006, 13:08
Good information.

If I don't like to use the BUTTON command or WHILE/WEND artifices, it's because of this short pause that has to be artificially created to avoir the bouncing.

It sounds silly but I like to hear the button's "click" and see the display (or LED or any other action) react at the same time.

Instead of waiting for the button to debounce, wouldn't there be a solution to use the only the very first raising/falling edge of the signal and make the PIC ignore the following pulses for some milliseconds meanwhile it exectues the program?

mister_e
- 16th December 2006, 14:00
Well, that's what my previous example did?

It read the Button, then 'Do your Stuff' And wait untill you release the button. then debounce it.

If you released the Button before your 'Stuff' is executed, it will just execute the PAUSE 50. No harm at all.

flotulopex
- 16th December 2006, 15:17
I have made a timer using the TMR0 interrupt.

With the settings I use, I can't PAUSE for more than 16ms or I'll miss a tick.

So I have to slice a
PAUSE 50
in
PAUSE 10 : PAUSE 10 : PAUSE 10 : PAUSE 10 : PAUSE 10

But this is not a problem.

I have already used the WHILE/WEND loop followed by a PAUSE. And here, some problems occur from time to time.

I'm not absolutely sure but I think it can miss the "real" button state. The WHILE/WEND loop can "see" a bounce of the button and not the real state of the button you actually want it to have. It may not have the desired effect.

Moreover, this WHILE/WEND loop is a blocking loop since it will prevent the PIC to give the hand to the Interrupt as long as the button is pressed.

I would really prefer some kind of interrupt scanning for a raising/falling edge of I/O ports with an internal routine preventing consecutive (bouncing) inputs whithin a certain time frame.

Maybe something already existing in PICs, maybe something to do?

sougata
- 16th December 2006, 16:08
Hi,


I can't PAUSE for more than 16ms or I'll miss a tick


Look at this: http://www.picbasic.co.uk/forum/showthread.php?t=3251