Mesa 7i96s PID Spindle Setup

  • scda
  • scda's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
11 Mar 2025 15:36 - 11 Mar 2025 15:52 #323685 by scda
Mesa 7i96s PID Spindle Setup was created by scda
Hi all,

I am working on a weiler cnc lathe retrofit. So far it works well, the only thing left ist the PID tuning of the spindle speed. 
The spindle also works without PID but the offset to the actual speed varies quite a bit (not linear), I was hoping to correct this with a PID loop.

VFD: Huanyang with analog voltage input (0-10V).

Currently I am trying to figure out how to implenent the PID setup for this.

How can I scale the PID output to 0-10V (or 0-4600 rpm) ? Currently my PID output can be negative and so the pwmgen.value of the Mesa7i96s spindle is negative which does not work for my setup. I feed the PID ouput to the scaled pwmgen input.

I think the system has to adjust the current value sent to the pwmgen.value just below and above the current setpoint in order to adjust for velocity offset. I was thinking of using the sum function (which kind of works but also does not really correct the non-linearity) but I think there must be an easier way...

Cheers,
David
Last edit: 11 Mar 2025 15:52 by scda.

Please Log in or Create an account to join the conversation.

More
11 Mar 2025 16:18 #323686 by PCW
Replied by PCW on topic Mesa 7i96s PID Spindle Setup
Normally this is just done with normal PID,
with FF0 set to 1 and PWM scale set to RPM at 10V

PID would mainly be for Keeping constant RPM vs load.
If you have major non-linearities, these can be corrected with
the lincurve component.

Please Log in or Create an account to join the conversation.

  • scda
  • scda's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
11 Mar 2025 16:42 - 11 Mar 2025 16:54 #323689 by scda
Replied by scda on topic Mesa 7i96s PID Spindle Setup
Thanks. Yeah I think the main problem was that I have set the P value too high (above 2 is too much --> runaway). So the system seems to be working now.
  • I set a non-zero value to the DEADBAND setting (10)
  • I am using a low pass filter on the encoder feedback signal before feeding it to the PID loop
  • I use a low P value to stop the system "from running away"
#======================================================================================
#  Spindle0
#======================================================================================

setp   pid.s.Pgain     [SPINDLE_0]P
setp   pid.s.Igain     [SPINDLE_0]I
setp   pid.s.Dgain     [SPINDLE_0]D
setp   pid.s.bias      [SPINDLE_0]BIAS
setp   pid.s.FF0       [SPINDLE_0]FF0
setp   pid.s.FF1       [SPINDLE_0]FF1
setp   pid.s.FF2       [SPINDLE_0]FF2
setp   pid.s.deadband  [SPINDLE_0]DEADBAND
setp   pid.s.maxoutput [SPINDLE_0]MAX_OUTPUT
setp   pid.s.error-previous-target true

setp hm2_7i96s.0.pwmgen.00.enable 1
setp hm2_7i96s.0.pwmgen.00.scale [SPINDLE_0]MAX_RPM

setp lowpass.0.gain [SPINDLE_0]LOWPASS_GAIN

setp    hm2_7i96s.0.encoder.04.counter-mode 0
setp    hm2_7i96s.0.encoder.04.filter 1
setp    hm2_7i96s.0.encoder.04.index-invert 0
setp    hm2_7i96s.0.encoder.04.index-mask 0
setp    hm2_7i96s.0.encoder.04.index-mask-invert 0
setp    hm2_7i96s.0.encoder.04.scale  [SPINDLE_0]ENCODER_SCALE

net spindle-index-enable      =>    pid.s.index-enable
net spindle-enable            =>    pid.s.enable 
net spindle-vel-cmd-rpm         =>    pid.s.command        
net spindle-vel-fb-rpm          =>    pid.s.feedback
net spindle-output            <=    pid.s.output        => hm2_7i96s.0.pwmgen.00.value    

net spindle-vel-cmd-rps        <=    spindle.0.speed-out-rps    
net spindle-vel-cmd-rps-abs    <=    spindle.0.speed-out-rps-abs
net spindle-vel-cmd-rpm        <=    spindle.0.speed-out        
net spindle-vel-cmd-rpm-abs    <=    spindle.0.speed-out-abs    
net spindle-enable        <=    spindle.0.on             # =>    hm2_7i96s.0.pwmgen.00.enable
net spindle-cw            <=     spindle.0.forward        =>    hm2_7i96s.0.outm.00.out-04 
net spindle-ccw            <=    spindle.0.reverse         =>    hm2_7i96s.0.outm.00.out-05

net spindle-revs            =>    spindle.0.revs    
net spindle-at-speed        =>    spindle.0.at-speed
net spindle-vel-fb-rps      =>    spindle.0.speed-in            <=     hm2_7i96s.0.encoder.04.velocity
net spindle-vel-fb-rpm_raw    =>    hm2_7i96s.0.encoder.04.velocity-rpm    =>     lowpass.0.in    
net spindle-vel-fb-rpm        <=    lowpass.0.out
net spindle-index-enable    <=>    spindle.0.index-enable
Last edit: 11 Mar 2025 16:54 by scda.

Please Log in or Create an account to join the conversation.

More
11 Mar 2025 17:16 #323692 by PCW
Replied by PCW on topic Mesa 7i96s PID Spindle Setup
You should never get a runaway, but you will get oscillations with a too high PID value

To avoid a runaway around 0 speed where a negative PID output may occur might require
some hal magic, say using the PID output sign to run the VFD direction signal or forcing the
PWM value to 0 when the PID output is negative.
 

Please Log in or Create an account to join the conversation.

Time to create page: 0.070 seconds
Powered by Kunena Forum