Encoder question

More
27 Aug 2026 15:51 #349053 by Tinker
Encoder question was created by Tinker
Good morning gents!! 
I was wondering if a cheap amazon Incremental rotary encoder (5 wire including ground/shield) could be used for a 4th axis? I am using a Mesa 7i97T board and am experiencing so difficulty with it. I can see it count in Hal show but when i try to use it in real time it keeps erroring out...
Once again thank you to all the experts that make this possible!!! 
 

Please Log in or Create an account to join the conversation.

More
27 Aug 2026 16:07 #349054 by PCW
Replied by PCW on topic Encoder question
You can use single ended (5 wire) encoders with the 7I97/7I97T
as long as the three 7I97/7I97T encoder jumpers for the single ended
encoder are in the single ended/TTL positions (right hand position)

What error do you get?

Please Log in or Create an account to join the conversation.

More
27 Aug 2026 16:17 #349055 by Tinker
Replied by Tinker on topic Encoder question
The 4th jerks when I enable the machine and i get a following error. The only way I can get it to work is if I enter a crazy high pulse count. It will rotate but with terrible accuracy, like 1 revolution shows a couple of degrees of rotation.

Please Log in or Create an account to join the conversation.

More
27 Aug 2026 16:27 #349056 by Tinker
Replied by Tinker on topic Encoder question
I just checked and they are in the left hand position.... I'm going to swap them over and give it a try!! Thank you as always for your help. 

Please Log in or Create an account to join the conversation.

More
27 Aug 2026 16:37 #349057 by PCW
Replied by PCW on topic Encoder question
An immediate following error may also be because the feedback is backwards.
(if the encoder is scaled right and has the correct direction, you may need to
reverse the analog output polarity in the hal file)

Please Log in or Create an account to join the conversation.

More
27 Aug 2026 19:40 #349059 by Tinker
Replied by Tinker on topic Encoder question
Ok, thank you.. thats what im getting. i will try that next.

Please Log in or Create an account to join the conversation.

More
27 Aug 2026 20:15 #349061 by Tinker
Replied by Tinker on topic Encoder question
So not i get no motion and an immediate following error. Before i would get a small amount of rotation but no counts in both configurations. Keep in mind this is a cheap amazon encoder that might just be a piece of junk. When I swapped this 4th from a resolver to an encoder i was able to see like 1440 0r so counts per encoder revolution but for some reason linux just doesnt like this guy. Not a problem, i can get one that y,all recommend.. i just dont know which one to get. It would be nice if I could get this one to work because I had to design/print a new riser/mount to fit the analigm dc servo... I can send you a link to the encoder that i bought if that might help....

Please Log in or Create an account to join the conversation.

More
27 Aug 2026 20:31 #349062 by PCW
Replied by PCW on topic Encoder question
You should be able to debug the encoder issue by monitoring these pins::

hm2_7i97.0.encoder.0N.input-a
hm2_7i97.0.encoder.0N.input-b

in halshows 'Watch' tab

Where N is the number of the encoder you want to monitor (0..5)

These pins should toggle as you rotate the encoder

If the a or b hal pins do not change, you can trace back to the hardware
by measuring the voltage at the 7I97 encoder input pins, these should
toggle between near 0V and say +3V to +5V
The following user(s) said Thank You: Tinker

Please Log in or Create an account to join the conversation.

More
06 Sep 2026 20:39 #349398 by Tinker
Replied by Tinker on topic Encoder question
So the encoder is now counting but the 4th just slowly rotates until I get a following error. This encoder does not have an index wire, do i need to change anything in my hal file? I was thinking this might have something to do with the random motion...
Thank you for your help!! 

# This file was created with the Mesa Configuration Tool on Aug 27 2026 19:07:25
# If you make changes to this file DO NOT run the configuration tool again!
# This file will be replaced with a new file if you do!

# kinematics
loadrt [KINS](KINEMATICS)

# motion controller
loadrt [EMCMOT](EMCMOT) servo_period_nsec=[EMCMOT](SERVO_PERIOD) num_joints=[KINS](JOINTS)

# hostmot2 driver
loadrt hostmot2
loadrt [HM2](DRIVER) board_ip=[HM2](ADDRESS) config="num_encoders=6 num_pwmgens=6 sserial_port_0=00000000"

setp hm2_[MESA](BOARD).0.watchdog.timeout_ns 7500000

loadrt pid names=pid.x,pid.y,pid.z,pid.a

# THREADS
addf hm2_[MESA](BOARD).0.read servo-thread
addf motion-command-handler servo-thread
addf motion-controller servo-thread
addf pid.x.do-pid-calcs servo-thread
addf pid.y.do-pid-calcs servo-thread
addf pid.z.do-pid-calcs servo-thread
addf pid.a.do-pid-calcs servo-thread
addf hm2_[MESA](BOARD).0.write servo-thread

# amp enable
net motion-enable <= motion.motion-enabled

# Global PWM setup
setp hm2_[MESA](BOARD).0.pwmgen.pwm_frequency 75000

# Board: 7i97t

# Axis: X Joint: 0 Output: 0
# PID Setup
setp pid.x.Pgain [JOINT_0](P)
setp pid.x.Igain [JOINT_0](I)
setp pid.x.Dgain [JOINT_0](D)
setp pid.x.bias [JOINT_0](BIAS)
setp pid.x.FF0 [JOINT_0](FF0)
setp pid.x.FF1 [JOINT_0](FF1)
setp pid.x.FF2 [JOINT_0](FF2)
setp pid.x.deadband [JOINT_0](DEADBAND)
setp pid.x.maxoutput [JOINT_0](MAX_OUTPUT)
setp pid.x.error-previous-target True

# joint-0 enable chain
net joint-0-index-enable <=> pid.x.index-enable
net joint-0-index-enable <=> joint.0.index-enable
net joint-0-index-enable <=> hm2_[MESA](BOARD).0.encoder.00.index-enable

net joint-0-enable <= joint.0.amp-enable-out
net joint-0-enable => pid.x.enable
net joint-0-enable => hm2_[MESA](BOARD).0.pwmgen.00.enable

# PWM Generator setup
setp hm2_[MESA](BOARD).0.pwmgen.00.dither true
setp hm2_[MESA](BOARD).0.pwmgen.00.output-type 1 #PWM pin0
setp hm2_[MESA](BOARD).0.pwmgen.00.offset-mode 1 # offset mode so 50% = 0
setp hm2_[MESA](BOARD).0.pwmgen.00.scale [JOINT_0]SCALE

# position command and feedback
net joint-0-pos-cmd <= joint.0.motor-pos-cmd
net joint-0-pos-cmd => pid.x.command

net joint-0-pos-fb <= hm2_[MESA](BOARD).0.encoder.00.position
net joint-0-pos-fb => joint.0.motor-pos-fb
net joint-0-pos-fb => pid.x.feedback

# PID Output
net joint.0.output <= pid.x.output
net joint.0.output => hm2_[MESA](BOARD).0.pwmgen.00.value

# Encoder Setup
setp hm2_[MESA](BOARD).0.encoder.00.scale [JOINT_0](ENCODER_SCALE)
setp hm2_[MESA](BOARD).0.encoder.00.counter-mode 0
setp hm2_[MESA](BOARD).0.encoder.00.filter 1
setp hm2_[MESA](BOARD).0.encoder.00.index-invert 0
setp hm2_[MESA](BOARD).0.encoder.00.index-mask 0
setp hm2_[MESA](BOARD).0.encoder.00.index-mask-invert 0

# Axis: Y Joint: 1 Output: 1
# PID Setup
setp pid.y.Pgain [JOINT_1](P)
setp pid.y.Igain [JOINT_1](I)
setp pid.y.Dgain [JOINT_1](D)
setp pid.y.bias [JOINT_1](BIAS)
setp pid.y.FF0 [JOINT_1](FF0)
setp pid.y.FF1 [JOINT_1](FF1)
setp pid.y.FF2 [JOINT_1](FF2)
setp pid.y.deadband [JOINT_1](DEADBAND)
setp pid.y.maxoutput [JOINT_1](MAX_OUTPUT)
setp pid.y.error-previous-target True

# joint-1 enable chain
net joint-1-index-enable <=> pid.y.index-enable
net joint-1-index-enable <=> joint.1.index-enable
net joint-1-index-enable <=> hm2_[MESA](BOARD).0.encoder.01.index-enable

net joint-1-enable <= joint.1.amp-enable-out
net joint-1-enable => pid.y.enable
net joint-1-enable => hm2_[MESA](BOARD).0.pwmgen.01.enable

# PWM Generator setup
setp hm2_[MESA](BOARD).0.pwmgen.01.dither true
setp hm2_[MESA](BOARD).0.pwmgen.01.output-type 1 #PWM pin0
setp hm2_[MESA](BOARD).0.pwmgen.01.offset-mode 1 # offset mode so 50% = 0
setp hm2_[MESA](BOARD).0.pwmgen.01.scale [JOINT_0]SCALE

# position command and feedback
net joint-1-pos-cmd <= joint.1.motor-pos-cmd
net joint-1-pos-cmd => pid.y.command

net joint-1-pos-fb <= hm2_[MESA](BOARD).0.encoder.01.position
net joint-1-pos-fb => joint.1.motor-pos-fb
net joint-1-pos-fb => pid.y.feedback

# PID Output
net joint.1.output <= pid.y.output
net joint.1.output => hm2_[MESA](BOARD).0.pwmgen.01.value

# Encoder Setup
setp hm2_[MESA](BOARD).0.encoder.01.scale [JOINT_1](ENCODER_SCALE)
setp hm2_[MESA](BOARD).0.encoder.01.counter-mode 0
setp hm2_[MESA](BOARD).0.encoder.01.filter 1
setp hm2_[MESA](BOARD).0.encoder.01.index-invert 0
setp hm2_[MESA](BOARD).0.encoder.01.index-mask 0
setp hm2_[MESA](BOARD).0.encoder.01.index-mask-invert 0

# Axis: Z Joint: 2 Output: 2
# PID Setup
setp pid.z.Pgain [JOINT_2](P)
setp pid.z.Igain [JOINT_2](I)
setp pid.z.Dgain [JOINT_2](D)
setp pid.z.bias [JOINT_2](BIAS)
setp pid.z.FF0 [JOINT_2](FF0)
setp pid.z.FF1 [JOINT_2](FF1)
setp pid.z.FF2 [JOINT_2](FF2)
setp pid.z.deadband [JOINT_2](DEADBAND)
setp pid.z.maxoutput [JOINT_2](MAX_OUTPUT)
setp pid.z.error-previous-target True

# joint-2 enable chain
net joint-2-index-enable <=> pid.z.index-enable
net joint-2-index-enable <=> joint.2.index-enable
net joint-2-index-enable <=> hm2_[MESA](BOARD).0.encoder.02.index-enable

net joint-2-enable <= joint.2.amp-enable-out
net joint-2-enable => pid.z.enable
net joint-2-enable => hm2_[MESA](BOARD).0.pwmgen.02.enable

# PWM Generator setup
setp hm2_[MESA](BOARD).0.pwmgen.02.dither true
setp hm2_[MESA](BOARD).0.pwmgen.02.output-type 1 #PWM pin0
setp hm2_[MESA](BOARD).0.pwmgen.02.offset-mode 1 # offset mode so 50% = 0
setp hm2_[MESA](BOARD).0.pwmgen.02.scale [JOINT_0]SCALE

# position command and feedback
net joint-2-pos-cmd <= joint.2.motor-pos-cmd
net joint-2-pos-cmd => pid.z.command

net joint-2-pos-fb <= hm2_[MESA](BOARD).0.encoder.02.position
net joint-2-pos-fb => joint.2.motor-pos-fb
net joint-2-pos-fb => pid.z.feedback

# PID Output
net joint.2.output <= pid.z.output
net joint.2.output => hm2_[MESA](BOARD).0.pwmgen.02.value

# Encoder Setup
setp hm2_[MESA](BOARD).0.encoder.02.scale [JOINT_2](ENCODER_SCALE)
setp hm2_[MESA](BOARD).0.encoder.02.counter-mode 0
setp hm2_[MESA](BOARD).0.encoder.02.filter 1
setp hm2_[MESA](BOARD).0.encoder.02.index-invert 0
setp hm2_[MESA](BOARD).0.encoder.02.index-mask 0
setp hm2_[MESA](BOARD).0.encoder.02.index-mask-invert 0

# Axis: A Joint: 3 Output: 3
# PID Setup
setp pid.a.Pgain [JOINT_3](P)
setp pid.a.Igain [JOINT_3](I)
setp pid.a.Dgain [JOINT_3](D)
setp pid.a.bias [JOINT_3](BIAS)
setp pid.a.FF0 [JOINT_3](FF0)
setp pid.a.FF1 [JOINT_3](FF1)
setp pid.a.FF2 [JOINT_3](FF2)
setp pid.a.deadband [JOINT_3](DEADBAND)
setp pid.a.maxoutput [JOINT_3](MAX_OUTPUT)
setp pid.a.error-previous-target True

# joint-3 enable chain
net joint-3-index-enable <=> pid.a.index-enable
net joint-3-index-enable <=> joint.3.index-enable
net joint-3-index-enable <=> hm2_[MESA](BOARD).0.encoder.03.index-enable

net joint-3-enable <= joint.3.amp-enable-out
net joint-3-enable => pid.a.enable
net joint-3-enable => hm2_[MESA](BOARD).0.pwmgen.03.enable

# PWM Generator setup
setp hm2_[MESA](BOARD).0.pwmgen.03.dither true
setp hm2_[MESA](BOARD).0.pwmgen.03.output-type 1 #PWM pin0
setp hm2_[MESA](BOARD).0.pwmgen.03.offset-mode 1 # offset mode so 50% = 0
setp hm2_[MESA](BOARD).0.pwmgen.03.scale [JOINT_0]SCALE

# position command and feedback
net joint-3-pos-cmd <= joint.3.motor-pos-cmd
net joint-3-pos-cmd => pid.a.command

net joint-3-pos-fb <= hm2_[MESA](BOARD).0.encoder.03.position
net joint-3-pos-fb => joint.3.motor-pos-fb
net joint-3-pos-fb => pid.a.feedback

# PID Output
net joint.3.output <= pid.a.output
net joint.3.output => hm2_[MESA](BOARD).0.pwmgen.03.value

# Encoder Setup
setp hm2_[MESA](BOARD).0.encoder.03.scale [JOINT_3](ENCODER_SCALE)
setp hm2_[MESA](BOARD).0.encoder.03.counter-mode 0
setp hm2_[MESA](BOARD).0.encoder.03.filter 1
setp hm2_[MESA](BOARD).0.encoder.03.index-invert 0
setp hm2_[MESA](BOARD).0.encoder.03.index-mask 0
setp hm2_[MESA](BOARD).0.encoder.03.index-mask-invert 0

# Standard I/O Block - EStop, Etc
# create a signal for the estop loopback
net estop-loopback iocontrol.0.emc-enable-in <= iocontrol.0.user-enable-out

# Manual Tool Change Dialog
loadusr -W hal_manualtoolchange
net tool-number hal_manualtoolchange.number <= iocontrol.0.tool-prep-number
net tool-change-request hal_manualtoolchange.change <= iocontrol.0.tool-change
net tool-change-confirmed iocontrol.0.tool-changed => hal_manualtoolchange.changed

# tool prep loopback
net tool-prep-loop iocontrol.0.tool-prepare => iocontrol.0.tool-prepared
 

Please Log in or Create an account to join the conversation.

More
06 Sep 2026 21:00 #349399 by PCW
Replied by PCW on topic Encoder question
If you have no position control, I would check:

1. The PID values

2. Does the analog out voltage change as the axis drifts?

3. Does the analog output voltage control the axis velocity?
 

Please Log in or Create an account to join the conversation.

Time to create page: 0.251 seconds
Powered by Kunena Forum