Control Spindle with Toggle Switch and Pot
24 Aug 2020 11:05 #179217
by ebartel
Control Spindle with Toggle Switch and Pot was created by ebartel
I have a two axis bedmill that I wanted to be able to control the spindle forward/stop/reverse with a three way toggle switch and the speed of the spindle speed with a pot. The manual buttons would essentially mimic the GUI buttons in Axis. The issue I faced was that when halui.spindle.forward/reverse goes high, it does not start the spindle until halui.spindle.increase is pulsed which is equivalent to clicking the + button.
I'm not sure if this is the best way to achieve this but below is what I used. Would appreciate any thoughts on if there was an easier way to get this done and any issues it could cause.
Overall I created a custom component that pulses the increase when spindle reverse and forward is enabled. The component works by first setting pulse (number of times to pulse) and thread delay (number of iterations to wait till next pulse). Once in goes high it pulses out according to the settings. If the thread delay is set to small it seems pulses will be missed (not really sure the specifics of why this is).
Pulser Component
Related lines in HAL file
Full HAL UI
Post GUI HAL for Pot spindle speed
I'm not sure if this is the best way to achieve this but below is what I used. Would appreciate any thoughts on if there was an easier way to get this done and any issues it could cause.
Overall I created a custom component that pulses the increase when spindle reverse and forward is enabled. The component works by first setting pulse (number of times to pulse) and thread delay (number of iterations to wait till next pulse). Once in goes high it pulses out according to the settings. If the thread delay is set to small it seems pulses will be missed (not really sure the specifics of why this is).
Pulser Component
component pulseout;
pin out bit out;
pin in bit in;
param rw unsigned pulse = 3;
param rw unsigned thread_delay = 100;
param r unsigned thread_cnt = 0;
variable bool fire = FALSE;
variable int pulse_count = 0;
variable bool pulse_flip = FALSE;
function _;
license "GPL";
;;
FUNCTION(_) {
if(in){
if(fire){
fire = FALSE;
pulse_count = pulse;
pulse_flip = TRUE;
}
if(pulse_count > 0) {
if (thread_cnt == 0) {
if(pulse_flip){
out = TRUE;
pulse_flip = FALSE;
pulse_count = pulse_count - 1;
thread_cnt = thread_delay;
} else {
out = FALSE;
pulse_flip = TRUE;
thread_cnt = thread_delay;
}
} else {
thread_cnt = thread_cnt - 1;
}
}
} else {
fire = TRUE;
}
}
Related lines in HAL file
# Load related components and tie to servo-thread
loadrt or2 count=1
loadrt not count=1
loadrt pulseout count=1
addf or2.0 servo-thread
addf not.0 servo-thread
addf pulseout.0 servo-thread
# tie pulseout to spindle speed
setp pulseout.0.pulse 10
setp pulseout.0.thread-delay 500
net pulse-spindle-speed pulseout.0.out => halui.spindle.increase
# tie toggle switch to halui forward/reverse and pulser
net spindle-manual-cw halui.spindle.forward or2.0.in0 pulseout.0.in hm2_5i25.0.7i76.0.0.input-08
net spindle-manual-ccw halui.spindle.reverse or2.0.in1 hm2_5i25.0.7i76.0.0.input-07
net spindle-switch-on or2.0.out not.0.in
net spindle-manual-stop halui.spindle.stop not.0.out
Full HAL UI
# Generated by PNCconf at Sat Sep 2 06:06:21 2017
# If you make changes to this file, they will be
# overwritten when you run PNCconf again
loadrt trivkins
loadrt [EMCMOT]EMCMOT servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[TRAJ]AXES
#loadrt probe_parport
loadrt hostmot2
loadrt hm2_pci config=" num_encoders=1 num_pwmgens=0 num_3pwmgens=0 num_stepgens=3 sserial_port_0=10xxx "
#setp hm2_5i25.0.watchdog.timeout_ns 10000000
loadrt mux16 names=jogincr
loadrt conv_float_s32 count=1
loadrt scale count=2
loadrt abs count=1
loadrt or2 count=1
loadrt not count=1
loadrt pulseout count=1
# load runtime for e-stops
loadrt estop_latch count=2
addf hm2_5i25.0.read servo-thread
addf motion-command-handler servo-thread
addf motion-controller servo-thread
addf jogincr servo-thread
addf hm2_5i25.0.write servo-thread
#addf hm2_5i25.0.pet_watchdog servo-thread
addf scale.0 servo-thread
addf scale.1 servo-thread
addf conv-float-s32.0 servo-thread
addf abs.0 servo-thread
addf or2.0 servo-thread
addf not.0 servo-thread
addf pulseout.0 servo-thread
# add functions for e-stop
addf estop-latch.0 servo-thread
addf estop-latch.1 servo-thread
# external output signals
# --- SPINDLE-CW ---
#setp hm2_5i25.0.gpio.017.is_output true
net spindle-cw hm2_5i25.0.7i76.0.0.spinena
# --- SPINDLE-CCW ---
#setp hm2_5i25.0.gpio.018.is_output true
net spindle-ccw hm2_5i25.0.7i76.0.0.spindir
# --- SPINDLE Speed ---
#setp scale.0.gain 0.035
setp scale.0.gain 0.1
net spindle-speed motion.spindle-speed-out => abs.0.in
net spindle-speed-abs abs.0.out => scale.0.in
net spindle-speed-DAC scale.0.out => hm2_5i25.0.7i76.0.0.spinout
#net spindle-speed-DAC abs.0.out => hm2_5i25.0.7i76.0.0.spinout
#net spindle-speed-scale motion.spindle-speed-out => scale.0.in
#net spindle-speed-DAC scale.0.out => hm2_5i25.0.7i76.0.0.spinout
setp pulseout.0.pulse 10
setp pulseout.0.thread-delay 500
net pulse-spindle-speed pulseout.0.out => halui.spindle.increase
# external input signals
# --- MIN-HOME-X ---
net min-home-x <= hm2_5i25.0.7i76.0.0.input-04-not
# --- MIN-HOME-Y ---
net min-home-y <= hm2_5i25.0.7i76.0.0.input-05-not
# --- ABORT ---
#net abort <= hm2_5i25.0.gpio.018.in
# --- SINGLE-STEP ---
net single-step <= hm2_5i25.0.gpio.019.in
# --- CYCLE-START ---
net cycle-start <= hm2_5i25.0.gpio.020.in
#*********************
# E-STOP
#*********************
#GUI Input
net latch-reset iocontrol.0.user-request-enable
net latch0-ok-in iocontrol.0.user-enable-out
net latch0-ok-in => estop-latch.0.ok-in
net latch0-out <= estop-latch.0.ok-out
net latch0-out => estop-latch.1.ok-in
#net latch1-out <= estop-latch.1.ok-out
net latch-reset => estop-latch.0.reset
net latch-reset => estop-latch.1.reset
net latch-out iocontrol.0.emc-enable-in <= estop-latch.1.ok-out
net estop-out estop-latch.1.fault-out
net red-button-estop <= hm2_5i25.0.7i76.0.0.input-06-not
net red-button-estop => estop-latch.1.fault-in
#*******************
# AXIS X
#*******************
# Step Gen signals/setup
setp hm2_5i25.0.stepgen.00.dirsetup [AXIS_0]DIRSETUP
setp hm2_5i25.0.stepgen.00.dirhold [AXIS_0]DIRHOLD
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.position-scale [AXIS_0]STEP_SCALE
setp hm2_5i25.0.stepgen.00.step_type 0
setp hm2_5i25.0.stepgen.00.control-type 0
setp hm2_5i25.0.stepgen.00.maxaccel [AXIS_0]STEPGEN_MAXACCEL
setp hm2_5i25.0.stepgen.00.maxvel [AXIS_0]STEPGEN_MAXVEL
net x-pos-fb axis.0.motor-pos-fb <= hm2_5i25.0.stepgen.00.position-fb
net x-pos-cmd axis.0.motor-pos-cmd => hm2_5i25.0.stepgen.00.position-cmd
net x-enable axis.0.amp-enable-out => hm2_5i25.0.stepgen.00.enable
# ---setup home / limit switch signals---
net min-home-x => axis.0.home-sw-in
net min-home-x => axis.0.neg-lim-sw-in
net x-pos-limit => axis.0.pos-lim-sw-in
#*******************
# AXIS Y
#*******************
# Step Gen signals/setup
setp hm2_5i25.0.stepgen.01.dirsetup [AXIS_1]DIRSETUP
setp hm2_5i25.0.stepgen.01.dirhold [AXIS_1]DIRHOLD
setp hm2_5i25.0.stepgen.01.steplen [AXIS_1]STEPLEN
setp hm2_5i25.0.stepgen.01.stepspace [AXIS_1]STEPSPACE
setp hm2_5i25.0.stepgen.01.position-scale [AXIS_1]STEP_SCALE
setp hm2_5i25.0.stepgen.01.step_type 0
setp hm2_5i25.0.stepgen.01.control-type 0
setp hm2_5i25.0.stepgen.01.maxaccel [AXIS_1]STEPGEN_MAXACCEL
setp hm2_5i25.0.stepgen.01.maxvel [AXIS_1]STEPGEN_MAXVEL
net y-pos-fb axis.1.motor-pos-fb <= hm2_5i25.0.stepgen.01.position-fb
net y-pos-cmd axis.1.motor-pos-cmd => hm2_5i25.0.stepgen.01.position-cmd
net y-enable axis.1.amp-enable-out => hm2_5i25.0.stepgen.01.enable
# ---setup home / limit switch signals---
net min-home-y => axis.1.home-sw-in
net min-home-y => axis.1.neg-lim-sw-in
net y-pos-limit => axis.1.pos-lim-sw-in
#*******************
# AXIS Z
#*******************
# Step Gen signals/setup
setp hm2_5i25.0.stepgen.02.dirsetup [AXIS_2]DIRSETUP
setp hm2_5i25.0.stepgen.02.dirhold [AXIS_2]DIRHOLD
setp hm2_5i25.0.stepgen.02.steplen [AXIS_2]STEPLEN
setp hm2_5i25.0.stepgen.02.stepspace [AXIS_2]STEPSPACE
setp hm2_5i25.0.stepgen.02.position-scale [AXIS_2]STEP_SCALE
setp hm2_5i25.0.stepgen.02.step_type 0
setp hm2_5i25.0.stepgen.02.control-type 0
setp hm2_5i25.0.stepgen.02.maxaccel [AXIS_2]STEPGEN_MAXACCEL
setp hm2_5i25.0.stepgen.02.maxvel [AXIS_2]STEPGEN_MAXVEL
net z-pos-fb axis.2.motor-pos-fb <= hm2_5i25.0.stepgen.02.position-fb
net z-pos-cmd axis.2.motor-pos-cmd => hm2_5i25.0.stepgen.02.position-cmd
net z-enable axis.2.amp-enable-out => hm2_5i25.0.stepgen.02.enable
# ---setup home / limit switch signals---
net z-home-sw => axis.2.home-sw-in
net z-neg-limit => axis.2.neg-lim-sw-in
net z-pos-limit => axis.2.pos-lim-sw-in
#*******************
# SPINDLE S
#*******************
# ---setup spindle control signals---
#net spindle-vel-cmd-rps <= motion.spindle-speed-out-rps
#net spindle-vel-cmd-rps-abs <= motion.spindle-speed-out-rps-abs
#net spindle-vel-cmd <= motion.spindle-speed-out
#net spindle-vel-cmd-rpm-abs <= motion.spindle-speed-out-abs
net spindle-on <= motion.spindle-on
net spindle-cw <= motion.spindle-forward
net spindle-ccw <= motion.spindle-reverse
net spindle-brake <= motion.spindle-brake
net spindle-revs => motion.spindle-revs
net spindle-at-speed => motion.spindle-at-speed
net spindle-vel-fb => motion.spindle-speed-in
net spindle-index-enable <=> motion.spindle-index-enable
# ---Setup spindle at speed signals---
sets spindle-at-speed true
# ---- SEE Postgui for spindle speed
#******************************
# connect miscellaneous signals
#******************************
# ---HALUI signals---
net joint-select-a halui.joint.0.select
net x-is-homed halui.joint.0.is-homed
net jog-x-pos halui.jog.0.plus
net jog-x-neg halui.jog.0.minus
net jog-x-analog halui.jog.0.analog
net joint-select-b halui.joint.1.select
net y-is-homed halui.joint.1.is-homed
net jog-y-pos halui.jog.1.plus
net jog-y-neg halui.jog.1.minus
net jog-y-analog halui.jog.1.analog
net joint-select-c halui.joint.2.select
net z-is-homed halui.joint.2.is-homed
net jog-z-pos halui.jog.2.plus
net jog-z-neg halui.jog.2.minus
net jog-z-analog halui.jog.2.analog
net jog-selected-pos halui.jog.selected.plus
net jog-selected-neg halui.jog.selected.minus
net spindle-manual-cw halui.spindle.forward or2.0.in0 pulseout.0.in hm2_5i25.0.7i76.0.0.input-08
net spindle-manual-ccw halui.spindle.reverse or2.0.in1 hm2_5i25.0.7i76.0.0.input-07
net spindle-switch-on or2.0.out not.0.in
net spindle-manual-stop halui.spindle.stop not.0.out
net machine-is-on halui.machine.is-on
net jog-speed halui.jog-speed
net MDI-mode halui.mode.is-mdi
# ---coolant signals---
net coolant-mist <= iocontrol.0.coolant-mist
net coolant-flood <= iocontrol.0.coolant-flood
# ---probe signal---
net probe-in hm2_5i25.0.7i76.0.0.input-09-not => motion.probe-input
# ---jogwheel signals to mesa encoder - shared MPG---
net joint-selected-count <= hm2_5i25.0.encoder.00.count
# ---mpg signals---
# for axis x MPG
setp axis.0.jog-vel-mode 0
net selected-jog-incr => axis.0.jog-scale
net joint-select-a => axis.0.jog-enable
net joint-selected-count => axis.0.jog-counts
# for axis y MPG
setp axis.1.jog-vel-mode 0
net selected-jog-incr => axis.1.jog-scale
net joint-select-b => axis.1.jog-enable
net joint-selected-count => axis.1.jog-counts
# for axis z MPG
setp axis.2.jog-vel-mode 0
net selected-jog-incr => axis.2.jog-scale
net joint-select-c => axis.2.jog-enable
net joint-selected-count => axis.2.jog-counts
sets selected-jog-incr 0.000000
# ---motion control signals---
net in-position <= motion.in-position
net machine-is-enabled <= motion.motion-enabled
# ---digital in / out signals---
# ---estop signals---
#net estop-out <= iocontrol.0.user-enable-out
#net estop-out => iocontrol.0.emc-enable-in
# ---manual tool change signals---
#loadusr -W hal_manualtoolchange
#net tool-change-request iocontrol.0.tool-change => hal_manualtoolchange.change
#net tool-change-confirmed iocontrol.0.tool-changed <= hal_manualtoolchange.changed
#net tool-number iocontrol.0.tool-prep-number => hal_manualtoolchange.number
#net tool-prepare-loopback iocontrol.0.tool-prepare => iocontrol.0.tool-prepared
Post GUI HAL for Pot spindle speed
# Include your custom_postgui HAL commands here
# This file will not be overwritten when you run PNCconf again
# ---Setup POT for spindle control
setp halui.spindle-override.direct-value true
setp halui.spindle-override.count-enable true
setp halui.spindle-override.scale 0.1
setp scale.1.gain 3.61239
setp scale.1.offset 0
net pot-input hm2_5i25.0.7i76.0.0.analogin0 => scale.1.in
net spindle-convert scale.1.out conv-float-s32.0.in
net spindle-override conv-float-s32.0.out halui.spindle-override.counts
net tool-prep-loop iocontrol.0.tool-prepare <= iocontrol.0.tool-prepared
Please Log in or Create an account to join the conversation.
- tommylight
- Away
- Moderator
Less
More
- Posts: 19209
- Thank you received: 6438
26 Aug 2020 11:53 #179520
by tommylight
Replied by tommylight on topic Control Spindle with Toggle Switch and Pot
What is you spindle min set to in the ini file?
It should not be 0, it should be the minimum the spindle can safely handle, example: most 24000RPM spindles have the min of 8000RPM.
It should not be 0, it should be the minimum the spindle can safely handle, example: most 24000RPM spindles have the min of 8000RPM.
Please Log in or Create an account to join the conversation.
Time to create page: 0.062 seconds