Waitpeq to monitor a change in 2 pins? Possible????
TJHJ
Posts: 243
Hi all,
So I am trying to pick up a simple optical encoder. I have a cased phototransistor set, and a disc that is cut with missing slots. Each high low transition on a pin is a given distance movement.
My issue is I don’t want to give up 2 cogs to watch the encoders, I don’t mind giving up one…
To monitor just 1 encoder I dedicate off a cog and have it doing the following, I am doing it like this so I don’t miss a transition.
·
·
But can I do something to watch for a change in either pin?
·
I think this will cause it to wait for a matched transition set. Not one or the other.....
I am thinking there is a way to do this alot simpler, but I am getting hung up on my bit math……
Any ideas or help is appreciated.
·
TJ
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I owe everyone here a bunch, So thanks again for answering my dumb questions.
Projects. RG500 ECU system. PropCopter. Prop CanSat. Prop Paste Gun.
Suzuki RG500 in a RGV 250 frame.
Bimota V-Due (Running on the fuel injection system)
Aprilia RS250
So I am trying to pick up a simple optical encoder. I have a cased phototransistor set, and a disc that is cut with missing slots. Each high low transition on a pin is a given distance movement.
My issue is I don’t want to give up 2 cogs to watch the encoders, I don’t mind giving up one…
To monitor just 1 encoder I dedicate off a cog and have it doing the following, I am doing it like this so I don’t miss a transition.
·
Repeat waitpeq(|<XEncoder, |<XEncoder,0) ‘wait for pin high waitpne(|<XEncoder, |<XEncoder,0) ‘ wait for low XPosition ++’add to position
·
But can I do something to watch for a change in either pin?
Repeat waitpeq((|< XEncoder & |<Yencoder), ((|< XEncoder & |<Yencoder),0) ‘does it compare the whole mask or just the pins set in state component? waitpne(|< XEncoder & |<Yencoder), ((|< XEncoder & |<Yencoder),0) ‘does it compare the whole mask or just the pins set in state component? HorCurrentPosition ++ if ina[noparse][[/noparse]xEnxoder] == 0 XPosition ++ Elseif ina[noparse][[/noparse]yEncoder] == 0 YPosition ++
·
I think this will cause it to wait for a matched transition set. Not one or the other.....
I am thinking there is a way to do this alot simpler, but I am getting hung up on my bit math……
Any ideas or help is appreciated.
·
TJ
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I owe everyone here a bunch, So thanks again for answering my dumb questions.
Projects. RG500 ECU system. PropCopter. Prop CanSat. Prop Paste Gun.
Suzuki RG500 in a RGV 250 frame.
Bimota V-Due (Running on the fuel injection system)
Aprilia RS250
Comments
-Phil
Post Edited (Phil Pilgrim (PhiPi)) : 10/13/2009 7:05:19 PM GMT
Thanks a bunch Phil, I was thinking way to hard here..
TJ
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I owe everyone here a bunch, So thanks again for answering my dumb questions.
Projects. RG500 ECU system. PropCopter. Prop CanSat. Prop Paste Gun.
Suzuki RG500 in a RGV 250 frame.
Bimota V-Due (Running on the fuel injection system)
Aprilia RS250
Post Edited (TJHJ) : 10/14/2009 6:31:34 PM GMT
NOTE: It's vitally important that ina be read only once in the loop. If your encoder logic needs the value of ina for anything, it will take two lines of code to compute a value for change, viz:
Then use inaval in your code instead of ina. This will prevent weirdness should ina change between reads.
-Phil