1c1 < # Tormach Lathe Simulation HAL file --- > # Tormach Lathe Hal file for Mesa 5I25 5,7c5,8 < loadrt [EMCMOT]EMCMOT base_period_nsec=[EMCMOT]BASE_PERIOD servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[TRAJ]AXES num_dio=9 < loadrt abs count=0 < loadrt pwmgen output_type=0 --- > loadrt [EMCMOT]EMCMOT servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[TRAJ]AXES num_dio=9 > loadrt hostmot2 > loadrt hm2_pci config=" num_encoders=2 num_pwmgens=1 num_3pwmgens=0 num_stepgens=3 enable_raw " > loadrt estop_latch 8a10,11 > #loadrt near > loadrt gearchange count=1 9a13,14 > loadrt machineokdb names=machine-ok-db > 11a17,84 > # as per Peter Wallace to reduce encoder errors from noise > # use the 'raw' interface to set the encoder filter higher to ignore more noise > # this sets how long an encoder signal needs to be stable to be accepted > # register 0x3400 is QfilterRate decimal 13312 > # count rate is ClockLow/(QfilterRate + 2) > # ClockLow is 33 MHz > # setting the filter to 38 (decimal) will allow the encoder to function well past 100 kHz > # lathe encoder is 1200 pulses per rev, 3000 RPM is 60 kHz > # > setp hm2_5i25.0.raw.write_address 13312 > setp hm2_5i25.0.raw.write_data [SPINDLE]ENCODER_FILTER > setp hm2_5i25.0.raw.write_strobe TRUE > > # stabilizes spindle RPM display > loadrt lowpass > setp lowpass.0.gain 0.01 > > # debounce - coolant relay switching noise hammers estop input > loadrt debounce cfg=1,2 > loadrt lut5 > > # used to decode the signal from the lathe control board that encodes > # the door and limit switches as a frequency > loadrt freq2pin personality=0x0004 > setp freq2pin.0.freq-width 200 > setp freq2pin.0.input 0 > setp freq2pin.0.stability-count 25 > setp freq2pin.0.stability-width 20 > setp freq2pin.0.freq-table-00 1800 > setp freq2pin.0.freq-table-01 2000 > setp freq2pin.0.freq-table-02 2200 > setp freq2pin.0.freq-table-03 2400 > setp freq2pin.0.freq-table-04 2600 > setp freq2pin.0.freq-table-05 2800 > setp freq2pin.0.freq-table-06 3000 > setp freq2pin.0.freq-table-07 3200 > setp freq2pin.0.freq-table-08 3400 > setp freq2pin.0.freq-table-09 3600 > setp freq2pin.0.freq-table-10 3800 > setp freq2pin.0.freq-table-11 4000 > setp freq2pin.0.freq-table-12 4200 > setp freq2pin.0.freq-table-13 4400 > setp freq2pin.0.freq-table-14 4600 > setp freq2pin.0.freq-table-15 4800 > addf freq2pin.0 servo-thread > > ############################################################################# > # servo thread > > addf lut5.0 servo-thread > addf debounce.0 servo-thread > addf debounce.1 servo-thread > > ######################################################################## > # noise debounce for estop > # debounce.0 no longer used but left installed for the time being > # temporarily bump from 150 ms to 850 ms to debug seemingly random e-stops > #setp debounce.0.delay 850 > ###### estop debounce > addf machine-ok-db servo-thread > setp machine-ok-db.delay 850 > > # limit and door switches > setp debounce.1.delay 10 > > addf hm2_5i25.0.read servo-thread > addf hm2_5i25.0.write servo-thread > addf hm2_5i25.0.pet_watchdog servo-thread 13,14c86 < # Add RT components to threads < addf pwmgen.make-pulses base-thread --- > addf lowpass.0 servo-thread 15a88 > # always needed 18,19c91,96 < addf abs.0 servo-thread < addf pwmgen.update servo-thread --- > > addf estop-latch.0 servo-thread > > # used by spindle speed > addf gearchange.0 servo-thread > #addf near.0 servo-thread 23,31c100,227 < # Spindle set up < net machine-ok => pwmgen.0.enable < net spindle-pwm pwmgen.0.pwm < setp pwmgen.0.pwm-freq 10000.0 < setp pwmgen.0.scale 3000. < setp pwmgen.0.offset 0. < setp pwmgen.0.dither-pwm true < net spindle-on motion.spindle-on < net spindle-dir motion.spindle-reverse --- > addf prog-not-idle servo-thread > > > ############################################################### > # 5i25 watchdog timeout > # 10 milliseconds (~10 times the servo loop period) > setp hm2_5i25.0.watchdog.timeout_ns 10000000 > > ############################################################### > # 5i25 > # Configuration pin-out: > # > # IO Connections for P3 > # Lathe Function Pin# I/O Pri. func Sec. func Chan Pin func Pin Dir > # > # Spindle Speed 1 0 IOPort StepGen 2 Step/Table1 (Out) > # Coolant 14 1 IOPort None > # X Direction 2 2 IOPort StepGen 0 Dir/Table2 (Out) > # Machine OK 15 3 IOPort None (In) > # X Step 3 4 IOPort StepGen 0 Step/Table1 (Out) > # Door Switch 16 5 IOPort QCount 1 Quad-A (In) > # Z Direction 4 6 IOPort StepGen 1 Dir/Table2 (Out) > # ChrgPump/Tool# 17 7 IOPort PWM 0 PWM (Out) > # Z Step 5 8 IOPort StepGen 1 Step/Table1 (Out) > # Spindle Dir 6 9 IOPort None > # ATC Reference 7 10 IOPort None > # ATC Forward 8 11 IOPort None > # Collet Closer 9 12 IOPort None > # Spindle Enc Z 10 13 IOPort QCount 0 Quad-IDX (In) > # Spindle Enc A 11 14 IOPort QCount 0 Quad-A (In) > # Spindle Enc B 12 15 IOPort QCount 0 Quad-B (In) > # Probe 13 16 IOPort None (In) > # > > > ############################################################### > # Spindle speed controlled by frequency > # > # LinuxCNC (rpm) => gearchange (pulse-freq) => stepgen (step & dir) => spindle > # > > setp gearchange.0.min1 [SPINDLE]LO_RANGE_MIN > setp gearchange.0.max1 [SPINDLE]LO_RANGE_MAX > setp gearchange.0.min2 [SPINDLE]HI_RANGE_MIN > setp gearchange.0.max2 [SPINDLE]HI_RANGE_MAX > setp gearchange.0.scale2 [SPINDLE]HI_RANGE_SCALE > setp gearchange.0.sel 1 > > # direction not controlled via gearchanger, so reverse isn't set > # and the dir-in and dir-out pins aren't linked > net spindle-speed-raw motion.spindle-speed-out gearchange.0.speed-in > net spindle-speed gearchange.0.speed-out hm2_5i25.0.stepgen.02.velocity-cmd > > # type 1 velocity control mode > setp hm2_5i25.0.stepgen.02.control-type 1 > > # step/dir > # type 2 quadrature output for 50% duty cycle > setp hm2_5i25.0.stepgen.02.step_type 2 > > # position = counts / position_scale > # this scales the input RPM to the output frequency > # fast spindle pulley 1000 Hz -> 1000 RPM > setp hm2_5i25.0.stepgen.02.position-scale [SPINDLE]LO_SCALE > > # no limit on acceleration > setp hm2_5i25.0.stepgen.02.maxaccel 0 > > # for lathe 5000 Hz/RPM max > # 5000 Hz maximum frequency, position units / second > setp hm2_5i25.0.stepgen.02.maxvel 5000 > > # stepspace in nanoseconds > setp hm2_5i25.0.stepgen.02.stepspace 0 > > # steplen in nanoseconds > setp hm2_5i25.0.stepgen.02.steplen 100000 > > # Spindle run assigned in the the POSTGUI_HALFILE > > # spindle direction, '0' forward, '1' reverse > setp hm2_5i25.0.gpio.009.is_output 1 > setp hm2_5i25.0.gpio.009.is_opendrain 0 > # invert direction signal > setp hm2_5i25.0.gpio.009.invert_output 1 > # connect motion to pin > net spindle-forward motion.spindle-forward => hm2_5i25.0.gpio.009.out > > # door and limit switch > # frequency encoded signal for door and limit switches > # tied to encoder "A" in step/dir mode > setp hm2_5i25.0.encoder.01.counter-mode 1 > # with no "B" dir signal encoder run backwards > setp hm2_5i25.0.encoder.01.scale -1 > # set timeout for slow/no pulses to short amount of time > # in other words drop to zero velocity quickly > setp hm2_5i25.0.encoder.01.vel-timeout 0.010 > net freq2pin-input hm2_5i25.0.encoder.01.velocity => freq2pin.0.input > > net door-switch-in freq2pin.0.output-not-0 > > # limit switch > net limit-switch-in freq2pin.0.output-not-1 > > ######################################################################## > # home + limit switch > > # must noise debounce inputs - otherwise coolant on/off relay can cause spurious estops/limits > net limit-switch-in => debounce.1.0.in > net door-switch-in => debounce.1.1.in > > net all-limit-home <= debounce.1.0.out > > # this truth table makes lut5.0.out false if any inputs are true > # in other words, if any axis is homing all-limit is false > # this avoids limit switch errors while homing > setp lut5.0.function 0x1000000 > net all-limit-home => lut5.0.in-4 > net all-limit <= lut5.0.out > > net homing-x <= axis.0.homing => lut5.0.in-0 > net homing-y <= axis.1.homing => lut5.0.in-1 > net homing-z <= axis.2.homing => lut5.0.in-2 > net limit-switch-enable => lut5.0.in-3 > > # connect to axes > net all-limit-home => axis.0.home-sw-in > net all-limit => axis.0.neg-lim-sw-in axis.0.pos-lim-sw-in 32a229,233 > net all-limit-home => axis.2.home-sw-in > net all-limit => axis.2.neg-lim-sw-in axis.2.pos-lim-sw-in > > > ######################################################################## 34,35c235 < # iocontrol.0.coolant-flood now assigned in the the POSTGUI_HALFILE < # net coolant-flood iocontrol.0.coolant-flood => parport.0.pin-14-out --- > # iocontrol.0.coolant-flood assigned in the the POSTGUI_HALFILE 37,41d236 < # counting the spindle encoder in software < loadrt encoder num_chan=1 < # simulate the encoder < loadrt sim_encoder num_chan=1 < loadrt limit2 count=1 43c238,323 < addf limit2.0 servo-thread --- > ######################################################################## > # Spindle Encoder > setp hm2_5i25.0.encoder.00.counter-mode 0 > > # setting scale negative makes spindle position increase in CW > # and decrease in CCW - if this not done threading and rigid tapping stall > # perhaps swapping the A-B encoder inputs would have the same effect > setp hm2_5i25.0.encoder.00.scale [SPINDLE]ENCODER_SCALE > setp hm2_5i25.0.encoder.00.filter 1 > > # see 'man hostmot2' for descriptions > setp hm2_5i25.0.encoder.00.index-mask 0 > > net spindle-position hm2_5i25.0.encoder.00.position => motion.spindle-revs > net spindle-raw-velocity hm2_5i25.0.encoder.00.velocity => motion.spindle-speed-in lowpass.0.in > net spindle-velocity lowpass.0.out > net spindle-index-enable hm2_5i25.0.encoder.00.index-enable <=> motion.spindle-index-enable > > # note: gpio pins only read at servo thread frequency > # these nodes are only for driving diagnostic "LEDs" in the UI > # this is only going to be useful when the spindle is rotated by hand slowly > net spindle-phase-A hm2_5i25.0.gpio.014.in > net spindle-phase-B hm2_5i25.0.gpio.015.in > net spindle-phase-Z hm2_5i25.0.gpio.013.in_not > > ################################################## > # SPINDLE-AT-SPEED - NOT YET TESTED - NOT ENABLED > ################################################## > ## for at-speed detection > ## +/- 5% for true > #setp near.0.scale 1.05 > ## or with 25 RPM of commanded > #setp near.0.difference 25 > #net spindle-cmd => near.0.in1 > #net spindle-velocity => near.0.in2 > #net spindle-at-speed near.0.out motion.spindle-at-speed > > ######################################################################## > # Charge pump > # pin set by 5i25 configuration > # P3 pin 17 gpio 007 > # duty cycle for tool #1 is 10%, 2 is 20%, 8 is 80%, 90% is non-ATC tool > > setp hm2_5i25.0.pwmgen.00.output-type 1 > setp hm2_5i25.0.pwmgen.pwm_frequency 500 > setp hm2_5i25.0.pwmgen.00.scale 100 > # start with no ATC tool indicated > # actual ATC tool changes handled via tormachltc.comp and the UI > setp hm2_5i25.0.pwmgen.00.value 90 > > net estop-out <= iocontrol.0.user-enable-out > > ######################################################################## > # E stop > > # P3 pin 15 gpio 003 > > # estop noise debounce > # use this line with a machine attached > net machine-ok-raw hm2_5i25.0.gpio.003.in_not => machine-ok-db.in > > # use the setp line below without a machine attached > # this isn't useful unless a properly flashed 5i25 is present > # no machine attached > #setp machine-ok-db.in 1 > > net machine-ok-debounced machine-ok-db.out => estop-latch.0.ok-in > > net estop estop-latch.0.ok-out => iocontrol.0.emc-enable-in => hm2_5i25.0.pwmgen.00.enable > net estop-reset iocontrol.0.user-request-enable => estop-latch.0.reset > > ######################################################################## > # Digital outputs > > # P3 pin 8 gpio 011 > # ATC_FWD > setp hm2_5i25.0.gpio.011.is_output 1 > setp hm2_5i25.0.gpio.011.is_opendrain 0 > setp hm2_5i25.0.gpio.011.out 1 > #net dout-01 motion.digital-out-01 => hm2_5i25.0.gpio.011.out > > ######################################################################## > # Digital inputs > # P3 pin 7 gpio 010 > # ATC_REF - tool change complete > setp hm2_5i25.0.gpio.010.is_output 0 45d324 < addf prog-not-idle servo-thread 47,90c326,335 < ####################################################### < # Beginning of threading related stuff < ####################################################### < < # spindle speed control < net spindle-speed-cmd motion.spindle-speed-out => limit2.0.in < net spindle-speed-limited limit2.0.out => sim-encoder.0.speed < < # simulate spindle mass < setp limit2.0.maxv 500.0 # rpm/second < < # spindle encoder < # connect encoder signals to encoder counter < net spindle-phase-A sim-encoder.0.phase-A => encoder.0.phase-A < net spindle-phase-B sim-encoder.0.phase-B => encoder.0.phase-B < net spindle-phase-Z sim-encoder.0.phase-Z => encoder.0.phase-Z < < # assume 120 ppr = 480 counts/rev for the spindle < setp sim-encoder.0.ppr 120 < # iocontrol output is in rpm, but sim-encoder speed is rps < setp sim-encoder.0.scale 60 < # scale encoder output to read in revolutions < # (that way thread pitches can be straightforward, < # a 20 tpi thread would multiply the encoder output < # by 1/20, etc) < setp encoder.0.position-scale 480 < < # encoder reset control < # hook up motion controller's sync output < net spindle-index-enable motion.spindle-index-enable <=> encoder.0.index-enable < < # report our revolution count to the motion controller < net spindle-pos encoder.0.position => motion.spindle-revs < < # for spindle velocity estimate < loadrt lowpass count=1 < loadrt scale count=1 < net spindle-rps-raw encoder.0.velocity lowpass.0.in < net spindle-rps-filtered lowpass.0.out scale.0.in motion.spindle-speed-in < net spindle-rpm-filtered scale.0.out < setp scale.0.gain 60 < setp lowpass.0.gain .07 < addf lowpass.0 servo-thread < addf scale.0 servo-thread --- > # Tool Changer > > # type of tool changer is set by the UI via tormachltc.0.tool-changer-type > # 0 - manual > # 1 - gang > # 3 - 8 position ATC > > # tool-prepare > # loopback - not needed > net tool-prepare-loopback iocontrol.0.tool-prepare => iocontrol.0.tool-prepared 92,99c337,338 < # for at-speed detection < loadrt near < addf near.0 servo-thread < setp near.0.scale 1.1 < setp near.0.difference 10 < net spindle-speed-cmd => near.0.in1 < net spindle-rpm-filtered => near.0.in2 < net spindle-at-speed near.0.out motion.spindle-at-speed --- > # tool number > net tool-prep-number-to-comp iocontrol.0.tool-prep-number => tormachltc.0.tool-prep-number 101c340,341 < net spindle-fwd <= motion.spindle-forward --- > # ATC tool number PWM duty cycle computed by tormachltc from tool-prep-number > net tool-number-as-pwm tormachltc.0.pwm-duty-cycle => hm2_5i25.0.pwmgen.00.value 103,104c343,349 < addf encoder.capture-position servo-thread < addf sim-encoder.update-speed servo-thread --- > # feedback that tool change is complete > # iocontrol.0.tool-changed needs to go high when tool change is complete > net tool-change-done-from-changer tormachltc.0.tool-changed-out => iocontrol.0.tool-changed > > # this connects the lathe control board tool-changed signal to the HAL comp > # this pin from the lathe control board is active low so invert > net tool-change-done-from-atc hm2_5i25.0.gpio.010.in_not <=> tormachltc.0.atc-tool-changed 106,107c351,374 < addf sim-encoder.make-pulses base-thread < addf encoder.update-counters base-thread --- > # 0 -> 1 iocontrol.0.tool-change begins ATC tool change process for ATC tools > # comp will only pass along to lathe control board for ATC tool numbers > net tool-change-start iocontrol.0.tool-change => tormachltc.0.tool-change-in > > # and connect comp tool-change-out to the lathe control board > net tcout tormachltc.0.tool-change-out => hm2_5i25.0.gpio.011.out > > > ######################################################################## > # collet closer > # > #net dout-02 motion.digital-out-02 => parport.0.pin-09-out > # P3 pin 9 gpio 012 > setp hm2_5i25.0.gpio.012.is_output 1 > setp hm2_5i25.0.gpio.012.is_opendrain 0 > setp hm2_5i25.0.gpio.012.out 0 > net dout-02 motion.digital-out-02 => hm2_5i25.0.gpio.012.out > > ######################################################################## > # Digital input > # SPARE SPARE > # P3 pin 13 gpio 016 > setp hm2_5i25.0.gpio.016.is_output 0 > net din-00 hm2_5i25.0.gpio.016.in => motion.digital-in-00 124,125d390 < # collet closer < net dout-02 motion.digital-out-02 127c392 < # Axes --- > ######################################################################## 129,130c394,397 < # loopback < net axisXpos axis.0.motor-pos-cmd => axis.0.motor-pos-fb --- > # step/dir > setp hm2_5i25.0.stepgen.00.step_type 0 > # position control > setp hm2_5i25.0.stepgen.00.control-type 0 132,134c399,401 < # Z axis < # loopback < net axisZpos axis.2.motor-pos-cmd => axis.2.motor-pos-fb --- > # scaling for position feedback, position command, and velocity command, in steps per length unit. > # converts from counts to position units. position = counts / position_scale > setp hm2_5i25.0.stepgen.00.position-scale [AXIS_0]SCALE 136,137c403,407 < # estop loopback < net estop-loop iocontrol.0.user-enable-out => iocontrol.0.emc-enable-in --- > # stepper driver timing parameters > setp hm2_5i25.0.stepgen.00.steplen [AXIS_0]STEPLEN > setp hm2_5i25.0.stepgen.00.stepspace [AXIS_0]STEPSPACE > setp hm2_5i25.0.stepgen.00.dirhold [AXIS_0]DIRHOLD > setp hm2_5i25.0.stepgen.00.dirsetup [AXIS_0]DIRSETUP 139c409,410 < # Tool Changer --- > setp hm2_5i25.0.stepgen.00.maxvel [AXIS_0]STEPGEN_MAX_VEL > setp hm2_5i25.0.stepgen.00.maxaccel [AXIS_0]STEPGEN_MAXACCEL 141,144c412 < # type of tool changer is set by the UI via tormachltc.0.tool-changer-type < # 0 - manual < # 1 - gang < # 3 - 8 position ATC --- > net xpos-cmd axis.0.motor-pos-cmd => hm2_5i25.0.stepgen.00.position-cmd 146,148c414,447 < # tool-prepare < # loopback - not needed < net tool-prepare-loopback iocontrol.0.tool-prepare => iocontrol.0.tool-prepared --- > net xpos-fb hm2_5i25.0.stepgen.00.position-fb => axis.0.motor-pos-fb > > # P3 pin 3 gpio 004 > setp hm2_5i25.0.gpio.004.invert_output 1 > > net xenable axis.0.amp-enable-out => hm2_5i25.0.stepgen.00.enable > > ######################################################################## > # Z axis > # step/dir > setp hm2_5i25.0.stepgen.01.step_type 0 > # position control > setp hm2_5i25.0.stepgen.01.control-type 0 > > # scaling for position feedback, position command, and velocity command, in steps per length unit. > # converts from counts to position units. position = counts / position_scale > setp hm2_5i25.0.stepgen.01.position-scale [AXIS_2]SCALE > > # stepper driver timing parameters > setp hm2_5i25.0.stepgen.01.steplen [AXIS_2]STEPLEN > setp hm2_5i25.0.stepgen.01.stepspace [AXIS_2]STEPSPACE > setp hm2_5i25.0.stepgen.01.dirhold [AXIS_2]DIRHOLD > setp hm2_5i25.0.stepgen.01.dirsetup [AXIS_2]DIRSETUP > > setp hm2_5i25.0.stepgen.01.maxvel [AXIS_2]STEPGEN_MAX_VEL > setp hm2_5i25.0.stepgen.01.maxaccel [AXIS_2]STEPGEN_MAXACCEL > > net zpos-cmd axis.2.motor-pos-cmd => hm2_5i25.0.stepgen.01.position-cmd > net zpos-fb hm2_5i25.0.stepgen.01.position-fb => axis.2.motor-pos-fb > > # P3 pin 5 gpio 008 > setp hm2_5i25.0.gpio.008.invert_output 1 > > net zenable axis.2.amp-enable-out => hm2_5i25.0.stepgen.01.enable 150,151d448 < # tool number < net tool-prep-number-to-comp iocontrol.0.tool-prep-number => tormachltc.0.tool-prep-number 153,155d449 < # feedback that tool change is complete < # iocontrol.0.tool-changed needs to go high when tool change is complete < net tool-change-done-from-changer tormachltc.0.tool-changed-out => iocontrol.0.tool-changed 157,160d450 < # 0 -> 1 iocontrol.0.tool-change begins ATC tool change process < # connect real ATC signal to the HAL comp < # lathe control board ignores it if the tool number is out of range of the ATC < net tool-change-start iocontrol.0.tool-change 162,163d451 < # and connect iocontrol.0.tool-change to the tool changer comp < net tool-change-start tormachltc.0.tool-change-in 165,167d452 < # this connects the lathe control board tool-changed signal to the HAL comp < # for sim ATC 'tool-changed' is looped back to 'tool-change' < net tool-change-start tormachltc.0.atc-tool-changed