- Posts: 237
- Thank you received: 10
Understaning PWM
5 years 4 months ago #213217
by rider-83
Understaning PWM was created by rider-83
I have changed the standard spindle motor on my Boxford lathe as the original no longer functioned correctly.
In place is a 240v servo and drive rated at a maximum of 3000 rpm
The drive uses the 0-10v analogue input for speed control.
I am using LinuxCNC to deliver a PWM signal into a small DAC pcb which is then delivered to the drive as the 0-10v Analogue signal.
Rotation is controlled via a relay PCB to swap the signal from + to -
I can control on/off, direction and rpm
The system works fine, but I need to understand how to control the spindle speed more closely to the actual speed requested by LinuxCNC.
I have in my HAL a scale set to 3000, but I don't understand what frequency value I require or indeed what other parameters I must set to achieve what is required. Currently as I request RPM values via LinuxCNC if I look at the displayed RPM at the actual servo drive there is a mismatch which can either be higher or lower than requested and the differance can vary wildly. It appear the differance is non linear.
I like the sound of Andy's linear component, but I need help in understanding the basics first.
Once I have this set pretty close to what is required, I can then introduce my closed loop encoder to assist a more precise control.
In place is a 240v servo and drive rated at a maximum of 3000 rpm
The drive uses the 0-10v analogue input for speed control.
I am using LinuxCNC to deliver a PWM signal into a small DAC pcb which is then delivered to the drive as the 0-10v Analogue signal.
Rotation is controlled via a relay PCB to swap the signal from + to -
I can control on/off, direction and rpm
The system works fine, but I need to understand how to control the spindle speed more closely to the actual speed requested by LinuxCNC.
I have in my HAL a scale set to 3000, but I don't understand what frequency value I require or indeed what other parameters I must set to achieve what is required. Currently as I request RPM values via LinuxCNC if I look at the displayed RPM at the actual servo drive there is a mismatch which can either be higher or lower than requested and the differance can vary wildly. It appear the differance is non linear.
I like the sound of Andy's linear component, but I need help in understanding the basics first.
Once I have this set pretty close to what is required, I can then introduce my closed loop encoder to assist a more precise control.
Please Log in or Create an account to join the conversation.
5 years 4 months ago #213287
by andypugh
Replied by andypugh on topic Understaning PWM
If you are planning to go with closed-loop spindle speed control then there is no need to bother with lincurve.
If you set up the PID first, then adjust FF0 to give the correct speed somewhere in the mid-range then you can use the I term to make the speed corrections at other speeds. Then possibly add a bit of P to get the error out faster.
If you set up the PID first, then adjust FF0 to give the correct speed somewhere in the mid-range then you can use the I term to make the speed corrections at other speeds. Then possibly add a bit of P to get the error out faster.
Please Log in or Create an account to join the conversation.
5 years 3 months ago - 5 years 3 months ago #214131
by hairyMug
Replied by hairyMug on topic Understaning PWM
Hi Andy,
I am currently fighting with my spindle setup created by the pncconf wizard and was following your instructions above to adjust the speed.
It will only run at one speed and that only the maxaccel and/or maxvel have any effect and it does not matter what my "s" command value is...
I did look over the docs but it only has an example for a parallel port and no example for my 7i96 card... Also, all the examples assume an encode for feedback..
Your help is greatly appreciated!
[SPINDLE_0]
MAX_VELOCITY = 8.33333333333
MAX_ACCELERATION = 500.0
# The values below should be 25% larger than MAX_VELOCITY and MAX_ACCELERATION
# If using BACKLASH compensation STEPGEN_MAXACCEL should be 100% larger.
STEPGEN_MAXVEL = 10.42
STEPGEN_MAXACCEL = 625.00
P = 0.0
I = 0.0
D = 0.0
FF0 = 1.0
FF1 = 0.0
FF2 = 0.0
BIAS = 0.0
DEADBAND = 0.0
MAX_OUTPUT = 24000.0
# these are in nanoseconds
DIRSETUP = 2000
DIRHOLD = 2000
STEPLEN = 2000
STEPSPACE = 2000
SCALE = 3125.0
#*******************
# 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
# This setting is to limit bogus stepgen
# velocity corrections caused by position
# feedback sample time jitter.
setp pid.s.maxerror 0.012700
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
# Step Gen signals/setup
setp hm2_7i96.0.stepgen.03.dirsetup [SPINDLE_0]DIRSETUP
setp hm2_7i96.0.stepgen.03.dirhold [SPINDLE_0]DIRHOLD
setp hm2_7i96.0.stepgen.03.steplen [SPINDLE_0]STEPLEN
setp hm2_7i96.0.stepgen.03.stepspace [SPINDLE_0]STEPSPACE
setp hm2_7i96.0.stepgen.03.position-scale [SPINDLE_0]SCALE
setp hm2_7i96.0.stepgen.03.step_type 0
setp hm2_7i96.0.stepgen.03.control-type 1
setp hm2_7i96.0.stepgen.03.maxaccel [SPINDLE_0]MAX_ACCELERATION
setp hm2_7i96.0.stepgen.03.maxvel [SPINDLE_0]MAX_VELOCITY
net spindle-enable => hm2_7i96.0.stepgen.03.enable
net spindle-vel-cmd-rps => hm2_7i96.0.stepgen.03.velocity-cmd
net spindle-vel-fb-rps <= hm2_7i96.0.stepgen.03.velocity-fb
# ---setup spindle control signals---
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-cw <= spindle.0.forward
net spindle-ccw <= spindle.0.reverse
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
I am currently fighting with my spindle setup created by the pncconf wizard and was following your instructions above to adjust the speed.
It will only run at one speed and that only the maxaccel and/or maxvel have any effect and it does not matter what my "s" command value is...
I did look over the docs but it only has an example for a parallel port and no example for my 7i96 card... Also, all the examples assume an encode for feedback..
Your help is greatly appreciated!
[SPINDLE_0]
MAX_VELOCITY = 8.33333333333
MAX_ACCELERATION = 500.0
# The values below should be 25% larger than MAX_VELOCITY and MAX_ACCELERATION
# If using BACKLASH compensation STEPGEN_MAXACCEL should be 100% larger.
STEPGEN_MAXVEL = 10.42
STEPGEN_MAXACCEL = 625.00
P = 0.0
I = 0.0
D = 0.0
FF0 = 1.0
FF1 = 0.0
FF2 = 0.0
BIAS = 0.0
DEADBAND = 0.0
MAX_OUTPUT = 24000.0
# these are in nanoseconds
DIRSETUP = 2000
DIRHOLD = 2000
STEPLEN = 2000
STEPSPACE = 2000
SCALE = 3125.0
#*******************
# 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
# This setting is to limit bogus stepgen
# velocity corrections caused by position
# feedback sample time jitter.
setp pid.s.maxerror 0.012700
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
# Step Gen signals/setup
setp hm2_7i96.0.stepgen.03.dirsetup [SPINDLE_0]DIRSETUP
setp hm2_7i96.0.stepgen.03.dirhold [SPINDLE_0]DIRHOLD
setp hm2_7i96.0.stepgen.03.steplen [SPINDLE_0]STEPLEN
setp hm2_7i96.0.stepgen.03.stepspace [SPINDLE_0]STEPSPACE
setp hm2_7i96.0.stepgen.03.position-scale [SPINDLE_0]SCALE
setp hm2_7i96.0.stepgen.03.step_type 0
setp hm2_7i96.0.stepgen.03.control-type 1
setp hm2_7i96.0.stepgen.03.maxaccel [SPINDLE_0]MAX_ACCELERATION
setp hm2_7i96.0.stepgen.03.maxvel [SPINDLE_0]MAX_VELOCITY
net spindle-enable => hm2_7i96.0.stepgen.03.enable
net spindle-vel-cmd-rps => hm2_7i96.0.stepgen.03.velocity-cmd
net spindle-vel-fb-rps <= hm2_7i96.0.stepgen.03.velocity-fb
# ---setup spindle control signals---
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-cw <= spindle.0.forward
net spindle-ccw <= spindle.0.reverse
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
Last edit: 5 years 3 months ago by hairyMug. Reason: added ini vals
Please Log in or Create an account to join the conversation.
5 years 3 months ago #214133
by PCW
Replied by PCW on topic Understaning PWM
If your analog circuit expects PWM value, a stepgen is not going to work very well.
If you want PWM, you need to:
1. Use firmware that has a PWM output available
2. Initialize and connect this PWM hardware
in the hal file
There is firmware for the 7I96 that replaces stepgen-04
(the last channel) with a PWM generator. (7i96d_1pwm.bit)
If you want PWM, you need to:
1. Use firmware that has a PWM output available
2. Initialize and connect this PWM hardware
in the hal file
There is firmware for the 7I96 that replaces stepgen-04
(the last channel) with a PWM generator. (7i96d_1pwm.bit)
Please Log in or Create an account to join the conversation.
5 years 3 months ago #214140
by hairyMug
Replied by hairyMug on topic Understaning PWM
Thanks PCW,
When I find the listed bit file, is it just a matter of flashing the 7i96?
And, would this overwrite my current setups for the other steppers & switches?
When I find the listed bit file, is it just a matter of flashing the 7i96?
And, would this overwrite my current setups for the other steppers & switches?
Please Log in or Create an account to join the conversation.
5 years 3 months ago #214142
by BigJohnT
Replied by BigJohnT on topic Understaning PWM
You can use my 7i96 Configuration Tool to flash as well as build your configuration files.
gnipsel.com/mesa/index.html
JT
gnipsel.com/mesa/index.html
JT
Please Log in or Create an account to join the conversation.
Time to create page: 0.140 seconds