Hello Guest it is March 28, 2024, 03:26:25 PM

Author Topic: Understanding spindle control in MACH3  (Read 24093 times)

0 Members and 1 Guest are viewing this topic.

Understanding spindle control in MACH3
« on: October 04, 2016, 02:38:48 PM »
Hi,

I have difficulties understanding what happens to my spindle speed, using the manual control.
First the problem:
When program starts, the spindle is off, the spindle speed is displayed as 5.999 and S-OV is also 5.999. This is exactly my pulley minimum. When I press the spindle on button the spindle speeds up to 10.800 (display on the Inverter), but displays 5.999 in Mach3.
If press the "Spindle +" key the spindle decelerates (!) to 6.780 which is near the minimum speed of 6.000 setup in the inverter. MACH3 shows 6.599.
Pressing "spindle +" again the spindle accelerates to 7.560, MACH3 shows 7.199.
Pressing "spindle -" returns to 6.780 / 6.599.
Pressing "spindle -" again stops the spindle, displaying 5.999 in MACH3

So there are two questions.
  • Why does MACH3 always accelerates to 10.800 rpm when pressing the "Spindle start" button? Shouldn't it start with the speed displayed on screen?
  • How can I setup the right speed translation. My wanted speed range is 6.000 .. 18.000 rpm.

Now my setup:

The spindle is controlled via PWM via Smoothstepper.
Inverter is configured such as a voltage of 0V is the minimum speed of 6.000 rpm and 10V is the maximum speed of 18.000 rpm. I veryfied this using a regulated power supply to the voltage input. Stopping the spindle is achieved by stopping the PWM pulse.

Pulley is set to 5999 min and 18000 max.
Spindle Motor Configuration is set as follows:
steps/mm = 1
speed = 100002 (I don't know why I did this, but it seems to have no effect)
acceleration = 491520
G's = 50,123243
Step pulse = 2
Dir puls = 2
mode is set to PWM with 50Hz in Smoothstepper configuration
Re: Understanding spindle control in MACH3
« Reply #1 on: October 05, 2016, 03:06:27 AM »
I'm not sure that the spindle needs to be set up in the motor tuning configuration screen for PWM.  I have not configured anything in that section and I'm running just fine on my machine.  What I don't see is mention of a PWM to Analog converter in your system.  That 0 - 10V DC input on the inverter cannot be connected directly to a PWM output.  PWM is a digital signal with varying "duty cycle" and a constant peak-to-peak voltage of 5V DC.

The way PWM works is by changing the "on" pulse width to a certain percentage of the overall cycle time.  For example, with your set PWM base frequency of 50Hz each cycle of pulses (one high pulse and one low) would be 20ms.  Then if the high pulse was set to 2ms, this would result in a 10 percent duty cycle.  Now take your range of 6000 (let's keep nice round numbers for this discussion) to 18000 RPM and this results in an overall range of 12000 RPM.  10 percent of 12000 is 1200 so the resulting RPM would be 6000 (minimum frequency) plus 1200 or 7200.  Now this is still in the digital world and needs to be converted to an analog voltage between 0 and 10V DC.

What the converter does is two-fold:

1.  Averages the voltage of the pulses to get an analog voltage between 0 and 5V DC based on the duty cycle (percentage value described above).
2.  Amplifies this voltage from the 0 - 5V DC analog signal generated in step 1 (this average cannot be higher than the peak voltage applied) and generates the 0 - 10V DC signal required to run the inverter to drive the spindle motor at the desired RPM.

What will happen if you do not run the PWM signal to the converter is that you will be applying a 5V DC digital signal to an analog input.  Depending on the design of the input stage of the inverter, it may "see" 5V DC and command a speed of 50 percent which is close to the 10800 RPM you are seeing when you first start up the spindle with the button on Mach3.  However, the inverter will probably not handle the averaging function well and will give erratic speeds as you vary the duty cycle of the PWM signal but as you've seen in your trials, it will never be above 50 percent of the available RPM.

You need to run the PWM signal through a converter unless your BOB or Smoothstepper has one built in.  This will generate the appropriate 0 - 10V DC analog signal required by the inverter input.  Also, note that the actual speeds may not be as accurate since there could be some non-linearity introduced in either the converter, the input stage of the inverter, or both.

Hope this all makes sense.  Let me know if you do have this PWM to analog converter or a 0 - 10V analog DC output on your controller/BOB.

Stephen "Highspeed" Kruse
Re: Understanding spindle control in MACH3
« Reply #2 on: October 05, 2016, 04:01:01 AM »
Ok, I forgot to mention that I have a PWM to analog converter. I also checked it's function with an oscilloscope.

It is really so that MACH3 generates PWM pulses that does not fit the onscreen value at the first spindle on press. It then adjusts correctly at the first speed change, e.g. pressing the plus key at the spindle control.

The second question is how do I tell MACH3 which PWM value correlated to which speed?
Re: Understanding spindle control in MACH3
« Reply #3 on: October 06, 2016, 03:58:34 PM »
Sorry for the delayed response, I had trouble remembering where this post was on the forum.

Let me start by answering the last question:  Mach3 takes the range of speeds determined by your pulley settings to assign the PWM value.  It interpolates between the lowest and highest speeds to determine the duty cycle for all speeds in between.  Make sure you have the correct spindle set in the settings screen.  You can set multiple pulley setups and if you don't have the correct one selected there you will end up with strange/unexpected behavior.

Now on to the original discussion.  I am glad to hear you do have the converter for the PWM to analog signal.  So, not knowing your electronics background or what test equipment you have available and are able to use the first thing I would suggest is to check the voltage coming out of the converter for various Spindle speed settings.  I usually check at minimum, maximum, mid-range, 1/4 and 3/4 settings.  These should result in 0v, 10v, 5v, 2.5v and 7.5v respectively.  If you have access to an oscilloscope, you could also check the PWM signal itself to ensure you see the appropriate variance in the pulse width duty cycle.  At mid-range speed, the high pulse should equal the low pulse.

Finally, you may need to recheck your inverter settings again.  Bear in mind that many inverters are not very linear and will have some variance even if your input signal is completely linear.  But certainly nothing like what you have described.

I'm also puzzled why the spindle starts at a different speed than what is showing on the screen.

Let me know what you find or if you have other thoughts/symptoms you come across.

Stephen "Highspeed" Kruse
Re: Understanding spindle control in MACH3
« Reply #4 on: October 09, 2016, 10:20:40 AM »
Now I had some delay further investigating the issue.
I configured the pulley now exactly like the inverter. I set minimum to 6.000 rpm and maximum to 18000 rpm. The PWM to analog converter does exactly what it should. If I set spindle speed to 6000 I get 0V, if I set it to 18000 I get 10V, a value of 7000 gives 0.8V and 10.000 gives 3.4V.

But I found a hardware issue at voltages below 0.8V, my Benezean Breakout board begins to trigger the spindle stop signal then. So if I set the speed to 6100 the motor stops. I can live with that.

But the wrong startup speed is a bad thing. It seems a MACH3 issue, all the voltages are correlating to the given speeds below. So the hardware seems ok to me.

I wrote a small GCODE for demonstration which I run in single step mode. After the hash sign I wrote the spindle speed I get


G90               # off
G91.1             # off
M03 S7000         # 10920 rpm !!!
M03 S7000         #  7080 rpm
G00 Z50.0 S7000   #  7080 rpm
G00 Z50.0 S10000  # 10200 rpm
G00 Z50.0 S7000   #  7080 rpm
M05               # off
M30               # off


You see that at the first start the spindel speed is much to high. After the second speed setting all runs as intended. What about the first start? Why goes it wrong?
I can help me with that double M03 command, but it's not nice.

The same happens if you set the speed via GUI. You type 7000 to the spindle speed field, press spindle start and it runs up to 10920 rpm. Enter 7001 and it slows down to 7080. (the delta of 80 rpm is ok for me, it's a bit of error of the PWM to voltage converter on the breakout board or the ADC in the inverter, I think.

Offline ger21

*
  • *
  •  6,295 6,295
    • View Profile
    • The CNC Woodworker
Re: Understanding spindle control in MACH3
« Reply #5 on: October 09, 2016, 10:37:16 AM »
Try:
S7000 M3

Or type S7000 in the MDI before running the g-code.
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html
Re: Understanding spindle control in MACH3
« Reply #6 on: October 11, 2016, 01:29:55 PM »
I tried now to use S7000 M3 instead of M03 S7000. It's the same: only the second S7000 command reduces the speed.
If I type S7000 in MDI and start my G-Code it is also the same behavior.
If I type S7000 M3 in the MDI spindle also starts up at high speed (10.800). If I enter S7000 the again, the speed drops to about 7000. Pressing ESC after that stops the spindle.
If I run my G-Code then, it works as desired. But only for one cycle. If I let it run until the end and then start it again, it starts up at high speed and drops down at the second S7000 command.

I think there is something weird happening after spindle stop or at spindle startup. And it is no difference if I start the spindle via MDI, via GUI button or via G-Code. Always the first start is at high speed. And why 10800 rpm? That isn't either MAX nor MIN.
What I also noticed, if I change speed in a move command like "G00 Z50.0 S10000" it does not wait for reaching the speed. It increases the speed but then moves immediately, not waiting until reaching the desired speed.
Re: Understanding spindle control in MACH3
« Reply #7 on: October 21, 2017, 05:58:56 AM »
I have had some issues with PWM spindle control. On my travels, I found mention of a bug in Mach3 when using PWM.

To quote the article I read "Mach3 has a bug in the initial commanded spindle speed under PWM control. It manifests itself as resulting in a higher initial speed than that requested. For example, on my lathe, if you request S500 the spindle will go to 643rpm. If you then perform either of the following actions, the speed will come back to the requested 500rpm:
1. Press Spindle Speed Override Reset Button, or
2. Issue another S500 command from Mach3 via DRO or MDI
Subsequent requested spindle speeds are then true until you stop the spindle and start again."

Offline ger21

*
  • *
  •  6,295 6,295
    • View Profile
    • The CNC Woodworker
Re: Understanding spindle control in MACH3
« Reply #8 on: October 21, 2017, 09:25:36 AM »
If there's a bug, I've never seen it. My spindle always runs at the commanded speed, including the first time.
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html