Hi,
No, I'm sorry, I've misunderstood this. You need to keep track of the old state since 62 are on both sides of 63 there's no way for a simple IF-THEN to determine if the if next commutation "step" should be that equaling encoderstate 60 or 63.
In the forward direction that is not a problem since the same value isn't on both sides of any other value but in reverse it is so you'll have to keep track of the previous state as well.
I must admit though that I still don't understand how this thing work. Let's say the motor is turning forward and then stops at "step" 7, ie EncoderState is 7. It now reverses direction, what is the next expected encoderstate? I don't see 7 in the expected sequence when moving in reverse but it has to be there since, no?
I can't see how the actual numbers can change depending on the direction of rotation. I would guess that if going forward gives you this sequence:
0, 1, 3, 7, 15, 31, 63, 62, 60, 56, 48, 32
the reverse sequence would be:
32, 48, 56, 60, 62, 63, 31, 15, 7, 3, 1, 0
But you're saying it's not. Can you explain, show a diagram or a photo of how this thing works. How can the sensors give out the value 7 in one direction but not in the other? I mean, at that specific rotation angle some sensors are activated and others are not giving the binary value of 7, I can't see how it can be different depending on in which direction the shaft got there.
I'm clearly missing something here but untill I understand how this thing really works there's no use in trying to come up with a solution.
/Henrik.
Bookmarks