Author Topic: Bipolar full step sequence  (Read 7187 times)

0 Members and 1 Guest are viewing this topic.

Offline DigibinTopic starter

  • Regular Contributor
  • *
  • Posts: 90
Bipolar full step sequence
« on: December 21, 2015, 09:44:47 pm »
I purchased a stepper from China on Alibaba and it came with the attached information. I don't understand the sequence table. I know what it should be, but I cannot relate this to the what's on the sheet provided. Presumably the + indicates a positive voltage, but this would mean in step 1 you would drive both ends of coil A, which can't be right.

Am I missing something or is this just poorly presented? Or perhaps is the motor construction non-standard?
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Bipolar full step sequence
« Reply #1 on: December 21, 2015, 10:00:55 pm »
The document is borked.  Confirm the pinout with an ohmmeter

The following sequence will step a four wire bipolar stepper four whole steps per repeat:
Code: [Select]
A1 A2  B1 B2
------------
+  -   0  0
0  0   +  -
-  +   0  0
0  0   -  + 

If it goes the wrong direction either reverse the sequence, or the wires to one coil.
To half-step, activate the next coil before deactivating the previous one.

Assuming you are driving it with H-bridges, where the table says 0 0, drive both ends of the coil to the same level.




 

Online H.O

  • Frequent Contributor
  • **
  • Posts: 815
  • Country: se
Re: Bipolar full step sequence
« Reply #2 on: December 22, 2015, 06:20:54 am »
The document doens't look righ and I'm not too sure about Ian.M sequece either.... It seems to me like it might step a standard 1.8° motor at 7.2° but I'm not sure. In my experience the full-step sequence for a bipolar motor is
Code: [Select]
   A1 A2  B1 B2
   ------------
1: +  -   +  -
2: -  +   +  -
3: -  +   -  +
4: +  -   -  + 

And to half-step the motor you deactivate alternating coils between steps:
Code: [Select]
   A1 A2  B1 B2
   ------------
1: +  -   +  -
2: +  -   -  -
3: +  -   -  +
4: -  -   -  +
5: -  +   -  +
6: -  +   -  -
7: -  +   +  -
8: -  -   +  -
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Bipolar full step sequence
« Reply #3 on: December 22, 2015, 07:29:54 am »
Yes.  I think your sequence is the preferred one.   I reproduced the one I gave from memory, and it looks like I gave the half steps without the full ones. It would still step but with much reduced torque.    I'm glad we both agree the document is bogus.
 

Offline DigibinTopic starter

  • Regular Contributor
  • *
  • Posts: 90
Re: Bipolar full step sequence
« Reply #4 on: December 22, 2015, 08:16:42 am »
Yes I agree with H.O. too - for maximum torque both coils should be driven at any step. I wonder why the document is wrong... it must be a translation thing, perhaps it is interpreted differently in China.

I've tried driving the motor with this sequence via a TB6600 based board but have not had much luck. It tries to step but cannot achieve smooth rotational motion, even at very low speeds. The driver also came from China via eBay so I have reverse engineered it and am in the process of troubleshooting.
 

Offline Emil

  • Regular Contributor
  • *
  • Posts: 164
  • Country: no
    • ZeptoBit
Re: Bipolar full step sequence
« Reply #5 on: December 22, 2015, 11:58:41 am »
I've tried driving the motor with this sequence via a TB6600 based board but have not had much luck.

Except for the phase names, the sequence in the pdf looks like a correct unipolar sequence.

How do you set the sequence for the TB6600 driver? As far as I know the TB6600 only accepts step, direction and step mode.
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8172
  • Country: fi
Re: Bipolar full step sequence
« Reply #6 on: December 22, 2015, 01:08:51 pm »
"Full step" or "half step" sequence is a very poor way to model and drive a stepper motor, which basically is a synchronous AC motor with large number of poles and strong holding torque. Maybe in the 80's before integration and cheap integrated high-speed MOSFETs, it made sense to crudely approximate the desired waveform with square wave. Today, it is only a concept of history. Curiously enough, these sequence tables tend to go wrong all the time. I'm not sure why, but Wikipedia also did have it wrong for long time.

Nowadays, I think this whole "full/half stepping" concept should be totally forgotten! It's fundamentally wrong.

In 2015, there is very little reason not to drive stepper motors with PWM'd sinewaves, also called "microstepping". It is also easier to understand, because it shows that stepper motor is like any electric motor. Stepper motor, after all, is a two-phase motor which can be drawn on X-Y plane, so that sine and cosine wave produce the correct action. One phase is fed with sine, another with cosine wave; rotor follows the resulting sum magnetic field. This is the only satisfactory way of driving stepper motors. Square wave - the 80's way, often presented as "sequence tables", results in horrible mechanical vibration especially at certain resonant speeds. As "full/half stepping" offers little benefit and only confuses beginners, it should be moved from the "basic stepper motor 101" to books of history.

tldr; Stepper motors are AC motors that should be driven with sine waves for satisfactory operation using two-phase inverter. Today, market is full of integrated drivers. Forget about "sequences", they are fundamentally flawed and tend to go wrong.
 

Offline Sal Ammoniac

  • Super Contributor
  • ***
  • Posts: 1672
  • Country: us
Re: Bipolar full step sequence
« Reply #7 on: May 22, 2022, 03:26:54 am »
tldr; Stepper motors are AC motors that should be driven with sine waves for satisfactory operation using two-phase inverter. Today, market is full of integrated drivers. Forget about "sequences", they are fundamentally flawed and tend to go wrong.

I'm about to start a project that uses stepper motors, and I came upon this ancient thread. I have a lot of experience with motor control, but not with steppers. I agree that sine wave drive is probably the way to go when driving steppers, but there's one thing I'm missing here... When driving a stepper in the conventional way, it's easy to control the angle of the motor just by sending it the appropriate number of steps since each step corresponds to 1.8 degrees, or whatever the step size of the motor is. How is this done when driving a stepper with sine waves? Let's say I want to move the rotor 45 degrees, which corresponds to 25 1.8 degree steps when driving it the conventional way, how is that done?

So if I'm generating sine waves using a 256 entry lookup table, would it just be a matter of generating PWM (with a 90 degree offset between the two phases) for

                 (45 / 360) * (360 / 256) * PWM frequency

PWM updates and then just stop updating the PWM so that it stays at the last value (to provide holding torque to the motor)?

And if I want to vary the speed of rotation, I'm assuming I just use the regular formula for calculating the sine frequency required:

                 f = (RPM * poles) / 120   where poles is 200 for a 1.8 degree per step motor

Is this how it's done?
Complexity is the number-one enemy of high-quality code.
 

Online Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3360
  • Country: nl
Re: Bipolar full step sequence
« Reply #8 on: May 22, 2022, 03:14:20 pm »
the Ideal drive for a two phase stepper motor are a sine wave for each coil with a phase shift of 90 degrees between the two coils.

In modern times it is usually done with a stepper motor driver IC, and many variants of these exist, and the better the approximation of the sine waves is, the quiter and smoother the motor will run. Normally these stepper motor driver IC's are controlled by a "step" and a "direction" input, and with each pulse the driver IC shifts both sinewaves a bit. You only see the "sine waves" if such IC's get a constant stream of pulses. If the pulses stop, each motor has a (quasi) DC current and stands still.

You can also do most of it in software if you wish. both "Ananas Stepper" and "Mechaduino" are projects that calulate PWM duty cycles in software (uC timer peripheral) and then use separate H-bridges to amplify the PWM signals for the motor currents. Both are open source projects but you can also buy already made PCB's.

"mks servo57" is a similar project.

You can buy these PCB's from Ali / Ebay, but take a close look before you buy anything. The better boards have an on-board SMPS to derive the microcontroller power supply from the high motor voltage, while the cheapest boards just assume you get +5V from "elsewhere" and this can be a headache because of noise pickup and voltage drops over cables.
« Last Edit: May 22, 2022, 03:16:38 pm by Doctorandus_P »
 

Offline Sal Ammoniac

  • Super Contributor
  • ***
  • Posts: 1672
  • Country: us
Re: Bipolar full step sequence
« Reply #9 on: May 22, 2022, 05:30:41 pm »
Thanks for the reply. I’m not interested in buying or using someone else’s work—I want to do it myself using a microcontroller and H-bridges, mainly as a learning experience.
Complexity is the number-one enemy of high-quality code.
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8172
  • Country: fi
Re: Bipolar full step sequence
« Reply #10 on: May 22, 2022, 05:58:27 pm »
tldr; Stepper motors are AC motors that should be driven with sine waves for satisfactory operation using two-phase inverter. Today, market is full of integrated drivers. Forget about "sequences", they are fundamentally flawed and tend to go wrong.

I'm about to start a project that uses stepper motors, and I came upon this ancient thread. I have a lot of experience with motor control, but not with steppers. I agree that sine wave drive is probably the way to go when driving steppers, but there's one thing I'm missing here... When driving a stepper in the conventional way, it's easy to control the angle of the motor just by sending it the appropriate number of steps since each step corresponds to 1.8 degrees, or whatever the step size of the motor is. How is this done when driving a stepper with sine waves?

I still stand behind my words from 7 years ago.

Let's assume 1.8deg/step motor.

With full-stepping, you are just forced to use 1.8 deg resolution.
With half-stepping, you have 0.9 deg resolution.

With microstepping/sine wave drive, you just choose any arbitrary step size! The smaller, the better.

Then, you just index the sine/cosine tables with the step index you have chosen, and set the PWM values accordingly. The motor holds there, at any arbitrary position.

Quote
Let's say I want to move the rotor 45 degrees, which corresponds to 25 1.8 degree steps when driving it the conventional way, how is that done?

The key is to understand electrical rotation vs. physical rotation. The problem is, these motors are synchronous AC motors, but unlike other motor types which are specified by number of poles (2 poles: electrical rotation equals physical rotation. 20 poles: electrical rotation = 1/10th physical rotation i.e. 36 degrees), stepper motor manufacturers just do not specify this. So you need to back-calculate this by referring to those ancient "full steps". Since the "full stepping" pattern repeats every 4 cycles, this means, 1.8deg per step is 4*1.8 = 7.2deg per electrical revolution.

So you want to rotate it by 45 deg? It's going to be 45deg/7.2deg = 6.25 electrical revolutions. Meaning, for your 256 entry look up table, you just loop it, increasing the index one by one, finally reaching 6.25*256 = 1600 counts. (Do utilize the natural wrap-around of unsigned integers if writing in C. 256- or 65536-entry tables wrap around with no overhead at all; arbitrary 2^n size requires masking high bits when accessing the table, usually perfectly acceptable.)

In any case, the math is easy to verify in practice (we are prone to errors, anyway). Write the 256 elements long sin/cos tables, and test iterating over it by 1600 steps, see if you got 45 degrees, or if I did some error in the calculation.

If memory is limited, first optimization is to only use sine table and get cosine by accessing the table 64 elements off. I usually won't bother going further, but of course you can then only store half of the table, and get the other half by negating the value. You can again halve that by utilizing the symmetry, sin[62] == sin[64], sin[61] == sin[65] and so on.
« Last Edit: May 22, 2022, 06:03:58 pm by Siwastaja »
 

Online Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3360
  • Country: nl
Re: Bipolar full step sequence
« Reply #11 on: May 22, 2022, 10:34:20 pm »
Thanks for the reply. I’m not interested in buying or using someone else’s work—I want to do it myself using a microcontroller and H-bridges, mainly as a learning experience.

All right then.
Trow your PC out of the window, take a piece of paper and a pen and try to think of some parts you can order by mail.
And whatever direction it takes, never peek at the internet because that is cheating.  :-//
 

Offline Sal Ammoniac

  • Super Contributor
  • ***
  • Posts: 1672
  • Country: us
Re: Bipolar full step sequence
« Reply #12 on: May 23, 2022, 12:35:12 am »
tldr; Stepper motors are AC motors that should be driven with sine waves for satisfactory operation using two-phase inverter. Today, market is full of integrated drivers. Forget about "sequences", they are fundamentally flawed and tend to go wrong.

I'm about to start a project that uses stepper motors, and I came upon this ancient thread. I have a lot of experience with motor control, but not with steppers. I agree that sine wave drive is probably the way to go when driving steppers, but there's one thing I'm missing here... When driving a stepper in the conventional way, it's easy to control the angle of the motor just by sending it the appropriate number of steps since each step corresponds to 1.8 degrees, or whatever the step size of the motor is. How is this done when driving a stepper with sine waves?

I still stand behind my words from 7 years ago.

Let's assume 1.8deg/step motor.

With full-stepping, you are just forced to use 1.8 deg resolution.
With half-stepping, you have 0.9 deg resolution.

With microstepping/sine wave drive, you just choose any arbitrary step size! The smaller, the better.

Then, you just index the sine/cosine tables with the step index you have chosen, and set the PWM values accordingly. The motor holds there, at any arbitrary position.

Quote
Let's say I want to move the rotor 45 degrees, which corresponds to 25 1.8 degree steps when driving it the conventional way, how is that done?

The key is to understand electrical rotation vs. physical rotation. The problem is, these motors are synchronous AC motors, but unlike other motor types which are specified by number of poles (2 poles: electrical rotation equals physical rotation. 20 poles: electrical rotation = 1/10th physical rotation i.e. 36 degrees), stepper motor manufacturers just do not specify this. So you need to back-calculate this by referring to those ancient "full steps". Since the "full stepping" pattern repeats every 4 cycles, this means, 1.8deg per step is 4*1.8 = 7.2deg per electrical revolution.

So you want to rotate it by 45 deg? It's going to be 45deg/7.2deg = 6.25 electrical revolutions. Meaning, for your 256 entry look up table, you just loop it, increasing the index one by one, finally reaching 6.25*256 = 1600 counts. (Do utilize the natural wrap-around of unsigned integers if writing in C. 256- or 65536-entry tables wrap around with no overhead at all; arbitrary 2^n size requires masking high bits when accessing the table, usually perfectly acceptable.)

In any case, the math is easy to verify in practice (we are prone to errors, anyway). Write the 256 elements long sin/cos tables, and test iterating over it by 1600 steps, see if you got 45 degrees, or if I did some error in the calculation.

If memory is limited, first optimization is to only use sine table and get cosine by accessing the table 64 elements off. I usually won't bother going further, but of course you can then only store half of the table, and get the other half by negating the value. You can again halve that by utilizing the symmetry, sin[62] == sin[64], sin[61] == sin[65] and so on.

Thanks for the comments. I implemented this last night and it's working, although the motor doesn't seem to run any smoother than when half-stepping it.

I've implemented it using a 256 element sine lookup table and am handling the 90 offset for the other phase by offsetting the index by 1/4 of 256 (64). Looking at the output of the controller on a scope (with the motor replaced by a resistor across each phase and a low-pass filter to remove most of the PWM switching frequency) the sine and cosine waves look very smooth.

The motor is a Nema 17 bipolar with with 1.8° per step. Moving the motor 45° requires 1256 steps (rather than 1600). This is a cheap (USD$10) Chinese stepper, so perhaps 1.8° is wishful thinking. I'll switch back to full-step and half-step and see if a 45° rotation takes 25 and 50 steps.

EDIT: In half-step mode, 50 steps move the motor as close to 45° as I can measure. I don't feel any difference in motor smoothness between half-stepping it or driving it with sine waves, but in sine wave mode, it's drawing 1/3 to 1/2 the current it does when half-stepping.

EDIT2: I found a math error in my code, and when I fixed it, I am now getting 1600 counts per 45° rotation.
« Last Edit: May 23, 2022, 01:04:06 am by Sal Ammoniac »
Complexity is the number-one enemy of high-quality code.
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 21686
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Bipolar full step sequence
« Reply #13 on: May 23, 2022, 01:14:30 am »
Yup, drive with sine and cosine currents and you can divide a step arbitrarily far.

Note that the drive current is key.  If you're driving by PWM for example, you need to factor in velocity (back EMF / output voltage).  Best is to use a current mode controller -- which is what the integrated ones [usually] do, which keeps things smooth at most velocities (actual applied PWM (voltage) depends on speed).

There are voltage mode controls too; which I suppose are basically VFDs?

Tim
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8172
  • Country: fi
Re: Bipolar full step sequence
« Reply #14 on: May 23, 2022, 06:26:06 pm »
Yes, current mode will be even better. Though, steppers have quite some resistance (making voltage control approach current control), and are pretty "nonsinusoidal" anyway (by that, I mean for smooth torque, you need to pre-distort the waveform. In one project, I remember using an average of triangle and sine wave for somewhat smoother movement. It was a film scanner, so uneven speed caused image nonlinearity; I just spent some half an hour to experimentally find a waveform which reduced the effect below perception). So voltage based is nearly as good. BTW, to get constant torque, you need to scale the amplitude by frequency (called V/f control). In other words, choose whatever holding torque is necessary, but at high speeds, multiply the sine table value by higher and higher values, otherwise the torque drops at faster speeds. This is because torque is ~ current, which is basically defined by (Vapplied - Vbemf)/Rwinding, where Vbemf is the generated voltage directly proportional to RPM. A current mode controller of course automatically avoids this multiplier.

Regarding half stepping being nearly as smooth, this is no surprise - sometimes half stepping is smooth enough. Depends on the motor, how strong it is, what is the mechanical load, are there resonance modes in the complete mechanical system, etc.

Sometimes, when the smoothness really matters, it makes a real difference going from half stepping to sinusoidal nearly-infinite resolution microstepping - and you can improve even further by implementing current mode control with decoupled PI loop, also known as FOC - and then even further by empirically distorting the current waveforms to compensate for the non-sinusoidal nature of the motor.
« Last Edit: May 23, 2022, 06:31:50 pm by Siwastaja »
 
The following users thanked this post: T3sl4co1l

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 21686
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Bipolar full step sequence
« Reply #15 on: May 23, 2022, 06:52:22 pm »
Ah, interesting.  I suppose it figures that the waveform won't be sinusoidal; the slots/bars don't give perfect geometry and all that.  Easy way to figure out, should be: give it a spin and read the waveform, then duplicate that?

Tim
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8172
  • Country: fi
Re: Bipolar full step sequence
« Reply #16 on: May 23, 2022, 07:05:25 pm »
Ah, interesting.  I suppose it figures that the waveform won't be sinusoidal; the slots/bars don't give perfect geometry and all that.  Easy way to figure out, should be: give it a spin and read the waveform, then duplicate that?

Tim

Yeah, geometry plus the "cogging torque" you can feel when rotating the motor by hand - it won't feel smooth - this torque counteracts the generated torque. Good idea regarding reading the waveform, but I'm not sure how the cogging torque interacts with this. Add a large flywheel to make it run smooth during measurement, at least. Or maybe that's exactly what you don't want to do, I'm not sure. My experience on this is limited to experimentally finding good enough waveform and call it a day.

https://en.wikipedia.org/wiki/Cogging_torque
 

Offline Sal Ammoniac

  • Super Contributor
  • ***
  • Posts: 1672
  • Country: us
Re: Bipolar full step sequence
« Reply #17 on: May 23, 2022, 10:54:29 pm »
The motor I'm using has quite a bit of cogging torque, which probably accounts for the buzzy feeling when I hold the motor in my hand when it's turning. That's not really an issue in my application, however, so I won't bother with trying to reproduce a waveform that results in smoother motion. I suppose that's just one of the characteristics of steppers--the PMSM motors I use with FOC control in other applications feel absolutely smooth when running. Steppers feel more akin to switched reluctance motors.
Complexity is the number-one enemy of high-quality code.
 

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 4427
  • Country: dk
Re: Bipolar full step sequence
« Reply #18 on: May 23, 2022, 10:58:37 pm »
The motor I'm using has quite a bit of cogging torque, which probably accounts for the buzzy feeling when I hold the motor in my hand when it's turning. That's not really an issue in my application, however, so I won't bother with trying to reproduce a waveform that results in smoother motion. I suppose that's just one of the characteristics of steppers--the PMSM motors I use with FOC control in other applications feel absolutely smooth when running. Steppers feel more akin to switched reluctance motors.

depends alot on the driver, https://youtu.be/Lx40lJkk9NQ
 

Offline Sal Ammoniac

  • Super Contributor
  • ***
  • Posts: 1672
  • Country: us
Re: Bipolar full step sequence
« Reply #19 on: May 23, 2022, 11:18:02 pm »
The motor I'm using has quite a bit of cogging torque, which probably accounts for the buzzy feeling when I hold the motor in my hand when it's turning. That's not really an issue in my application, however, so I won't bother with trying to reproduce a waveform that results in smoother motion. I suppose that's just one of the characteristics of steppers--the PMSM motors I use with FOC control in other applications feel absolutely smooth when running. Steppers feel more akin to switched reluctance motors.

depends alot on the driver, https://youtu.be/Lx40lJkk9NQ

When I said "buzzy", I meant that I could feel the motor vibrating in my hand. It doesn't produce any sound that I can hear when it's spinning (at least none that I can hear in my lab, which is fairly quiet).
Complexity is the number-one enemy of high-quality code.
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8172
  • Country: fi
Re: Bipolar full step sequence
« Reply #20 on: May 24, 2022, 07:19:24 am »
If you are familiar with FOC, then it's perfectly valid on steppers, too. Steppers are 2-phase motors so you don't need Clarke and inverse Clarke transform at all.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf