Counter module misses some edges. Why?
Daniel Nagy
Posts: 26
Hello everyone, I'm a new propeller user, with my first question posted to the forum.
I made a simple test code, to perform edge detection on a simple switch connected to PIN6. (The PIN is pulled to ground with a 100k resistor.)
The code speaks for itself.
What I experience is, that in some cases (within a few secs of continous switch tapping) the edge detection fails, leaves the LED connected to PIN7 goes out of sync compared to LED PIN 15 (used with the with feedback option). The LED PIN7 remains on with the switch released, or remains off with the switch pressed. This means the code missed to detect an edge.
Why?
I made a simple test code, to perform edge detection on a simple switch connected to PIN6. (The PIN is pulled to ground with a 100k resistor.)
The code speaks for itself.
What I experience is, that in some cases (within a few secs of continous switch tapping) the edge detection fails, leaves the LED connected to PIN7 goes out of sync compared to LED PIN 15 (used with the with feedback option). The LED PIN7 remains on with the switch released, or remains off with the switch pressed. This means the code missed to detect an edge.
Why?
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 PUB Main dira[noparse][[/noparse]6]~ dira[noparse][[/noparse]7..15]~~ CTRA[noparse][[/noparse]5..0]:=6 CTRA[noparse][[/noparse]14..9]:=15 CTRB[noparse][[/noparse]5..0]:=6 CTRA[noparse][[/noparse]30..26]:=%01011 CTRB[noparse][[/noparse]30..26]:=%01110 FRQA:=1 FRQB:=1 repeat if PHSA<>0 outa[noparse][[/noparse]8]:=1 phsa~ if PHSB<>0 outa[noparse][[/noparse]8]:=0 phsb~
Comments
If bouncing is faster then the Spin loop, then it can be that phsa counts 2 positive edges, but phsb only 1 negative for example.
Because you clear phsa and phsb one count gets lost.
Try this version:
Andy
Thank you for your suggestion.
Your theory is right I believe, but in practice, decrementing the register reduces the flaws only, not eleminates them.
Continuing your theory, I came up with:
It never misdetect, but has two drawbacks in this form:
1. If one register reaches the positive maximum, it will fail.
2. If the propeller is started with the button pressed, it wont work.
I'm continuing to solve this, but if anyone has the perfect solution, please post it. It must be a basic thing...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com