Encoder wheel interpertation
krazyideas
Posts: 119
Just so we're on the same page I'm a begginer at programing.
I have a encoder from USdigital (an E2) and I am trying to create a program that will count the marks on the encoder wheel.
I want it to count up when I turn the motor one way and count down when I turn the motor the other way. I don't care which way is up or down just so long as it is accurate.
The encoder wheel has three outputs pin 0 has the index it shows up once a rotation. Pin 1 has channel A and Pin 2 has Channel B
Channel A and B (or pin 1 and 2) work in this way. when turned clockwise Channel B leads Channel A and when turned counter clockwise Channel A leads B.
The wave looks like this when turned counter clockwise
A..
..........
..........
................ High.........(I had to use the periods so that everything would show
B.......
..........
..........
........... High.................up the way I wanted it to. Sorry)
A............
..........
..........
........Low
B..
..........
..........
..........
..Low
I use the index to start the program at the same location of the motor
I use the Space where both A and B are High for a refferance point.
So I wait till they are both High Then at that point I wait for A or B to go low which would indicate which direction the motor is turning.
If A goes low first then count Up in increments of 1
If B goes low first then count Down in increments of 1
Now that I have explained What I am trying to do NOW THE PROBLEM
Here's my program
Waitpne (|< 0, |< 0, 0)................................(Wait for index)
..Repeat...................................................(Begin counting program)
....Waitpeq (%0110, %0110, 0)...................(Wait for pin 1 and 2 to both be High, aka refferance point)
....if ina[1]~...............................................(If pin 1 goes low first count up)
.......count := count + 1
.......Waitpeq (%0000, %0100, 0)................(Wait for pin 2 to go low so that I only get one pass through the loop
or one increment per Channel A mark)
....if ina[2]~...............................................(Same as above except count down and wait for pin 1 to go low so as
.......count := count - 1.............................................to get only one increment each time through loop without this
.......Waitpeq (%0000, %0010, 0)..............................it counts super fast because the loop is so fast)
WHATS NOT WORKING is that if the "if ina[1]" statements are the only ones that get exicuted. But if I copy and paste the "if ina[2]" statement above the "if ina[1]" statement then it is the only one that gets exicuted
Other then that it works perfect ( I still have to build a reset so that once it reaches 720 or -720(one rotation) the count resets but that is for another time after I get the counter working. it should be easy anyway)
Why I thought this would work is because I thought the repeat command would be constantly checking for one of the if statements to be true and then exicute the first on that becomes true. I guess not
What can I do to make the propellors logic perform
if A and then B occur then do this but
if B and then A occur then do this other thing.
Well that's the best I can discribe the problem I have and why I am Stuck.
Any Help to get me past this hurdle would be apprecated.
Thanks.
I have a encoder from USdigital (an E2) and I am trying to create a program that will count the marks on the encoder wheel.
I want it to count up when I turn the motor one way and count down when I turn the motor the other way. I don't care which way is up or down just so long as it is accurate.
The encoder wheel has three outputs pin 0 has the index it shows up once a rotation. Pin 1 has channel A and Pin 2 has Channel B
Channel A and B (or pin 1 and 2) work in this way. when turned clockwise Channel B leads Channel A and when turned counter clockwise Channel A leads B.
The wave looks like this when turned counter clockwise
A..
..........
..........
................ High.........(I had to use the periods so that everything would show
B.......
..........
..........
........... High.................up the way I wanted it to. Sorry)
A............
..........
..........
........Low
B..
..........
..........
..........
..Low
I use the index to start the program at the same location of the motor
I use the Space where both A and B are High for a refferance point.
So I wait till they are both High Then at that point I wait for A or B to go low which would indicate which direction the motor is turning.
If A goes low first then count Up in increments of 1
If B goes low first then count Down in increments of 1
Now that I have explained What I am trying to do NOW THE PROBLEM
Here's my program
Waitpne (|< 0, |< 0, 0)................................(Wait for index)
..Repeat...................................................(Begin counting program)
....Waitpeq (%0110, %0110, 0)...................(Wait for pin 1 and 2 to both be High, aka refferance point)
....if ina[1]~...............................................(If pin 1 goes low first count up)
.......count := count + 1
.......Waitpeq (%0000, %0100, 0)................(Wait for pin 2 to go low so that I only get one pass through the loop
or one increment per Channel A mark)
....if ina[2]~...............................................(Same as above except count down and wait for pin 1 to go low so as
.......count := count - 1.............................................to get only one increment each time through loop without this
.......Waitpeq (%0000, %0010, 0)..............................it counts super fast because the loop is so fast)
WHATS NOT WORKING is that if the "if ina[1]" statements are the only ones that get exicuted. But if I copy and paste the "if ina[2]" statement above the "if ina[1]" statement then it is the only one that gets exicuted
Other then that it works perfect ( I still have to build a reset so that once it reaches 720 or -720(one rotation) the count resets but that is for another time after I get the counter working. it should be easy anyway)
Why I thought this would work is because I thought the repeat command would be constantly checking for one of the if statements to be true and then exicute the first on that becomes true. I guess not
What can I do to make the propellors logic perform
if A and then B occur then do this but
if B and then A occur then do this other thing.
Well that's the best I can discribe the problem I have and why I am Stuck.
Any Help to get me past this hurdle would be apprecated.
Thanks.
Comments
So for now in order to check a pin for high use if ina[pin] checking for low would be ifnot ina[pin].
I assume you want to get there by yourself rather than use an existing object?
Second I do want to get there myself. But being a beginer I would like to have access to another object that does work with an encoder doing more or less the same thing I am, so I have something to look at when I get stuck again. for ideas.
Third If any one has an idea about this but
I want this motor to spin at about 10_000 RPM. With my encoder counting 720 times a revoultion and how I am getting my program to run will I be able to spin it this fast?
I know the prop is fast (boggles my mind fast) but that is a lot to do in a tiny bit of time?
Thanks Again for your help
John Abshier
You can use the Quadrature Encoder or the Dual Quadrature Encoder Driver in the OBEX
So I racked my head some more I figured it out. What was happining was that the code was going to fast through the repeat loop. More or less how I had the code both the refferance point that I made and what I was thinking was waiting for the next step simple was instead checking if my "if ina[A]" statment was true and then repeating again.
How I fixed it.
So in my first post I asked how could you get the propellor to understand if A and then B happened do one thing but if B and then A happened then do a different thing.
Well you use a nested repeat loop inside the other loop that would quit when something occurs. the First repeat represent waiting for A and the second repeat represents waiting for B. Like this
example.
Repeat
if ina[1]
repeat
if ina[2]
count := count + 1
quit
if ina[3]
count := count - 1
quit
That is not exactly how my code looks that that is the logic I used and it worked great.
Anyway just an update on how I'm doing on my little project. and another thanks for the comments
take care
I don't quite follow your logic here- It looks to me like you are monitoring 3 inputs? ina[1] ina[2] & ina[3] is that correct? Would you mind posting part of your code that deals with this?
Thanks.