Phase angle and speed

288 views
Skip to first unread message

Larry Kvit

unread,
Jul 10, 2017, 11:18:07 PM7/10/17
to Mechaduino

So I just recently got the mechaduino cause I've been interested in playing around with closed loop stepper motors.

I was looking through the code and noticed that the phase angle was was always set to one step (1.8 degrees for typical stepper motors), and was wondering why. I found this white paper about torque and microstepping. It shows the relationship between the phase angle and the torque of the stepper. Interestingly, it shows that in real conditions, the phase angle should be a bit less than a full step.

I wanted to test this out, but I have no way of measuring the torque output on the shaft. So instead I measured the velocity of the shaft with different phase angles (at a constant torque using torque control).

Below are 2 graphs that I made for an input torque of 16 and 20 (these are the reference values I inputted to the controller, AFAIK they should be setting the current of the coils).
A torque value of 15 will not move stepper motor due to stiction.


I did this with an unloaded stepper motor.

I modified the firmware to be able to modify the phase angle, and to output the position of the stepper. I wrote a python script which sent serial commands to gather all the data and generate the plots.

I thought you guys would find this interesting.
Thoughts? Opinions?

Trampas Stern

unread,
Jul 11, 2017, 7:08:42 AM7/11/17
to Mechaduino
Larry,

The way Mechaduino firmware works for positional feedback mode is basically that it changes the stepper motor to a current controlled motor. It does this by using phase angle on the coil that is one step ahead of the current position. This is the way most brushless DC servos work, which a stepper is one.  The torque is then controlled by the current going into the motor.  There is some magnetic inefficiencies in the motor depending on shaft position, that is when the shaft is aligned with the coils the torque will be higher, however it this is significant to your design you should use larger motors.   However with that said if the maximum torque of the motor will be when each phase has the maximum current motor can stand going through it, this is when the maximum power is going to motor.  The "phase" of this depends on where you start your reference zero for phase measurement.  For example the last I checked the Mechaduino starts zero as both coils being powered, the smart steppers are different. 

The phase angle in the Mechaduino firmware is 1.8 degrees from current position,  so if motor is at 1 degree it will set the phase angle to 2.8.  The maximum torque points would be at 1.8 and 3.6 degrees, which are the full step points.  Please not that at the maximum torque point the motor driver should not be driving the maximum current into the motor but rather ~70.7% of maximum. The reason is that a sine wave is used and the maximum current on a coil of the motor would be when one coil is fully on and the other off.  The magnetic efficiency in the motor might still make these points the maximum torque points but should be only slight difference to any other angle. 

The Smart Steppers (www.misfittech.net) has a positional feedback mode where it changes the phase angle and the current. In this mode if the desired motor position is 1.0 degrees from current position it will set the phase angle to 1.0 degrees.  This allows the motor to behave like a DC servo with large errors and stepper motor when the error gets smaller.  I have found that this mode works for most application with out tuning the motor. 

Trampas

Larry Kvit

unread,
Jul 11, 2017, 8:55:45 AM7/11/17
to Mechaduino
I dont understand why the maximum torque points would be at 1.8 and 3.6 degrees. The two coils are engaged to create a virtual pole anywhere between them.

I was planning to try implementing a controller that changes phase angle. Looking through the nano_stepper firmware it looks like the maximum it will set the phase angle it to a full step ahead of the position. But from my graphs, it seems like it might be beneficial to set the phase angle to greater than a full step.

Kai Wolter

unread,
Jul 11, 2017, 9:53:20 AM7/11/17
to Mechaduino
Hi Larry,

if the phase angle gets greater than 1.8 degrees ahead the motor will not work properly since the electric field will simply align with another of the 50 poles of the rotor. At least in my understanding. What your graph is showing is that the controller is "lagging" behind the motor speed if you run the stepper with about 950 deg/s you turn  0.19 degree per control loop. So your motor is 1.9 degree ahead of what the controller sees.

1.8 degree + 0.19 degree = 1.99 degree -> your value

What you could do is calculate this error based on the known velocity to compensate this error.

I hope I explained well enough what I thought. Let me know what you're thinking.

Regards
Kai

Larry Kvit

unread,
Jul 11, 2017, 12:41:24 PM7/11/17
to Mechaduino
I read this article on microstepping: http://www.zaber.com/microstepping-tutorial
It has a phase diagram (with Ia, Ib). Switching completely from one coil (A) to another coil (B) is one full step. Each coil can be energized forwards or backwards (positive/negative current, or North/South).
This means that there are 4 steps to go between identical coil states:
A
B
-A
-B
A <- back where we started

You were saying that if the phase angle is more than one full step, the field would align to another of the 50 poles, but this is not true. If the phase angle is greater than 2 steps, then it will align with another pole. Infact setting a phase angle of more than 2 steps is equivalent to setting a negative phase angle. This is evident in the phase diagram in the article (3/4 rotation CW on the diagram is the same as 1/4 CCW).
Basically if you are right above coil A, having the phase angle 1 step would mean engaging coil B. Having the phase angle greater than 1 step would then mean having B coil engaged, and having a little bit of -A. This is different from taking a step backwards, which would be engaging -B coil.

I also ran an experiment with my script with -2, -1, 0, 1, 2, 3, 4 steps size for phase angle.
Having a phase angle of 3 steps is the same as having a phase angle of -1.


Kai Wolter

unread,
Jul 11, 2017, 1:33:01 PM7/11/17
to Mechaduino
Yes, you are right it's not every full step my mistake.

But never the less I would say that the effect you are seeing is still that the controller lags behind. You could try some more different speed. The higher you "torque setting" is the higher should your optimal phase angles be. I have currently no mechaduino free to test it for my self.

If your phase angle is 1.8 degrees ahead the distance between the last magnetic pole (which is attracted) and the next one (which is pushed away) is the biggest and therefore should give you the biggest available torque.

What I also wanted to mention is the ~71% that Trampas mentioned. This number comes from a simple dot-product of the tow electrical angles of the motor coils. If you use a commutation profile with a maximum of 71% this leads to an electrical angle that is the same in every position.

Trampas Stern

unread,
Jul 11, 2017, 3:29:38 PM7/11/17
to Mechaduino
The power out of a motor is function of the input power and efficiency

Power_out= Eff * Power_Input

So for example if you have 2V and 1A going into each phase/coil then your input power is:

Power_Input=2*1+2*1 = 4Watts

Now assuming your motor is limited at 1A input this is the maximum power you can put into the motor. That is each coil having 1Amp input.  

So now lets move the phase angle 45 degrees and you have one coil on, and the other coil off, thus you have:

Power_Input=2*1+0=2Watts. 

This is lower than the point where both phases are on, as you draw the wattage verse angle for this controller you will see that the result looks like a square, that is the maximum power input is 4W when both coils fully on, then 2W when one coil is on.  Most motor drivers like the A4954 will actually put in constant wattage (if software dictates this) and hence always puts in a maximum 2W (in this example), when drawn this looks like a circle.  see http://www.zaber.com/microstepping-tutorial

So now lets assume the input power is constant then the output power is still:
Power_out= Eff * Power_Input

However if the efficiency of the motor is higher at the full step points then your maximum output power will be at full step points.  Again the difference in efficiency verses step/angle is most likely insignificant.  

Trampas Stern

unread,
Jul 11, 2017, 3:29:50 PM7/11/17
to Mechaduino

Larry Kvit

unread,
Jul 12, 2017, 9:24:53 PM7/12/17
to Mechaduino
You were right about the controller lagging. I added some extra float operations (some multiplications and division), and the maximum velocity moved by 0.1 degrees.

Kai Wolter

unread,
Jul 13, 2017, 4:29:18 AM7/13/17
to Mechaduino
I'm currently working on a software version that comensates this, by measuring the shaft velocity. The problem is the signal noise that is even higher if you calculate the velocity based on the angle.
You could also use the desired speed to compensate this but this would only work for the position and velocity mode. I will post some updates if I get a stable version.

Trampas Stern

unread,
Jul 13, 2017, 7:36:07 AM7/13/17
to Mechaduino
On the motor shaft velocity verse phase angle, one thing to consider is that the velocity affects the desired phase angle.  

Specifically lets start and assume that the control loop updates every dt seconds, and to make math easier assume it takes dt seconds to execute control loop. Second lets assume that the motor is moving at an angular velocity V(t). 
Lets also assume we have a 200 steps per rotation motor.

At time t=0 the encoder is measured to be angle A(t). So what the firmware does is predict the applied phase P(t) as being:

P(t)=A(t)+1.8

However since it takes time to execute the control loop (dt by assumption) we actually are trying to predict the future phase:
P(t+dt)=A(t) +1.8

The issue here is that this incorrect if the angular velocity V(t) is not equal to zero, hence an improved equation would be:

P(t+dt)=A(t)+1.8+V(t)*dt 

That is in the dt time we have move some angular distance and we need the increase the phase angle to compensate.   The NZS firmware has the code to do this if you want to really high velocity, 20,000 RPM for example:

There are some issues here with the measurement of the V(t) in the NZS code which I have not resolved as of today so the code is not enabled by default.  These most likely are similar to the noise problem Kai is seeing. 

One thing to be careful with is assuming that maximum velocity is the same as maximum torque, I am sure everyone knows this is not the case.  With maximum torque you will have maximum acceleration (F=mA), not maximum velocity. To use an analogy, a small car with low torque engine can go just as fast as a race car, it just takes longer (slower acceleration) for the small car to get to that speed due to low torque. 

As far as the maximum power goes the easiest thing to do is increase your voltage. The motor power is based on the input power, with higher voltage the controller can over come the inductance of motor quicker and thus current rise is quicker and you can put more power into motor for a given time period, it makes a big difference going from 12-24VDC.  This is the easiest thing to do to increase power and speed of motor.  Note increasing the voltage really does not change the stall torque of motor, but rather the rate of change of the torque, and hence the power of the motor not the stall torque. However most people who want more torque for faster acceleration and speeds, increasing voltage will do this.  If you want more torque to "hold" a load, then it will be easier to get a better motor. 

Note the A4954 is specified with 40VDC max input, where the smart steppers have a 35VDC capacitor so it will not work at 36VDC, a common power supply voltage, however if you order a smart stepper and ask I will put a 50VDC capacitor on the boards for you. 

Trampas











Kai Wolter

unread,
Jul 13, 2017, 9:40:32 AM7/13/17
to Mechaduino
That's not quite right. The maximal torque will also lead to a maximal velocity. A small car can never reach the same speed as a race car, since with higher velocity's the forces against the car increased and you need more power to compensate this.
For a motor this is pretty similar. For example with higher velocity the drag torque in the bearing starts to increase and the motor needs more torque to compensate this.

Trampas Stern

unread,
Jul 13, 2017, 2:18:16 PM7/13/17
to Mechaduino
That is true, at some point you reach terminal velocity from drag and therefore you are torque limited. 

However if you have an unloaded stepper motor and measuring the maximum velocity of the shaft, the velocity will normally be limited by other factors before the torque of the motor and drag come into play.  For example the update rate of the processing loop in the firmware. 

I can get 20,000 RPM out of the motor with "phase prediction" but without phase prediction I can not achieve this velocity.  You could say in that example the maximum velocity is torque limited still, as that without phase prediction the electrical energy is being used to reduce the motor's torque, that the electrical energy is trying to turn motor backwards and thus limiting the velocity.  

Lets assume the update rate of the processing loop is 6kHz, if each update we move 1.8 degrees then our maximum shaft velocity is limited to (1.8*6000)=10,800 degrees per second = 1800RPM.

The next thing you might try is to make the motor torque limited. For example you might decide to limit the electrical current. So if you try this you can get some weird results.  Specifically the A4954 has a blank time of 2-4us what this means is that regardless of where you set the current in firmware it will turn on the FETs for the motor for 2-4us, after that it will do the current limiting.  If the current is too high after the blank time it will do the current decay (see the mixed decay mode in datasheet).  Because of this blanking time the current regulation at low currents is highly dependent on the voltage and inductance of motor.  Hence current limiting for this type of test might not be effective. 

To make the test more effective the easy thing is to put a constant load on the motor. For example lifting a weight  would be a constant load.  Then by having a large enough load the velocity would be torque limited. Note a bucket of water is a good weight as you can change the weight easily by adding/removing water. 

A simple way to measure stall torque is to bolt a lever on the motor shaft and have the level pull a scale like:

Using this technique the torque is the weight multiple by the length of arm, assuming scale is perpendicular to the arm. 

Trampas
 

 




 

Kai Wolter

unread,
Jul 18, 2017, 3:38:18 AM7/18/17
to Mechaduino
I've uploaded a version of my firmware that calculates the shaft velocity based on the shaft angle. The velocity is saved as global variable omega and is averaged over 4 reading. the phase angle is updated based on that omega value. maybe give it a try.

I also implemented a downhill simplex and twiddle algorithm to fine tune the PID settings.

- Kai
Reply all
Reply to author
Forward
0 new messages