switch inputs
Garced Winder
Posts: 4
I recently bought a Propeller kit, just "learning the ropes" if you will. Completed a few of the sample programs and am starting to grasp the unit and its capabilities. I can't find is how to "one shot" a pushbutton input. What I'd like is to increment Index by 1 for every button event (off-on-off) reguardless of on time - this increments Index as long as P18 is held high.
What I'd like is to increment Index by 1 for every button event (off-on-off) reguardless of on time - this increments Index by 1 as long as P18 is held high. Is there a one-shot routine or does that need to be coded? Or status register for i/o pins that can be checked then cleared?
I looked at keyboard.spin, got lost in the assembly. My assembly skills are quite rusty (8088 wayyy back in school)
repeat ! outa 'led on P3 if ina[noparse][[/noparse]18] == 1 'n/o momentary on P18 Index++ waitcnt(clkfreq / Index + cnt)
What I'd like is to increment Index by 1 for every button event (off-on-off) reguardless of on time - this increments Index by 1 as long as P18 is held high. Is there a one-shot routine or does that need to be coded? Or status register for i/o pins that can be checked then cleared?
I looked at keyboard.spin, got lost in the assembly. My assembly skills are quite rusty (8088 wayyy back in school)
Comments
Debouncing is an issue!
Nick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!
The DIY Digital-Readout for mills, lathes etc.:
YADRO
·You may need to experiment with the delay depending on the type of switch. The click action switch I tested with required only about 2 mS but you may require up to 20 or 30 mS. Since the push button is likely to be·operated by a·human the delay will not be·noticed.
BTW what was the purpose of the waitcnt(clkfreq/index·+·cnt) line?
Paul
milli seconds is "ms".
"mS" would be milli Siemens. And that is the inverse of resistance (G = 1/R) AKA conductance.
<http://en.wikipedia.org/wiki/Siemens_(unit)>
Nick, SI-evangelist
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!
The DIY Digital-Readout for mills, lathes etc.:
YADRO
Sorry to be pedantic, but 'mS' is the name of a variable·:-)
This was quite a clever move, as it COULD lead to become a little bit more interested in history. (Who was Volt? Oh it was Volta, Alessandro! And what did he do? Oh dear! Not only a frog eater but a frog tormentor... Sounds like a role model for Dr. Frankenstein....)
Of course there ar many more famous scientists than units... So with Werner Siemens who later became "von Siemens", who was not only a great scientist but also a great industrialist.
Thanks God they stopped then with inverting the units, but - maybe maybe - there is still some for you! I always wondered what a "Silva" could be...
(b) "Bouncing" happens only when closing a switch, no need to debounce when opening it.
Post Edited (deSilva) : 11/9/2007 7:13:17 PM GMT
Can hold switch down as long as you want, only increments by 1.
You can improve it by putting the WAITCNT into the IF.
Note that it will be expected that the kay can be pressed as fast as possible, which is about 10 per second.
What is the meaning of CLKFREG / Index ???
BTW: always insert a space after a [noparse][[/noparse]
http://www.ganssle.com/debouncing.pdf
http://www.elexp.com/t_bounc.htm
Graham
Here's a link to a recent thread that I think covers it rather well
http://forums.parallax.com/showthread.php?p=677248
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Brian
uController.com - home of SpinStudio
PropNIC - Add ethernet ability to your Propeller!
SD card Adapter
I always liked the thorough invstigation of Jack Ganssle, I generally give this reference myself, but I definitely had forgotten the part about opening switches..
The effect itself - as he well describes -is a little bit unclear. It is NOT the mechanical effect when closing a switch... Closing a switch resembles dropping a ball; opening the switch resembles picking it up...
There is always a small inductance involved and local electrical fields at sharp corners maybe can trick a digital circuit into intermediate triggering. Note the time constant for this effect when opening a switch is very different from closing.
SPIN programmers will not need to consider "unclean" effects when closing switches.
The second reference Paul M gave does not sound very reliable wrt to opening switch effects...
But it will do no harm to consider it. It absolutely depends on how short you start looking again for the switch after you noticed it's closing.
I have never used software debouncing for opening switches...