Electronics > Beginners

Need help with my first µC project

<< < (4/5) > >>


--- Quote from: Hero999 on September 30, 2010, 07:20:56 am ---
--- Quote from: ThoWaBu on September 29, 2010, 09:14:01 pm ---I read the BASIC DEBOUNCE does only an double check of state.
--- End quote ---

Something like: Is switch (de)pressed? If yes, wait for a certain length of time. Is switch still (de)pressed?

Yes, that´s it !
It´s not bad,
if the time between the measure is high (save) enough.

But our TO set it to a very low value.

--- Quote ---Do you have a Scope ?
Please draw the Voltage.
You can read the bounce time and set to an correct value.
--- End quote ---
What about using the MCU to time it?

It shouldn't be hard to write a program to time how long it takes for a switch to settle when it's pressed or released.

--- End quote ---

OK, so do it.
Maybe you can draw down an structure chart, or explain your Algorithm.

How can you predict if it is Low or High ?
The only thing is to measure the High an the Low times.
But how long is the minimun High/low Time ?
If you´re smart enough your Algo will detect an Failure.

I think You need a causality -- You need two things to compare.

But the Only thing you get is :  111111111011101101010000111110000000000011101010010010100101111111111111110000010010101010010101
Package                                :   aaaaaaaaa                      xxxxxbbbbbxxxxxxxxxxxxccc                                 dddddddddddddddxxxxx
My Algo above active high   :    12345678901230120101000012345000000000001230101001001010010123456789ABCDE0000010010101010010101

Package a is 9 times long, sure everyone would say its pushed.
But     b is only 5 is it pushed ? I thing a Statistcal analysis would say yes (conditional probability)
Package c is nothing real...
Package d is E long, it must be a long pushed...
The x could be detected as Low.
Everything between is garbage.

What about switch aging ? The bouncing will increase.
The simplest Method (which are the best) is an increase by a save factor of 2...5 !

In real, i saw switches bouncing up to 120ms !!!!
Thats near to the human speed of reaction.
(And it doen´t took 10ms to push/release a switch)

At the Oszi You can estimate the time you need in statistical fluke and multiply by a save factor.

Next I read this : "I tried just polling the key in the main loop (also using DEBOUNCE) and I tried using Timer0 interrupt
to poll the key outside the main loop (the code is there -> Isr_pollkeys:)."

Correct me if I am wrong.
He executes the Basic-Debounce-Monster (i explain later) inside the InterruptServiceRoutine ?
(I can´t read basic -- I am using C)

When right, he´s doing a very nasty thing !

Debounce WAITS for some time, but the ISR is called every second.
It looks not very critical, but *waiting* for an event must not done in an ISR.

ISR´s should be short as possible, so it don´t overrun.
But waiting is arrrghhh.
This got no name !!!

A non waiting algo is the above one.
It must be in the ISR.
It´s not wasting time by setting flags and increase counters...



PS: Waiting is never a good thing for a Processor, but in the main loop it´s OK. Maybr sleep mode is good for you ?


I have to confess I don't understand most of your post :(, not to worry, that's just me being thick.
The one thing I can say, though, is that I'm not using an interrupt to poll my keys.
The polling of the +/- buttons is done in the main loop with the mentioned DEBOUNCE command.
I do however use INT0 for the start/stop button.

I have understood that the ISR's are to be kept as short as possible.



Was für eine Prellzeit hast Du angenommen ?

Der debounce Befehl wartet standardmässig 25ms. Ich habe mit anderen Werten rumgespielt, unter 10ms
kommt das Prellen dann wieder durch, länger als 25ms hatte keine spürbare Auswirkung.
Kommt ja auch auf die Taster an, im Versuchsaufbau sind's noch andere als ich dann nachher verwende.

wow! its getting.... "internationalle"! ;D


[0] Message Index

[#] Next page

[*] Previous page

There was an error while thanking
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod