# Tormach Lathe Hal file for Mesa 5I25 # load RT components loadrt trivkins 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 loadrt tormachltc loadrt gearchange count=1 loadrt not names=prog-not-idle loadrt machineokdb names=machine-ok-db loadusr -W usbio # 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 1024 pulses per rev, 3000 RPM is 60 kHz # setp hm2_5i25.0.raw.write_address 13312 #Testing the filter - was 38 I changed to 19 setp hm2_5i25.0.raw.write_data 19 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 ############################################################################# # 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 addf lowpass.0 servo-thread # always needed addf motion-command-handler servo-thread addf motion-controller servo-thread addf estop-latch.0 servo-thread # used by spindle speed addf gearchange.0 servo-thread addf tormachltc.0 servo-thread 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 # added lincurve to correct for RPM differences between commanded and actual # type 1 velocity control mode setp hm2_5i25.0.stepgen.02.control-type 1 # step/dir # type 2 quadrature output for 50% duty cycle - I changed to 0 from 2 setp hm2_5i25.0.stepgen.02.step_type 0 # 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 2000 setp hm2_5i25.0.stepgen.02.maxvel 2000 # stepspace in nanoseconds setp hm2_5i25.0.stepgen.02.stepspace 0 # steplen in nanoseconds setp hm2_5i25.0.stepgen.02.steplen 425000 # 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 0 # connect motion to pin #this works to limit reverse motion of spindle on stop command net spindle-reverse motion.spindle-reverse => hm2_5i25.0.gpio.009.out #original tormach below #net spindle-forward motion.spindle-forward => hm2_5i25.0.gpio.009.out ######################################### # # # Added for M19 spindle Orientation # # # ######################################### loadrt pid num_chan=2 addf pid.0.do-pid-calcs servo-thread # Velocity addf pid.1.do-pid-calcs servo-thread # Position loadrt orient names=orient addf orient servo-thread loadrt mux2 addf mux2.0 servo-thread # chooses which pid output goes to the spindle speed control #Use this to detect that the spindle is oriented loadrt near count=1 addf near.0 servo-thread net spindle-pos pid.1.feedback orient.position net spindle-vel pid.0.feedback hm2_5i25.0.encoder.00.velocity motion.spindle-speed-in lowpass.0.in net spindle-vel-cmd motion.spindle-speed-out pid.0.command net spindle-vel-pid pid.0.output mux2.0.in0 net spindle-pos pid.1.feedback orient.position near.0.in1 hm2_5i25.0.encoder.00.position net spindle-pos-cmd orient.command pid.1.command near.0.in2 net spindle-angle motion.spindle-orient-angle orient.angle net spindle-pos-pid pid.1.output mux2.0.in1 setp near.0.difference 0.0005 net spindle-in-pos near.0.out motion.spindle-is-oriented # this switches modes net orient-mode motion.spindle-orient orient.enable pid.1.enable mux2.0.sel net velocity-mode motion.spindle-on pid.0.enable hm2_5i25.0.stepgen.02.enable #connect to spindle stepgen loadrt abs addf abs.0 servo-thread net spindle-cmd mux2.0.out abs.0.in net spindle-cmd-abs abs.0.out hm2_5i25.0.stepgen.02.velocity-cmd setp pid.0.Pgain [SPINDLE]PGAIN_V setp pid.0.Igain [SPINDLE]IGAIN_V setp pid.0.Dgain [SPINDLE]DGAIN_V setp pid.0.FF0 [SPINDLE]FF0_V setp pid.0.FF1 [SPINDLE]FF1_V setp pid.1.Pgain [SPINDLE]PGAIN_P setp pid.1.Igain [SPINDLE]IGAIN_P setp pid.1.Dgain [SPINDLE]DGAIN_P setp pid.1.FF0 [SPINDLE]FF0_P setp pid.1.FF1 [SPINDLE]FF1_P ######################################################################## # 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 # for quad encoder change counter mode to 0 above and scale below to 1024x4=-4096 #should be 4096 but trying this setp hm2_5i25.0.encoder.00.scale -4114.05 setp hm2_5i25.0.encoder.00.filter 1 # see 'man hostmot2' for descriptions - I added entire index mask invert line setp hm2_5i25.0.encoder.00.index-mask 0 setp hm2_5i25.0.encoder.00.index-mask-invert 0 setp hm2_5i25.0.encoder.00.index-invert 0 #net spindle-position hm2_5i25.0.encoder.00.position => motion.spindle-revs # Following remarked out because i put it into PID section above #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 ################################################################# # 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 ######################################################## # home + limit switch - THIS IS MY CODE FOR LIMIT SW net limit-switch-in <= hm2_5i25.0.gpio.016.in_not net limit-switch-in => debounce.1.0.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 axis.2.home-sw-in #axis.0.pos-lim-sw-in axis.2.neg-lim-sw-in axis.2.pos-lim-sw-in ######################################################################## # 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 # I changed freq from 500 to 12500 setp hm2_5i25.0.pwmgen.pwm_frequency 12500 #I changed scale from 100 to 1 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 50 ######################################################################## # E stop # P3 pin 15 gpio 003 # estop noise debounce # use this line with a machine attached - _ i changed machine-ok-raw to machine-ok I changed it from .in_not to .in net machine-ok hm2_5i25.0.gpio.003.in => machine-ok-db.in 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 net estop-out <= iocontrol.0.user-enable-out ######################################################################## # 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 # 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 # tool number net tool-prep-number-to-comp iocontrol.0.tool-prep-number => tormachltc.0.tool-prep-number # 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 # 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 # 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 ####################################################################### # IO Board ####################################################################### net dig-out-5 motion.digital-out-05 => usbio.relay-0 net dig-out-6 motion.digital-out-06 => usbio.relay-1 net dig-out-7 motion.digital-out-07 => usbio.relay-2 net dig-out-8 motion.digital-out-08 => usbio.relay-3 net dig-in-5 motion.digital-in-05 => usbio.input-0 net dig-in-6 motion.digital-in-06 => usbio.input-1 net dig-in-7 motion.digital-in-07 => usbio.input-2 net dig-in-8 motion.digital-in-08 => usbio.input-3 ######################################################################## # X axis # step/dir setp hm2_5i25.0.stepgen.00.step_type 0 # position control setp hm2_5i25.0.stepgen.00.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.00.position-scale [AXIS_0]SCALE # 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 setp hm2_5i25.0.stepgen.00.maxvel [AXIS_0]STEPGEN_MAX_VEL setp hm2_5i25.0.stepgen.00.maxaccel [AXIS_0]STEPGEN_MAXACCEL net xpos-cmd axis.0.motor-pos-cmd => hm2_5i25.0.stepgen.00.position-cmd net xpos-fb hm2_5i25.0.stepgen.00.position-fb => axis.0.motor-pos-fb 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