Spindle keep accelerating

More
24 Mar 2025 13:05 #324758 by vibram
Spindle keep accelerating was created by vibram
Hello,

I built my HAL file with bits taken from the forum and for sure sometimes I don't understand everything.
THis results in the current situation where when I run my Gcode, for example M3 S500, the spindle is going faster and faster and never stops
Signal spindle-at-speed is true before running gcode, then it goes false and never go back to true.
My encoder is working properly with the correct number of pulse.
Maybe the near part is wrong but I have no clue if it's the case, and if yes, why ?

Thank you for your help


Here is the spinde part of my HAL file
#*******************
#  SPINDLE
#*******************

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
 
net spindle-index-enable  <=> pid.s.index-enable
net spindle-enable        =>  pid.s.enable
net spindle-vel-cmd-rpm-abs     => pid.s.command
net spindle-vel-fb-rpm-abs-filtered      => pid.s.feedback
net spindle-output        <=  pid.s.output
    
net spindle-revs             <=   hm2_7i96s.0.encoder.00.position
net spindle-vel-fb-rps       <=   hm2_7i96s.0.encoder.00.velocity
net spindle-vel-fb-rpm       <=   hm2_7i96s.0.encoder.00.velocity-rpm
net spindle-index-enable     <=>  hm2_7i96s.0.encoder.00.index-enable
    
# ---setup spindle control signals---
# setp hm2_7i96s.0.pwmgen.00.scale 2500
setp   hm2_7i96s.0.pwmgen.00.scale [SPINDLE_0]MAX_OUTPUT
# setp hm2_7i96s.0.pwmgen.00.output_type 1
#net spindle-vel-cmd-rpm     => 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
net spindle-enable             =>  hm2_7i96s.0.pwmgen.00.enable
net spindle-cw                 <=  spindle.0.forward
net spindle-cw                    => hm2_7i96s.0.ssr.00.out-01
net spindle-ccw                <=  spindle.0.reverse
net spindle-ccw                    => hm2_7i96s.0.ssr.00.out-02
net spindle-brake              <=  spindle.0.brake
net spindle-revs               =>  spindle.0.revs
net spindle-at-speed           =>  spindle.0.at-speed
net spindle-vel-fb-rps         =>  spindle.0.speed-in
net spindle-index-enable      <=>  spindle.0.index-enable

# ---Setup spindle at speed signals---

sets spindle-at-speed true

net spindle-vel-cmd-rps    =>  near.0.in1
net spindle-vel-fb-rps         =>  near.0.in2
net spindle-at-speed       <=  near.0.out
setp near.0.scale 1.000000
setp near.0.difference 1.666667
 
setp lowpass.spindle.gain 1.000000
net spindle-vel-fb-rpm => abs.spindle.in
net spindle-vel-fb-rpm-abs abs.spindle.out => lowpass.spindle.in
net spindle-vel-fb-rpm-abs-filtered lowpass.spindle.out
net spindle-output => hm2_7i96s.0.pwmgen.00.value

# ---Setup spindle encoder---
setp hm2_7i96s.0.encoder.00.scale 4000 

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

More
24 Mar 2025 15:02 - 24 Mar 2025 15:16 #324780 by PCW
Replied by PCW on topic Spindle keep accelerating
What are the spindle P terms (in the ini file)

In general for spindle setup, I would get open loop operation
running correctly first before trying to close the loop.

Basically if you have a spindle PID loop, this means setting
FF0 to 1  and all other PID gains to 0
 
Last edit: 24 Mar 2025 15:16 by PCW.

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

More
24 Mar 2025 15:16 #324783 by vibram
Replied by vibram on topic Spindle keep accelerating
Hello PCW, thank you for your reply
Here is my ini file regarding spindle:

[SPINDLE_0]
P = 1
I = 0.01
D = 0
FF0 = 1
FF1 = 0
FF2 = 0
BIAS = 0
DEADBAND = 0
MAX_OUTPUT = 2500

When i just run the MDI command M3 S500, everything is fine
But when I run a gcdoe file with the same command, I get this issue

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

More
24 Mar 2025 15:34 #324787 by PCW
Replied by PCW on topic Spindle keep accelerating
What is the sign of the PWM value when it runs away?

I think there is a runaway possibility with that hal setup when you reduce
the spindle speed enough that you get a negative PID output (which is treated
as a positive by the PWM hardware so instead of the spindle slowing down, it speeds up)

This _may_ be fixable by setting the PWM mode to 2 (UP/DOWN) so you get 0 output
when given a negative command. Another way would be to limit the PID output to
positive values.

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

More
24 Mar 2025 15:51 #324790 by vibram
Replied by vibram on topic Spindle keep accelerating
How is it possible to monitor pwm sign in order to answer your question?

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

More
24 Mar 2025 19:34 - 24 Mar 2025 19:50 #324812 by vibram
Replied by vibram on topic Spindle keep accelerating
when output type set to 2, the spindle is not moving at all.
 
when out put is 1, another strange thing, with command M3 S100, I directly got this: 
I ask 100RPM and get 3.3 rps hence 200rpm
I checked the spindle.0.revs and it's correct, when I do 1 full turn, it's correctly recorded. This is strange
 
Attachments:
Last edit: 24 Mar 2025 19:50 by vibram.

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

More
25 Mar 2025 02:18 #324850 by PCW
Replied by PCW on topic Spindle keep accelerating

How is it possible to monitor pwm sign in order to answer your question?
 

Watch the pwm value: hm2_7i96s.0.pwmgen.00.value

Did you try open loop operation to see if that's OK?
(open loop means P,I,D = 0, FF0=1)
 You should definitely get that working first.

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

More
25 Mar 2025 11:51 - 25 Mar 2025 12:57 #324867 by vibram
Replied by vibram on topic Spindle keep accelerating
Yes it's working good with these parameters.
I wanted a PID control for better results in threading.

I think you can close the topic. 
I used the calibration tool and everything seems smooth now... 
P=1 was a huge mistake, it's 0.02 now 
Thank you for your help PCW
Last edit: 25 Mar 2025 12:57 by vibram.

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

Time to create page: 0.101 seconds
Powered by Kunena Forum