interfacing an inclinometer (quadrature encoder)
Archiver
Posts: 46,084
I am trying to interface an inclinometer to the BS2-sx to measure angles of
rotation. The device is basiclly a quadrature encoder. I need to be able to
resolve 1 degree and have the unit display -180 to +180 degrees (or 180 to 0
to 180). I have tried various routines to decode the quadrature output signal
and increment a word variable if rotated CCW and decrment it if rotated CW.
The rotation is rather slow so the BS2-SX is able to kkep up with the outputs
from the inclinometer, but I have two inclinometers that both must be decoded
simultaneously. I would appreciate any help with the algorithm for decoding
the inclinometer and more importantly, scaling the value to the 180-0-180
values that are required. Thanks!
[noparse][[/noparse]Non-text portions of this message have been removed]
rotation. The device is basiclly a quadrature encoder. I need to be able to
resolve 1 degree and have the unit display -180 to +180 degrees (or 180 to 0
to 180). I have tried various routines to decode the quadrature output signal
and increment a word variable if rotated CCW and decrment it if rotated CW.
The rotation is rather slow so the BS2-SX is able to kkep up with the outputs
from the inclinometer, but I have two inclinometers that both must be decoded
simultaneously. I would appreciate any help with the algorithm for decoding
the inclinometer and more importantly, scaling the value to the 180-0-180
values that are required. Thanks!
[noparse][[/noparse]Non-text portions of this message have been removed]
Comments
The section on two-bit encoders includes code for scanning four of
them at once. The shaft rotation does have to be slow in order for
the BS2 to keep up.
-- Tracy
> I am trying to interface an inclinometer to the BS2-sx to measure angles of
>rotation. The device is basiclly a quadrature encoder. I need to be able to
>resolve 1 degree and have the unit display -180 to +180 degrees (or 180 to 0
>to 180). I have tried various routines to decode the quadrature output signal
>and increment a word variable if rotated CCW and decrment it if rotated CW.
>The rotation is rather slow so the BS2-SX is able to kkep up with the outputs
>from the inclinometer, but I have two inclinometers that both must be decoded
>simultaneously. I would appreciate any help with the algorithm for decoding
>the inclinometer and more importantly, scaling the value to the 180-0-180
>values that are required. Thanks!
result to 180 to 0 to 180 degrees. Can you provide any help with that part of
my requirement? Thanks Again.
[noparse][[/noparse]Non-text portions of this message have been removed]
>result to 180 to 0 to 180 degrees. Can you provide any help with that part of
>my requirement? Thanks Again.
Need a little more information. What count do you get from the
encoder at 180 degrees? Let's say it is 256 steps for a full 360
degree rotation. Then:
degrees = countvalue */ 360 - 180.
Of course there needs to be a zero index point or a pushbutton to set
the zero point manually at the outset.
I've used those routines for water level shaft encoders, where the
motion is slow and even. There is one level gage at each end of a
calibrated flume for flow monitoring. We have an input routine that
allows the user to enter initial values.
-- best regards
Tracy Allen
electronically monitored ecosystems
http://www.emesystems.com
mailto:tracy@e...
Thanks for taking the time to respond to my question. The encoder is a
standard quadrature encoder that outputs one pulse on the A channel and one
pulse on the B channel (90 degrees out of phase with A) for every 0.1 degree
of rotation. Therefore at 360 degrees the encoder will have output 3600
pulses. So at 180 degrees the count would be 1800 assuming rotation in the
same direction. I am resetting the count at initialization so it always
starts at 0.0 degrees regardless of the actual position of the unit. I am
not using the index pulse since it is irrelevant. All I am looking at is a
relative rotation from where ever it was initialized at. My biggest problem
is scaling the result so that I never go over 1800 and I never go less than
0. If I initialize to 0 degrees then rotate CCW 90 degrees the output should
be 900, if I then rotate CW by 45 degrees the output should be 45. If I
continue to rotate CW another 90 degrees, the output should decrease to 0
then increase to 45. I am discarding the sign (+/-) at the end anyway. The
problem is to get it to increase until 1800 count is reached then decrease if
I continue to rotate in the same direction. Likewise, if I rotate in the
opposite direction, the count should decrease until 0 is reached then it
should increase until 1800 count is reached at which time it should begin to
decrease until count 0 is reached etc.
I have looked over the entire section on Math routines on your web site but
have not been able to come up with a workable solution. Thanks for the
help!!!
[noparse][[/noparse]Non-text portions of this message have been removed]
counter var word ' increments/decrements with pulses, twos complement
theta ' var word, we keep this in the range 0 to 3600
phi ' var word, from 0 to 1800
theta = abs counter // 3600
phi = theta - ((theta/1800) * (theta // 1800))
The quantity theta/1800 will be either 0 or 1, in Stamp integer math,
for theta<=1800 or theta>=1800. That means phi=theta when theta<1800
and phi=theta - theta//1800 when theta>=1800. Graph (degrees vs
degrees):
180| o |
o | o o |
o | o o | o
o o o o
______o_______________o_______ 0
0 180 360
-- Tracy
>Tracy,
>Thanks for taking the time to respond to my question. The encoder is a
>standard quadrature encoder that outputs one pulse on the A channel and one
>pulse on the B channel (90 degrees out of phase with A) for every 0.1 degree
>of rotation. Therefore at 360 degrees the encoder will have output 3600
>pulses. So at 180 degrees the count would be 1800 assuming rotation in the
>same direction. I am resetting the count at initialization so it always
>starts at 0.0 degrees regardless of the actual position of the unit. I am
>not using the index pulse since it is irrelevant. All I am looking at is a
>relative rotation from where ever it was initialized at. My biggest problem
>is scaling the result so that I never go over 1800 and I never go less than
>0. If I initialize to 0 degrees then rotate CCW 90 degrees the output should
>be 900, if I then rotate CW by 45 degrees the output should be 45. If I
>continue to rotate CW another 90 degrees, the output should decrease to 0
>then increase to 45. I am discarding the sign (+/-) at the end anyway. The
>problem is to get it to increase until 1800 count is reached then decrease if
>I continue to rotate in the same direction. Likewise, if I rotate in the
>opposite direction, the count should decrease until 0 is reached then it
>should increase until 1800 count is reached at which time it should begin to
>decrease until count 0 is reached etc.
> I have looked over the entire section on Math routines on your web site but
>have not been able to come up with a workable solution. Thanks for the
>help!!!
theta = abs counter // 3600
phi = theta - ((theta/1800) * (theta // 1800))
is:
o o o x o o o o x
| o |
| o | o
o o
______o_______________o_______ 0
0 180 360
Try this:
theta = abs counter // 3600
phi = theta max 1800 - ((theta/1800) * (theta // 1800))
to get this graph
180| o |
o | o o |
o | o o | o
o o o o
______o_______________o_______ 0
0 180 360
I think you can probably get rid of the variable "counter" too.
theta = abs (theta + right - left) // 3600
-- Tracy
moving in the right direction!
[noparse][[/noparse]Non-text portions of this message have been removed]