PDA

View Full Version : encoder port change



l_gaminde
- 17th September 2009, 21:36
I need some Ideas On how to monitor two pins, which are hooked to a 4 bit encorder, on pin change of state I need to mirror this change of state on two output pins. These output pins are also used to output the state of another input (toggel sw) which is programmed to output a 4 bit state. this is a manual setup where one encoder or one toggel sw(through programming) will output the 4 bit state (not both at the same time) upon pin change. so if they spin the encoder I want that output to be mirrored if they use the toggel sw I want that part of the program to output the state.
I have the toggle sw working I need to have a second input and which ever one is used takes over the program.

I hope this makes sense to someone!

mackrackit
- 17th September 2009, 21:52
I am sure I am missing something ...

Assume both input signals are 0 when idle.
If pinVar1 > 0 then ????
If pinVar2 > 0 then ?!?!

l_gaminde
- 18th September 2009, 16:53
Yea that kindof what I was thinking, but the hard part is that the encorder will not be zeroed It could be in any of 4 places 00,01,11,10 I need a clean quick way of reading change. I can read the port shift left 6 back right 6 and get my two LSB's I need a way to sense change in either bit, or at least encoder direction of change ( this would be best ) then I could feed into my existing program and handle the output. So it would not have to mirror the encorder just give me the direction of movement Left, Right, for each click I would increment my existing program by one, up or down.

I know I not real clear but I really know what I want!! I think

mackrackit
- 18th September 2009, 18:01
Henrik shared some code here that may give you an idea or two.
http://www.picbasic.co.uk/forum/showthread.php?t=11683

l_gaminde
- 18th September 2009, 18:36
Thank you I also did a search (dah) of the fourm and found that if I & the two bits it will give direction I will look all this over and repost if I don't get it.

thanks again

l_gaminde
- 18th September 2009, 19:41
Just so I don't mess anyone up here,This is what will work for me.

Using Xor will give direction.

take the righthand bit of your old value xor it with the lefthand bit of the new value.

if your xor value is 0 the knob is turning clockwise
if your xor value is 1 the knob is turning counter_clockwise