Things are getting to make sense and I can have the spindle working, set the speed and get the speed back from the encoder that I installed on the spindle.
At this point I correctly have spindle feedback, but I am running a open loop, as the spindle feedback is not being used for control the analog signal, but only for observe the speed at a determined instant.
Now I would like to control the output of my pwmgen.03 output based on the current spindle speed.
My .hal that have the spindle current control is below.
The example that I saw was:
wiki.linuxcnc.org/cgi-bin/wiki.pl?Closed...pindle_Speed_Control
but it is for the parallel port, and I will probably not get it right for my current set up.
Can some one give me a help here? Maybe an example using a 5i20 + 3i33 would be enough for me to start.
Thank you
#*******************
# SPINDLE S
#*******************
# ---PWM Generator signals/setup---
setp hm2_5i20.0.pwmgen.03.output-type 1
setp hm2_5i20.0.pwmgen.03.scale [SPINDLE_9]OUTPUT_SCALE
# ---I added this to make the output 0-10V
loadrt abs count=2
addf abs.0 servo-thread # analog output
addf abs.1 servo-thread # spindle speed display
net spindle-vel-cmd => abs.0.in
net absolute-spindle-vel-cmd <= abs.0.out
net absolute-spindle-vel-cmd => hm2_5i20.0.pwmgen.03.value
net machine-is-enabled => hm2_5i20.0.pwmgen.03.enable
# ---Encoder feedback signals/setup---
setp hm2_5i20.0.encoder.03.counter-mode 0
setp hm2_5i20.0.encoder.03.filter 1
setp hm2_5i20.0.encoder.03.index-invert 0
setp hm2_5i20.0.encoder.03.index-mask 0
setp hm2_5i20.0.encoder.03.index-mask-invert 0
setp hm2_5i20.0.encoder.03.scale [SPINDLE_9]ENCODER_SCALE
net spindle-revs <= hm2_5i20.0.encoder.03.position
net spindle-vel-fb <= hm2_5i20.0.encoder.03.velocity
net spindle-index-enable <=> hm2_5i20.0.encoder.03.index-enable
# ---setup spindle control signals---
net spindle-vel-cmd-rps <= motion.spindle-speed-out-rps
net spindle-vel-cmd <= motion.spindle-speed-out
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
net spindle-vel-fb => abs.1.in
loadrt scale count=1
addf scale.0 servo-thread
setp scale.0.gain 60 # spindle fb*60 (rpm)
net absolute-spindle-vel-measured-per_second <= abs.1.out
net absolute-spindle-vel-measured-per_second => scale.0.in
net absolute-spindle-vel-measured <= scale.0.out
# ---Setup spindle at speed signals---
loadrt near
addf near.0 servo-thread
net spindle-vel-cmd-rps => near.0.in1 # commanded
net spindle-vel-fb => near.0.in2 # real
net spindle-at-speed motion.spindle-at-speed <= near.0.out
setp near.0.scale 1.2