counting a 2 switch logic circuit
gc3076
Posts: 44
I am still a newbee to the BS2 programming and can't believe what a powerful learning tool this form is, amazing !
I am trying to complete, what I am assuming would be a pretty simple task. I would like to keep a running incremented / decremented real time count of a 2 switch logic circuit.··
Suggested approaches or sample sites would be appreciated................
SW1······ ·SW2
0··············· 0······· no change of state, count remains 0
0··············· 1
····· then·············incremented count, +1
1·············· 0
1·············· 0
····· then··········decremented count, -1
0············· 1
·
I am trying to complete, what I am assuming would be a pretty simple task. I would like to keep a running incremented / decremented real time count of a 2 switch logic circuit.··
Suggested approaches or sample sites would be appreciated................
SW1······ ·SW2
0··············· 0······· no change of state, count remains 0
0··············· 1
····· then·············incremented count, +1
1·············· 0
1·············· 0
····· then··········decremented count, -1
0············· 1
·
Comments
If Button2 pushed Then X = X + 1
If Button1 pushed Then X = X - 1
·
x=0
x=x+1
x=x-1
Here is the thing, I am using 2 stationary hall-effect sensors mounted closely together ·and 1 rotating magnet. I am not sure how to code the below logic.
1. A_hall goes high then B_hal goes high, increment counter (CW) or x=x+1
2. B_hall goes high then ·A_ hall goes high, decrement counter (CCW) or x=x-1
Help !!!!!!!!
Post Edited (gc3076) : 2/16/2006 8:27:36 PM GMT
· An optical encoder wheel·has two sensors and a number of alternating dark and white (or dark and clear) vanes.· The sensors have to be positioned so that neither will transition at the same time.
http://www.active-robots.com/products/motorsandwheels/wheel-encoders.shtml
Post Edited (PJ Allen) : 2/16/2006 8:51:41 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mike
·
A flip-flop is easily accomplished in software by exclusive ORing a bit with 1. This can be seen in the following truth table:
/code
Exclusive OR
Bit with One
1
0 1
1 0
code/
Then you can use the following:
flip_flop var bit
flip_flop = flip_flop ^ 1
ON flop_flop, GOTO Routine1, Routine2
I'm not sure what you were trying to accomplish however.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
I am trying to use the 2(qty) hall sensors, mounted·closely together (stationary) and 1(qty) magnet rotating with a spinning jack screw. I want to keep count of the jack screws rotations and display the·total result of the +·\ - rotations· that happened on a LCD.
-5 CCW + 6 CW = 1 rotation
Cheers,
g.c.
With good nature,
Jim
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
In the end, it seems that it's all about getting the LEDs to blink....
http://www.parallax.com/dl/docs/cols/nv/vol1/col/nv8.pdf
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
6CW-10CCW= 4 revolution result
Will the below/enclosed encoder count CW/CCW revolutions ?
Post Edited (gc3076) : 2/17/2006 7:46:17 PM GMT
Actually --·you're going to get several "clicks"/pulses·per revolution (hence, "16 or 32"), not one pulse per revolution.
Now that you've been a bit more specific about what you're intending to do, what you need is a quadrature encoder. There are Hall Effect quadrature encoders, as well as optical ones, and other types as well.
Allegro makes a nice small Hall Effect one which I've used quite successfully before. You can find it here: http://www.allegromicro.com/sf/3425/
Thanks to Dr. Tracy Allen, here are some excellent applications notes on the use of quadrature encoders with the PBASIC Stamp:
http://www.emesystems.com/BS2fsm.htm#twobit
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->