My attempt : ##################################################################### # Spindel VFD closed loop : PID NEAR SCALE OFFSET for Rev/stop/fw -10v 0v +10v # from 0/24v PWM to +-10v isolator/convertissor #####################################################################
loadrt pid names=pid.spindle loadrt offset names=offset.pwmgen loadrt near names=near.at-speed loadrt scale names=scale.spindle-vel-rpm loadrt and2 names=and2.spindle-ena addf pid.spindle.do-pid-calcs servo-thread addf offset.pwmgen.update-output servo-thread addf near.at-speed servo-thread addf scale.spindle-vel-rpm slow-thread addf and2.spindle-ena servo-thread # scale RPS to RPM setp scale.spindle-vel-rpm.gain [SPINDLE]VELOCITY_RPM_GAIN # setup Spindle PID setp pid.spindle.Pgain [SPINDLE]P setp pid.spindle.Igain [SPINDLE]I setp pid.spindle.Dgain [SPINDLE]D setp pid.spindle.FF0 [SPINDLE]FF0 setp pid.spindle.FF1 [SPINDLE]FF1 setp pid.spindle.FF2 [SPINDLE]FF2 setp pid.spindle.bias [SPINDLE]BIAS setp pid.spindle.deadband [SPINDLE]DEADBAND setp pid.spindle.maxerror [SPINDLE]MAX_ERROR setp pid.spindle.maxoutput [SPINDLE]MAX_OUTPUT # setup hardwar (encoder + PWMgen) setp hpg.encoder.00.chan.00.scale [SPINDLE]ENCODER_SCALE setp hpg.encoder.00.chan.00.counter-mode 0 setp hpg.pwmgen.00.pwm_period [SPINDLE]PWM_PERIOD setp hpg.pwmgen.00.out.00.enable 1 # allow to be at half value when spindle is off due to offset # offset the pid output the value of max output to shift the pwm output above 12v for output 0v from +-10 DAC setp offset.pwmgen.offset [SPINDLE]OFFSET_OUTPUT net DAC-ctrl-in <= pid.spindle.output net DAC-ctrl-in => offset.pwmgen.in #net spindle-vel-cmd-rps => offset.pwmgen.in # for bypass PID only for some test # scale max expected input * 2 to equal a PWM duty cycle of 1.0 setp hpg.pwmgen.00.out.00.scale [SPINDLE]PWM_OUTPUT_SCALE # encoder connections net spindle-pos <= hpg.encoder.00.chan.00.position net spindle-pos => motion.spindle-revs net spindle-vel-fb-rps <= hpg.encoder.00.chan.00.velocity net spindle-vel-fb-rps => motion.spindle-speed-in net spindle-vel-fb-rps => scale.spindle-vel-rpm.in net spindle-vel-fb-rps => pid.spindle.feedback net spindle-vel-rpm <= scale.spindle-vel-rpm.out net spindle-vel-cmd <= motion.spindle-speed-out # Speed command in RPS net spindle-vel-cmd-rps <= motion.spindle-speed-out-rps net spindle-vel-cmd-rps => pid.spindle.command # offset output to feed to pwmgen output net DAC-ctrl-out <= offset.pwmgen.out #net DAC-ctrl-out => hpg.pwmgen.00.out.00.value # do in the orient mux2 # Spindle control signals + and2 for stop spindle after stop GUI net spindle-enable <= motion.spindle-on net spindle-enable => and2.spindle-ena.in0 net drv-enable => and2.spindle-ena.in1 net spindle-and2enable <= and2.spindle-ena.out net spindle-and2enable => pid.spindle.enable #net spindle-and2enable => fur.do-6 # do in the orient or2 # Spindle at speed near signal setp near.at-speed.scale [SPINDLE]AT_SPEED_SCALE net spindle-vel-cmd-rps <= motion.spindle-speed-out-rps net spindle-vel-cmd-rps => near.at-speed.in1 net spindle-vel-fb-rps => near.at-speed.in2 net spindle-at-speed <= near.at-speed.out net spindle-at-speed => motion.spindle-at-speed ##################################################################### ##################################################################### # Spindle orient mode ##################################################################### loadrt orient names=orient.spindle loadrt pid names=pid.orient-value loadrt offset names=offset.orient loadrt near names=near.orient-ok loadrt or2 names=or2.orient-ena loadrt and2 names=and2.orient-ena loadrt mux2 names=mux2.orient-value addf orient.spindle servo-thread addf pid.orient-value.do-pid-calcs servo-thread addf offset.orient.update-output servo-thread addf near.orient-ok servo-thread addf or2.orient-ena servo-thread addf and2.orient-ena servo-thread addf mux2.orient-value servo-thread # setup Orient Spindle PID setp pid.orient-value.Pgain [ORIENT]P setp pid.orient-value.Igain [ORIENT]I setp pid.orient-value.Dgain [ORIENT]D setp pid.orient-value.FF0 [ORIENT]FF0 setp pid.orient-value.FF1 [ORIENT]FF1 setp pid.orient-value.FF2 [ORIENT]FF2 setp pid.orient-value.bias [ORIENT]BIAS setp pid.orient-value.deadband [ORIENT]DEADBAND setp pid.orient-value.maxerror [ORIENT]MAX_ERROR setp pid.orient-value.maxoutput [ORIENT]MAX_OUTPUT # Set asked mode from M19 P0/1/2 net spindle-orient-mode <= motion.spindle-orient-mode net spindle-orient-mode => orient.spindle.mode # Spindle orient control signals + and2 for stop spindle after stop GUI net spindle-orient-enable <= motion.spindle-orient net spindle-orient-enable => and2.orient-ena.in0 net drv-enable => and2.orient-ena.in1 net spindle-orient-and2enable <= and2.orient-ena.out net spindle-orient-and2enable => orient.spindle.enable net spindle-orient-and2enable => mux2.orient-value.sel net spindle-orient-and2enable => pid.orient-value.enable # enable out for controler from regular spindle or orient mode net spindle-and2enable => or2.orient-ena.in0 net spindle-orient-and2enable => or2.orient-ena.in1 net spindle-orient-or2enable <= or2.orient-ena.out net spindle-orient-or2enable => fur.do-6 # Spindle at orient near signal net spindle-pos => orient.spindle.position net spindle-pos => pid.orient-value.feedback net spindle-pos => near.orient-ok.in2 net spindle-orient_cmd <= motion.spindle-orient-angle net spindle-orient_cmd => near.orient-ok.in1 net spindle-orient_cmd => orient.spindle.angle net spindle-is-oriented <= near.orient-ok.out net spindle-is-oriented => motion.spindle-is-oriented # Rotation command in degree net spindle-orient-pid-cmd <= orient.spindle.command net spindle-orient-pid-cmd => pid.orient-value.command # offset the pid output the value of max output to shift the pwm output above 12v for output 0v from +-10 DAC setp offset.orient.offset [SPINDLE]OFFSET_OUTPUT net DAC-ctrl-orient-in <= pid.orient-value.output net DAC-ctrl-orient-in => offset.orient.in # offset output to feed to pwmgen output + mux with regular spindle modul net DAC-ctrl-orient-out <= offset.orient.out net DAC-ctrl-orient-out <= mux2.orient-value.in1 net DAC-ctrl-out => mux2.orient-value.in0 net DAC-computed-ctrl-out <= mux2.orient-value.out net DAC-computed-ctrl-out => hpg.pwmgen.00.out.00.value ##################################################################### # Spindle [SPINDLE] # PID, input is RPS P = 1 I = 0.0 D = 0.0 FF0 = 0.0 FF1 = 0.0 FF2 = 0.0 BIAS = 0.0 DEADBAND = 0.0 MAX_ERROR = 0.0 #Max desired spindle speed in RPMs (3300) / 60 = Spindle Speed in RPS. MAX_OUTPUT = 55.00 OFFSET_OUTPUT = 55 # quadrature mode (mode-0) is encoder PPR * 4 ENCODER_SCALE = 400 # scale pid output to pwm control value. Max duty cycle of 1.0 / (Max speed * 2) ---range of both directions # +30 for having correct 0v at 0rpm at offset output value and allow to increase max speed to 3600 if wanted PWM_OUTPUT_SCALE = 110 # PWMgen output frequency in Hz PWM_PERIOD = 20000000 AT_SPEED_SCALE = 1.01 VELOCITY_RPM_GAIN = 60 # Orient Spindle [ORIENT] # PID, input is degree P = 1 I = 0.0 D = 0.0 FF0 = 0.0 FF1 = 0.0 FF2 = 0.0 BIAS = 0.0 DEADBAND = 0.0 MAX_ERROR = 0.0 #Max desired spindle speed in RPMs (3300) / 60 = Spindle Speed in RPS. MAX_OUTPUT = 55.00 I hope the basic work, but i'm pretty sure something is needed for scale encoder to degree. i appologize this is a lot of work to understand but any help/suggestion are another time really welcome. Thanks -- website: http://www.machinekit.io blog: http://blog.machinekit.io github: https://github.com/machinekit --- You received this message because you are subscribed to the Google Groups "Machinekit" group. To unsubscribe from this group and stop receiving emails from it, send an email to machinekit+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/machinekit/f5f68d03-1cc0-4950-8ba2-51c2ad349e77%40googlegroups.com.