Counting Rotations on absolute encoder
Show older comments
Hello!
I am trying to count the number of rotations on an absolute encoder. I need to be able to count in both directions, so if the encoder spins forward, and then back, I would need the relative number of rotations from the starting position.
The encoder outputs and angle value from 0 to 255. I tried a set of if statments but the way I set it up was not logically sound.
How should I go about this?
function y = fcn(u)
% u is a value from 0 to 255
% y needs to be a value from 0 to 255 from x rotations of the encoder
c=0;
v=0;
if (u == 255) && (c==0)
c=1;
elseif (u > 254) && (c==1)
c=2;
elseif (u > 254) && (c==2)
c=3;
elseif (u > 254) && (c==3)
c=4;
x= 0.33;
z= u+c*255
y = x*z;
Answers (0)
Categories
Find more on Simulink 3D Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!