Setting up EMC2 for hobbing.
As show in this video:
http://www.youtube.com/user/blyndpew#p/a/f/0/ZhICrb0Tbn4
The hardware aspects are fairly clearly shown in the video, the only other things needed are a Pyvcp panel with a spinbox in it for tooth count (which should be wired to the invert.0.in pin in the posgui.hal file, and these some extra lines in the main HAL file:
loadrt invert count=1 # no divide in hal, so use invert and scale
loadrt scale count=1 # scale is used to divide the spindle command by the gear ratio
loadrt mux2 count=1 # the mux is used to store the offset as a sample-and-hold
loadrt ddt count=1 # used for change detection in the gear ratio to reset the axes
loadrt abs count=1
loadrt comp count=1 # convert non-zero to toggle a bit on change
addf invert.0 servo-thread #mult and invert are used to divide by the gear ratio
addf scale.0 servo-thread
addf mux2.0 servo-thread
addf ddt.0 servo-thread
addf abs.0 servo-thread
addf comp.0 servo-thread
# A-Axis
setp hm2_7i43.0.stepgen.03.step_type 0
setp hm2_7i43.0.stepgen.03.position-scale [AXIS_3]SCALE
setp hm2_7i43.0.stepgen.03.steplen [AXIS_3]STEPLEN
setp hm2_7i43.0.stepgen.03.stepspace [AXIS_3]STEPSPACE
setp hm2_7i43.0.stepgen.03.dirhold [AXIS_3]DIRHOLD
setp hm2_7i43.0.stepgen.03.dirsetup [AXIS_3]DIRSETUP
setp hm2_7i43.0.stepgen.03.maxaccel [AXIS_3]STEPGEN_MAXACCEL
setp hm2_7i43.0.encoder.00.scale -200
# Electronic gearing of stepgen position to encoder position
net invratio invert.0.out => scale.0.gain ddt.0.in # the ratio is linked in the postgui.hal to invert.0.in
net spindlepos hm2_7i43.0.encoder.00.position => scale.0.in
net gearpos scale.0.out => hm2_7i43.0.stepgen.03.position-cmd
net aenable axis.3.amp-enable-out => hm2_7i43.0.stepgen.03.enable => hm2_7i43.0.gpio.044.out
# Reset Logic. Zeroes the encoder and stores the current stepgen position as an offset.
# This is to prevent the gear rotating on tooth-count changes (often quite interminably)
net scale-change ddt.0.out => abs.0.in
net abs-scale-change abs.0.out => comp.0.in1
setp comp.0.in0 0.01 # this is looking for changes in 1/teeth as the raw value is not available until postgui.hal has run
net reset-spindles comp.0.out => hm2_7i43.0.encoder.00.reset mux2.0.sel # this bit toggles high on a ratio change
net sample-hold mux2.0.out => mux2.0.in0 scale.0.offset # the mux is wired to itself as a floating point sample-and-hold
net gear-spindle-position hm2_7i43.0.stepgen.03.position-fb => mux2.0.in1 # wire the stepgen position to the sample and hold, and thence to the scale