Welcome! Log In Create A New Profile

Advanced

A4988 stepper driver on Stepstick, current setting

Posted by wim 
wim
A4988 stepper driver on Stepstick, current setting
June 05, 2012 01:37PM
I have a question about the A4988 stepper motor driver, as used on the Stepstick board. It's about the setting of VREF in combination of the value of the sense resistor and the VDD voltage.
I have a step motor where the phase current is specified as 0.26A (per coil). Should I set VREF such that Itripmax is equal this current? That would be VREF = Itrip * 8 * Rs = 0.26 * 8 * 0.2 = 0.42V. Or somewhat larger? Or double?... Should I increase Rs to let's say 1 ohm?
And what about the VDD voltage? The step motor I have has a coil resistance of 36ohm, thus max voltage will be 9.36V. I thought of using 15V, and have the A4988 regulate accordingly. But I noticed that I could go lower than 9V, and also noticed different behaviour of the motor with higher voltages, like more vibrating.

Question basically is: what is the optimum values for Rs, Vref, and VDD, in given situation, with required priority of reliable stepping (e.g. lowest vibration, not missing steps), and as fast as possible. Somebody care to comment on this? (I noticed several questions here on this IC, so I reckon there's somebody out there...smiling smiley
Thank's
_Wim_
Re: A4988 stepper driver on Stepstick, current setting
June 06, 2012 03:58AM
The most reliable way is to ignore all these current calculations, as these calculations ignore the mechanics (friction, mass acceleration). For another procedure, see [reprap.org]


Generation 7 Electronics Teacup Firmware RepRap DIY
     
wim
Re: A4988 stepper driver on Stepstick, current setting
June 06, 2012 09:38AM
Well, that is indeed the pragmatic approach. However I need to make the design such that upfront I'm ensured that everything will work reliable... I can experiment on the lab bench, but would like to match that with some math.

What is the idea behind these values for Rs, VDD, and Itrip? For instance the 0.2 ohm in the stepstick seems to me rather low value for my stepper with only 0.26A current!? I was thinking of increasing that to 1 ohm. Does that make sense?
Are those calculations, you mentioned, somewhere described, such that I can verify the theory with the reality?
_Wim_
Re: A4988 stepper driver on Stepstick, current setting
June 06, 2012 11:27AM
Perhaps you should read the datasheet smiling smiley

VDD is the logic supply voltage and should be 5V or 3.3V to match your logic.

VBB needs to be high enough to get the desired current taking into account the coil resistance but at that value the switching frequency tends to zero so you want it a good deal higher to keep it ultrasonic. The higher it is the faster the motor can go. The limit is the 35V supply max and you are best keeping it below 30V as the motor can put transients onto the supply.

Rs is 0.2R on a stepstick for 1A as any higher would exceed the 1/4W resistor dissipation. It is 0.05R on a Pololu so it can handle 2A. You could make it bigger for a lower max current taking into account the resistor Wattage. The sense voltage should be no more than 0.5V on a 5V system and no more than 3.3V/8 on a 3.3V system. Higher values need higher Wattage resistors, which get big and expensive in surface mount packages and cause more losses. Lower values will be more sensitive to ground noise.

If your motor is rated for 0.26A per coil with both coils on (the normal way of rating them) you can set Itrip up to 1.4 times that as it is the peak current into 1 coil. Motors typically get very hot at the full rating.

The other critical value is ROSC which sets the fixed off time. This must be big enough to allow the smallest microstep current but small enough to keep the switching frequency ultrasonic.

See my blog for the detailed maths: [hydraraptor.blogspot.co.uk]

And [hydraraptor.blogspot.co.uk] for what happens when ROSC is wrong.

Edited 2 time(s). Last edit at 06/06/2012 11:30AM by nophead.


[www.hydraraptor.blogspot.com]
wim
Re: A4988 stepper driver on Stepstick, current setting
June 07, 2012 05:32AM
Thanks nophead, I'm trying to understand the maths. I thought this device would make life simple: just provide a step from the ucontroller, and the A4988 does its magic thing ...

A few replies on your answer:
VDD .. VBB I mixed them up in my original question. VDD offcourse is my logic supply, in my case 3.3V. Interesting though your remark that Vsense should be less than 3.3/8=0.4125V. It's not in the datasheet... (which I did read, but still struggling to fully understand...)

About Rsense. Indeed it is a matter of keeping Vsense below, lets say 0.4 V but rather closer to a few hundred mV to avoid sensitivity to GND noise and keeping the power consumption low enough. So I reckoned with 1ohm I could have currents up to 1.5 times my motor current of 0.26A, which would yield in a max Vs=0.39V and power consumption of 150mW. Which sounds reasonable for a 1206 res. But perhaps I could go a bit lower to for instance 0R7...

However I'm still struggling with the maths for Vref....You mentioned to setup Itripmax 1.4 times. That would imply a Vref = 8 * 1R * 1.4 * 0.26A = 2.9V. (And with the 0.2 ohm currently fitted in my stepstick board that would be Vref = 0.6V)
But how did you come to this 1.4 value? I can't relate that to the articles I've read from you.

Then about that fixed off time... The stepstick board uses a 10K to GND on the ROSC pin. According the datasheet that would give a Toff=10K/825=12us. Right now I'm only using full-step mode, but from what I understand it would be better to use half step or 1/4 step, to avoid resonance. So the minimum current for 1/4 step will be 0.26A * sin(pi/2*4)=38% of 0.26A= 100mA ?? May I conclude that the ratio of Ton/Toff determines the current, as in I = Ton/Toff * Itripmax. So if Itripmax is 1.4*0.26A = 0.364A, Ton @100mA will be 3us, and Ton @0.26A = 8us ??

Is above total non-sense... or am I getting closer in understanding the maths...??
BTW, I can't find the minimum Ton time from the datasheet, I reckon that is an important value as well.!?

Thanks in advance for your feedback..!
_Wim_
Re: A4988 stepper driver on Stepstick, current setting
June 07, 2012 08:40AM
wim Wrote:
-------------------------------------------------------
> Thanks nophead, I'm trying to understand the
> maths. I thought this device would make life
> simple: just provide a step from the ucontroller,
> and the A4988 does its magic thing ...

Yes I think everybody thinks that and Pololu sell them like they are plug and play, but they only microstep correctly under a very limited set of conditions.

>
> A few replies on your answer:
> VDD .. VBB I mixed them up in my original
> question. VDD offcourse is my logic supply, in my
> case 3.3V. Interesting though your remark that
> Vsense should be less than 3.3/8=0.4125V. It's not
> in the datasheet... (which I did read, but still
> struggling to fully understand...)

It isn't stated but it is implicit. The trip point is Vref / 8 so on a 3.3V system that can at most be 3.3/8. On a 5V system the limit for Vref is 4V, so you need resistor in series with the pot. On a 3.3V system you don't

>
> About Rsense. Indeed it is a matter of keeping
> Vsense below, lets say 0.4 V but rather closer to
> a few hundred mV to avoid sensitivity to GND noise
> and keeping the power consumption low enough. So I
> reckoned with 1ohm I could have currents up to 1.5
> times my motor current of 0.26A, which would yield
> in a max Vs=0.39V and power consumption of 150mW.
> Which sounds reasonable for a 1206 res. But
> perhaps I could go a bit lower to for instance
> 0R7...
>
1ohm seems reasonable. Things are a lot less critical when with a high resistance motor.

> However I'm still struggling with the maths for
> Vref....You mentioned to setup Itripmax 1.4 times.
> That would imply a Vref = 8 * 1R * 1.4 * 0.26A =
> 2.9V. (And with the 0.2 ohm currently fitted in my
> stepstick board that would be Vref = 0.6V)
> But how did you come to this 1.4 value? I can't
> relate that to the articles I've read from you.

It is sin(45) and cos(45), = sqrt(2) 1/sqrt(2). That is the value of the current when both coils are on equally so if you are relating the current to the motor specification that is the value to use. This is where the myth that micro stepping reduces torque comes from. It doesn't if you take this into account.


>
> Then about that fixed off time... The stepstick
> board uses a 10K to GND on the ROSC pin. According
> the datasheet that would give a Toff=10K/825=12us.
> Right now I'm only using full-step mode, but from
> what I understand it would be better to use half
> step or 1/4 step, to avoid resonance. So the
> minimum current for 1/4 step will be 0.26A *
> sin(pi/2*4)=38% of 0.26A= 100mA ?? May I conclude
> that the ratio of Ton/Toff determines the current,
> as in I = Ton/Toff * Itripmax. So if Itripmax is
> 1.4*0.26A = 0.364A, Ton @100mA will be 3us, and
> Ton @0.26A = 8us ??
>

The blog article I linked has the maths I use, backed up by measurements to show it is correct. To get an accurate figure for the motors we use I had to take into account the motor resistance, the sense resistor and the MOSFET on resistances. Since the resistance of your motor is large compared to all the other resistances the formula may simplify for an approximation, but supply voltage must still come into it.

Ron and Roff will be almost the same as the motor resistance, call it R.

Toff = Ton (V/IR - 1)

> BTW, I can't find the minimum Ton time from the
> datasheet, I reckon that is an important value as
> well.!?

Yes IIRC it is called blank time on the datasheet. It deliberately ignores the sense current for a short time to avoid the ringing when the current first turns on.

Edited 1 time(s). Last edit at 06/08/2012 04:54AM by nophead.


[www.hydraraptor.blogspot.com]
wim
Re: A4988 stepper driver on Stepstick, current setting
June 08, 2012 04:32AM
Thanks again nophead, it's getting clear to me bit by bit. But to be honest I'm still struggling with the theory behind your maths. (And I need to fully understand to warrant a reliable design!).

I realize that VBB comes into the equation: the higher the voltage --> the higher the current through the motor coil --> the lower the Ton time will be. Right?
But I fail to understand your formula: Toff = Ton (V/IR - 1) or as in your math article: Toff = Ton (V/I - Ron) /Roff
But I'm re-reading your article over and over, and probably there will be a moment I fully understand... winking smiley

Also I fail to understand that I need to set Itripmax to sqrt(2) of my rated motor current. I would think that I need to set it to some value higher than the rated motor current, to avoid a PWM duty cycle (close to) 100%. For example a Itripmax twice my rated motor current would cause a 50% dutycycle, and that translates into a certain frequency. (Also depending on the fixed Toff time offcourse). Am I correct?

But, as said, I will be re-reading your articles on this subject over and over, untill I get it....!winking smiley
Re: A4988 stepper driver on Stepstick, current setting
June 08, 2012 04:53AM
wim Wrote:
-------------------------------------------------------
> I realize that VBB comes into the equation: the
> higher the voltage --> the higher the current
> through the motor coil --> the lower the Ton time
> will be. Right?

The higher VBB is the faster the current builds up to reach Itrip, so the lower Ton is. The current always hovers around Itrip, regardless of supply voltage. That is why it is known as constant current drive.

> But I fail to understand your formula: Toff = Ton
> (V/IR - 1) or as in your math article: Toff = Ton
> (V/I - Ron) /Roff
> But I'm re-reading your article over and over, and
> probably there will be a moment I fully
> understand... winking smiley

The current ramps up during Ton and ramps down during Toff. At steady state these changes must be equal. When looking at Toff = Ton (V/IR - 1) you see that when IR tends to V then Ton tends to infinity. I.e. when the voltage needed (IR) across the coil resistance R to get current I approaches the supply voltage V the switching frequency tends to 0.


>
> Also I fail to understand that I need to set
> Itripmax to sqrt(2) of my rated motor current. I
> would think that I need to set it to some value
> higher than the rated motor current, to avoid a
> PWM duty cycle (close to) 100%. For example a
> Itripmax twice my rated motor current would cause
> a 50% dutycycle, and that translates into a
> certain frequency. (Also depending on the fixed
> Toff time offcourse). Am I correct?

No the PWM is not a percentage of Itripmax. I tripmax is simply the peak current in one coil. Motor currents and holding torque are specified for the full step position with two coils on. When the Allegro is at that position it sets the current in each coil to Itripmax / sqrt(2) . I.e. about 70% so to get the datasheet condition you set Itripmax to sqrt(2) times the datasheet value.

I should have said above: sin(45) and cos(45) = 1/sqrt(2). Sorry for the confusion.

Edited 2 time(s). Last edit at 06/08/2012 04:57AM by nophead.


[www.hydraraptor.blogspot.com]
wim
Re: A4988 stepper driver on Stepstick, current setting
June 08, 2012 01:21PM
If I understand you correctly, you are saying that my motor (Sonceboz 6540-13-2-36) with a specified phase current of 0.26A, requires 0.37A for 100% load (*sqrt(2)). But if I set Vref such that Itripmax=0.37A, then actually in order to drive the motor 100%, the Ton is near infinite, or continuously on!? I would expect that Itripmax is set to value greater than the max motor current, to allow the PWM let say at 75% to output the full motor current.. Am I completly off?
_Wim_

Edited 1 time(s). Last edit at 06/08/2012 01:34PM by wim.
Re: A4988 stepper driver on Stepstick, current setting
June 08, 2012 02:54PM
wim Wrote:
-------------------------------------------------------
> If I understand you correctly, you are saying that
> my motor (Sonceboz 6540-13-2-36) with a specified
> phase current of 0.26A, requires 0.37A for 100%
> load (*sqrt(2)).

Yes the peak current into one coil needs to be sqrt(2) times the two coil on current. The power dissipation in the motor is the same in any position because is it I^2R in each coil and sin^2(x) + cos^2(x) = 1. Also the torque is the same in any position.

But if I set Vref such that
> Itripmax=0.37A, then actually in order to drive
> the motor 100%, the Ton is near infinite, or
> continuously on!?

It would only be continuously on if the voltage needed to get that current was equal to the supply voltage. Chopper drives only work properly when the supply voltage is several times the motor voltage. The motors we use for Reprap are only 2.8V motors for a 12V supply. The supply has to be high enough to keep the frequency ultrasonic and also high enough to overcome the back EMF when the motor is spinning at its fastest speed. I.e. when it spins it acts as a generator and that voltage it generates is subtracted from the supply causing the current to build up slower and the on time to increase.

>I would expect that Itripmax is
> set to value greater than the max motor current,
> to allow the PWM let say at 75% to output the full
> motor current.. Am I completly off?
> _Wim_

Yes you are completely off. If you allow the pot to set the current higher than needed it doesn't change the PWM ratio. The PWM ratio depends on the demanded current, the motor resistance and the supply voltage (ignoring the losses in the transistors, sense resistors and the eddy currents). The current is determined by the microstep position and the actual value of VREF. The maximum value of VREF only needs to be sufficient to give maximum current you want to use.


[www.hydraraptor.blogspot.com]
wim
Re: A4988 stepper driver on Stepstick, current setting
June 08, 2012 03:16PM
OK! That makes sense.! But I give it a rest this weekend. Back on monday...
wim
Re: A4988 stepper driver on Stepstick, current setting
June 11, 2012 11:12AM
Well I did some measurements, and made the following observations:
- Setting Vref too high, causes the motor to miss steps. Even setting it to the value to achieve a Itripmax of 260mA (specified coil current) is not reliable. Actually setting Vref such that Itripmax = 150mA seems a good value for smooth stepping.
- Increasing Vbb has also a negative effect on stepping. I measured across Rsense, I noticed within the time of two steps a voltage ramping up and then the PWM starts to regulate. Changing Vbb increased the ramping up (makes sense), but apperantly with negative effect on reliabilty. I could decrease Vbb quite low, and observed on the scoop that the ramp up gets slower, and less time for the PWM. (Again makes sense)
So a good value for Vbb seems to be about 3 times higer than the actual coil voltage. Total power consumed is also much less as the datasheet says: 1.5W instead of 5W.
Conclusion:
I can't really relate the datasheet and theory with my observations...
Re: A4988 stepper driver on Stepstick, current setting
June 11, 2012 11:46AM
No it makes no sense that more current would lose steps until you get to the point where the chip overheats and shuts down.

Also more voltage giving faster rise times should only be beneficial until you get to the point where the off time is too short to allow the lowest steps.


Are you sure you don't have some ground / signal problems where more current causes the step signal to be corrupted?


[www.hydraraptor.blogspot.com]
wim
Re: A4988 stepper driver on Stepstick, current setting
June 11, 2012 01:15PM
Hmm, at this moment everything is indeed build with some loose wires, etc. I noticed already a lot of noise on the scope, and planned to build it more decently... With your remark, I definitely will re-build my setup!
wim
Re: A4988 stepper driver on Stepstick, current setting
June 15, 2012 06:53AM
Just an update, and a thank you for your help. I (finally) (I thinkwinking smiley) understand what's going on. I rebuild my test setup in a more reliable way, have a single ground point such to avoid ground bounce on my signals, use shielded cables for a position sensor I'm using, ect.

The figures I measure now match with your theory. And for some reason, I suddenly understand your article about "Motor maths", and correct me if I'm wrong, but you are actually stating the following relation between Vbb, Itripmax, Rcoil, Ton and Toff:
Toff= Ton * (Vbb / Rcoil * Itripmax - 1). (In case Rcoil is siginifantly larger than the R of the FETs)

And indeed if I set Vref such that my Itripmax is 1.4 higher than the rated current according the datasheet, then in fullstep mode (where Itrip is 71% of Itripmax), the motor consumes the full 5W for which it is specified. However I found out that in my application I could reduce the power significantly to ~2W, and still have enough torque left.

Putting above formula in Excel, and calculate resulting Ton, Frequency, etc it is easy now to define my Vbb, Rsense and Vref.

Again thanks for your help!
_Wim_smileys with beer
Re: A4988 stepper driver on Stepstick, current setting
June 15, 2012 07:06AM
wim Wrote:
-------------------------------------------------------
> The figures I measure now match with your theory.
> And for some reason, I suddenly understand your
> article about "Motor maths", and correct me if I'm
> wrong, but you are actually stating the following
> relation between Vbb, Itripmax, Rcoil, Ton and
> Toff:
> Toff= Ton * (Vbb / Rcoil * Itripmax - 1). (In
> case Rcoil is siginifantly larger than the R of
> the FETs)

Yes that is correct. It is always very satisfying when theory and reality match.


[www.hydraraptor.blogspot.com]
wim
Re: A4988 stepper driver on Stepstick, current setting
June 15, 2012 08:09AM
Great! As we in Holland say: "het kwartje is gevallen"... (I believe English has the same expresion: "The penny has dropped")
Sorry, only registered users may post in this forum.

Click here to login