Bipolar full step sequence - Page 1
Forum section: electronics / projects

author: Digibin
author_rank: Regular Contributor
timestamp: December 21, 2015, 09:44:47 pm
content: 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?

author: Ian.M
author_rank: Super Contributor
timestamp: December 21, 2015, 10:00:55 pm
content: The document is borked. Confirm the pinout with an ohmmeterThe following sequence will step a four wire bipolar stepper four whole steps per repeat:Code:A1 A2 B1 B2------------+ - 0 00 0 + -- + 0 00 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.

author: H.O
author_rank: Frequent Contributor
timestamp: December 22, 2015, 06:20:54 am
content: 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 isCode:A1 A2 B1 B2------------1: + - + -2: - + + -3: - + - +4: + - - +And to half-step the motor you deactivate alternating coils between steps:Code:A1 A2 B1 B2------------1: + - + -2: + - - -3: + - - +4: - - - +5: - + - +6: - + - -7: - + + -8: - - + -

author: Ian.M
author_rank: Super Contributor
timestamp: December 22, 2015, 07:29:54 am
content: 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.

author: Digibin
author_rank: Regular Contributor
timestamp: December 22, 2015, 08:16:42 am
content: 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.

author: Emil
author_rank: Regular Contributor
timestamp: December 22, 2015, 11:58:41 am
content: Quote from: Digibin on December 22, 2015, 08:16:42 amExcept for the phase names, the sequence in the pdf looks like a correctunipolarsequence.How do you set the sequence for the TB6600 driver? As far as I know the TB6600 only accepts step, direction and step mode.

author: Siwastaja
author_rank: Super Contributor
timestamp: December 22, 2015, 01:08:51 pm
content: "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.

author: Sal Ammoniac
author_rank: Super Contributor
timestamp: May 22, 2022, 03:26:54 am
content: Quote from: Siwastaja on December 22, 2015, 01:08:51 pmI'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 frequencyPWM 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 motorIs this how it's done?

author: Doctorandus_P
author_rank: Super Contributor
timestamp: May 22, 2022, 03:14:20 pm
content: 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.

author: Sal Ammoniac
author_rank: Super Contributor
timestamp: May 22, 2022, 05:30:41 pm
content: 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.

author: Siwastaja
author_rank: Super Contributor
timestamp: May 22, 2022, 05:58:27 pm
content: Quote from: Sal Ammoniac on May 22, 2022, 03:26:54 amI 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.QuoteThe key is to understand electrical rotation vs. physical rotation. The problem is, these motorsaresynchronous AC motors, but unlike other motor types which are specified bynumber 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 == sin, sin == sin and so on.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: May 22, 2022, 10:34:20 pm
content: Quote from: Sal Ammoniac on May 22, 2022, 05:30:41 pmAll 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.

author: Sal Ammoniac
author_rank: Super Contributor
timestamp: May 23, 2022, 12:35:12 am
content: Quote from: Siwastaja on May 22, 2022, 05:58:27 pmThanks 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.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: May 23, 2022, 01:14:30 am
content: 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  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

author: Siwastaja
author_rank: Super Contributor
timestamp: May 23, 2022, 06:26:06 pm
content: 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.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: May 23, 2022, 06:52:22 pm
content: 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

author: Siwastaja
author_rank: Super Contributor
timestamp: May 23, 2022, 07:05:25 pm
content: Quote from: T3sl4co1l on May 23, 2022, 06:52:22 pmYeah, 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 youdon'twant 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

author: Sal Ammoniac
author_rank: Super Contributor
timestamp: May 23, 2022, 10:54:29 pm
content: 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.

author: langwadt
author_rank: Super Contributor
timestamp: May 23, 2022, 10:58:37 pm
content: Quote from: Sal Ammoniac on May 23, 2022, 10:54:29 pmdepends alot on the driver,https://youtu.be/Lx40lJkk9NQ

author: Sal Ammoniac
author_rank: Super Contributor
timestamp: May 23, 2022, 11:18:02 pm
content: Quote from: langwadt on May 23, 2022, 10:58:37 pmWhen 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).

author: Siwastaja
author_rank: Super Contributor
timestamp: May 24, 2022, 07:19:24 am
content: 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.