Peter Nachtwey
Member
I can see you guys don't take hints. The trick is to use the absolute encoder like an incremental.
Only the bottom 16 bits are required so and the absolute encoder counts with 0xFFFF. A PLC can handle 16 bit numbers easily.
First, find a way to initialize the value inc_counts at startup or homing. In this case you may use the absolute counts to initialize inc_counts.
inc_counts = inc_counts + new_counts - old_counts
This works well with 16 bit math even if the new_counts from the absolute encoder rolls over.
Now it is easy to check to ensure 0 <= inc_counts < 3600
What bothers me is that we are led to believe that 1 count = 0.1 degree exactly.
The resulting code is much less than drbitboy's
It is also easy to add a turn counter.
Notice that the mod() or div() function isn't required after initializing.
The inc_counts could simply be set to 0 after hitting some input if not moving too fast.
Only the bottom 16 bits are required so and the absolute encoder counts with 0xFFFF. A PLC can handle 16 bit numbers easily.
First, find a way to initialize the value inc_counts at startup or homing. In this case you may use the absolute counts to initialize inc_counts.
inc_counts = inc_counts + new_counts - old_counts
This works well with 16 bit math even if the new_counts from the absolute encoder rolls over.
Now it is easy to check to ensure 0 <= inc_counts < 3600
What bothers me is that we are led to believe that 1 count = 0.1 degree exactly.
The resulting code is much less than drbitboy's
It is also easy to add a turn counter.
Notice that the mod() or div() function isn't required after initializing.
The inc_counts could simply be set to 0 after hitting some input if not moving too fast.