A bit of a puzzle

Something I am working on is using an encoder (slip ring style) to sense position. I have been trying to make sense of it for a few hours. I thought that I would pose it the forum so the smart guys can take a crack at it.

The attached picture shows what the encoder looks like. It has three tracks. Center is common. It also shows how I have it wired up. I also segmented it into sections that are unique. The yellow do is in the section that represents one extreme of movement, and the green dot represents the other. All sections are used. I am first trying to figure out how it can do that while having both extremes at odd positions. Second is to wire it up in a logical way that makes decoding it easy in software.

There were three encoders in the project similar to this one, but I have managed to decode the other two. This one has me perplexed...

There is one piece missing: the wiper. I didn't look closely at it while I had the gearbox apart because I thought it was straightforward like the others. But based on what I am observing, there must be more than one arrangement of the wipers. I will disassemble it again and take a pic.

leg_encoder.jpg

Looks like there are 9 segments of this switch by looking at your picture.

starting at the yellow segment:
A0
A1
GND only
A2
GND only
A2
A2
A0, A2
And ending at the Green segment

Is there a difference in resistance on each segment? like a volume knob?

Sometimes going old-school on a problem is the best way...

Took measurements, scaled it up, and made a decoder ring out of some transparency so that I could see what was happening inside. Now, I am left with a series of sequences. Still trying to figure out the best way to implement it in code.

Here is the sequence:

/******************************************************************************************************
Wiring:

Gray 	5 M0A Pin 3 of TA7291S H-bridge, pin 1 to Arduino 5
Purple 	6 M0B (-> pin 7 of H-bridge, Pin 6 of Arduino -> Pin 9)

Yellow 	A0 06
Orange 	A1 07
Brown 	A2 10

--------------------------------------------------------------------------------------------------------
These are a pair of legs in an animatronic toy. It goes from standing to sitting, and crosses its legs.
One method, I have started to devise, is to watch for a change of PINC and keep count. The counts then
become the position. 1 is unique and only used during standing. So, I can use that as a *home* position.
And standing only occurs with the motor directed reverse. So, I have a way to move it to a known position
at start up. 5 and 2 also only occur once. 
--------------------------------------------------------------------------------------------------------

currpos = ~PINC & 0x07; //Invert and mask input from Port C


Forward:
1 - Standing			Pos 0
0 - Standing Relaxed		Pos 1
4 - Start of bending		Pos 2
5 - Bent			Pos 3
4 - Bent more			Pos 4
0 - and more			Pos 5
2 - Seated			Pos 6
0 - Starting to lift leg	Pos 7
4 - Leg Up			Pos 8
0 - Leg Crossed			Pos 9

----------------------------------------------------------------------------------------------------
In binary:

001 - Pos 0 - Standing
000
100
101
100
000
010
000
100
000 - Pos 9 - Sitting, Legs crossed
--------------------------------------------------------------------------------------------------
Not inverted:
110
111
011
010
011
111
101
111
011
111
****************************************************************************************************/

Looking for a pattern here to make decoding quick and simple without having to use a ton of conditional statements. I have a little trick in mind, but I haven't cemented it yet, using deduction. I can't always count on the PINC changing idea, because in testing, it seems to count twice some times even though the number hasn't changed. And I need to do it quickly because the motors move quick enough through some of the changes that I could miss it, especially when adding in the other two motors and other routines in the code. I was hoping for one of the bits toggling for every change, but I don't see that happening.

alphaseinor:
Looks like there are 9 segments of this switch by looking at your picture.

starting at the yellow segment:
A0
A1
GND only
A2
GND only
A2
A2
A0, A2
And ending at the Green segment

Is there a difference in resistance on each segment? like a volume knob?

Sorry, I was posting an update while you were posting. I think I solved the positions. There isn't a different resistance for each segment, unfortunately. Though I do wonder if they could each create a different pulse width By counting how long in between each segment. Hmm....

Here is the wiper, BTW:

wiper.jpg

Looking at the pictures and code you supplied I don't think it's an encoder because your sometimes getting same code more than once during a sweep.
Is it maybe a simple sliding switch with 3 poles and as the switch turns it's powering on/off 3 separate motors in a set sequence.

Riva:
Looking at the pictures and code you supplied I don't think it's an encoder because your sometimes getting same code more than once during a sweep.
Is it maybe a simple sliding switch with 3 poles and as the switch turns it's powering on/off 3 separate motors in a set sequence.

Unfortunately, no. The original circuitry has the encoders going in to a port expander IC, then that goes to a CPU. There are 3 motors total and 3 separate encoders. These were meant for position feedback. With the other two, they were fairly straightforward offering a different code for each position and never doubling. This one is the only one that is a bit tricky. I have the encoding all figured out now, just need to figure out how to use it in code without a ton of conditional statements.

You are allowed to have the same pattern more than once in a sweep, as long as you keep track of every pattern change.

Just to make things a bit more clear. The original post with the green and yellow dots were based on an assumption that the three wipers were all in line. After disassembling it again, that isn't the case. So the yellow and green dots are not representative of the extremes. In the newer picture of my decoder ring you can see the stop that is based on the wiper configuration.

I believe that the only task I am left with is to figure out a quick and clever way to decode these into position data. Currently my code is checking for a change in pattern (by storing the previous pattern and comparing) and simply counting them. This gives me a position between 0 and 9. However, I am doing this in the main loop which is not where it would be in final code.

Later, I plan to write some code that will give me the time between pattern changes to see if there is a pattern there. Though, that would end up relying on having very accurate motor speed.

Out of all 10 phases, I am only particularly interested in 4. 3 of them are unique (001,010,101) but the last one is not.