Advice required re Bipolar Stepper motors

clockwork

Member
I am in the process of designing and building a Drawing Machine from scratch using Picaxe 18m2's to control the stepper motors. The control signals from the Picaxes control L298N modules. These control Nema 17 Bipolar 200 step, stepper motors. At present I intend to use two stepper motors individually controlled with the possibliity of adding a third stepper motor and servo motor in future. The drawing machine is intended to produce cyclic patterns rather than specific images.

I have reached the point where I can control the speed and direction of the stepper motors, and made my design up using different modules, some homemade. I want the stepper motor to rotate fairly slowly in order for observers to see the patterns produced develop gradually. The problem that is becoming apparent is that at low rotational speeds the motors have pronounced judder rather than a steady rotational speed. Is it possible to reduce or even eliminate this judder at low rotational speeds?

The rotational speed is derived from using a potentiometer connected to b.3 to change the value of the delay w2 from Zero to 128.

The code I am using to control rotation is:-
Code:
Clockwise:
 
do  
        
    let PinsB = %10000000  'B.4     Energised
      pause w2

    let PinsB = %11000000  'B.4,B.5 Energised
      pause w2

      let PinsB = %01000000  'B.5     Energised
    pause w2

    let PinsB = %01100000  'B.5,B.6 Energised
      pause w2

      let PinsB = %00100000  'B.6     Energised
      pause w2

    let PinsB = %00110000  'B.6,B.7 Energised
      pause w2

      let PinsB = %00010000  'B.7     Energised
      pause w2

    let PinsB = %10010000  'B.7,B.4 Energised
      pause w2

loop
I know I could do this differently say with Geared DC motors, but I have a number of old both used and new stepper motors and L298N modules available.
Also I am aware that these drawing machines are not new, but I wanted to design and build everything from scratch and not just copy others. Ideas on how to smooth out the rotation of the motors at slow speeds would be welcome. I could run the motors at a faster speed and gear the speed back, but I am trying to keep the design
as simple as possible.

Clockwork G8RIW
 

kfjl

Member
Hi,

I never played much with stepper motors, things that get hot worry me!
Your comments don't seem to match your code:

let PinsB = %10000000 'B.4 Energised B.7?
pause w2

let PinsB = %11000000 'B.4,B.5 Energised B.7,B.6?
pause w2

let PinsB = %01000000 'B.5 Energised B.6?
pause w2

let PinsB = %01100000 'B.5,B.6 Energised
pause w2

let PinsB = %00100000 'B.6 Energised B.5?
pause w2

let PinsB = %00110000 'B.6,B.7 Energised B.4, B.5?
pause w2

let PinsB = %00010000 'B.7 Energised B.4?
pause w2

let PinsB = %10010000 'B.7,B.4 Energised
pause w2

You can get by without the "Pins" command with something like this:

#PICAXE08M2
; Drives a bipolar stepper motor using two PICAXE outputs, an L293D driver chip and a 74HCT004 inverter
; Sequence: Coil 1 Coil 2
; 1 1
; 0 1
; 0 0
; 1 0

b0=10
main:
irin[1000,main],c.3,infra
sertxd(#infra)
if infra=0 then avant
if infra=1 then arriere
if infra>1 then goto main

avant: for b1=1 to 3
high c.4 ; To coil 1
pause b0
high c.1 ; To coil 2
pause b0
low c.4
pause b0
low c.1
pause b0
next b1
goto main

arriere: for b1= 1 to 3
high c.4
pause b0
low c.1
pause b0
low c.4
pause b0
high c.1
pause b0
next b1
goto main
 

kfjl

Member
Dear Katy,

I can't get the hang of the forum editor. What I see is what I want but not what I get.
In the above post, the 1's and 0's were in the columns "Coil 1" and "Coil 0" before I posted. The B.(x)'s were a tabulation away from the original comments.
What's wrong with me?

Disgruntled, France.
 

AllyCat

Senior Member
Hi,
I can't get the hang of the forum editor. What I see is what I want but not what I get.
To maintain formatting, you probably need to use Spaces not TABs, a fixed-width Font (e.g. Courier), and enclosed within {Code ] [/Code] tags. In practice this is probably best done in a separate Text Editor (e.g. PICaxe Editor 6), then Cut and Paste the text between [ Code ] [/Code] tags (or use the Insert option ...v ) in the post.

The problem that is becoming apparent is that at low rotational speeds the motors have pronounced judder rather than a steady rotational speed. Is it possible to reduce or even eliminate this judder at low rotational speeds?
Yes, the problem with Stepper Motors is in their name, they normally move in Steps (which I presume you are referring to as judder ? ) ! If the size of the steps is larger than is acceptable for an application, there seem to be two basic possibilities: Mechanically Smooth the output after the Motor's output shaft, or drive the Motor with Microstepping Waveforms.

For the former you need a mechanical Low-Pass filter, for example a rubber band/belt driving a pulley/wheel with considerable inertia. The rubber "spring" is equivalent to a Resistor or Inductor and the inertia is equivalent to a Capacitor.

Microstepping drivers normally employ dedicated integrated circuits because their operation is quite complex, they must operate quickly and need "quasi-analogue" outputs. If your stepping is VERY slow (perhaps just a few steps per second) then it might be possible to use a PICaxe's PWM outputs (and the L298Ns) but it would need at least two and perhaps 4 PWM outputs for each Stepper Motor.

Cheers, Alan.
 

AllyCat

Senior Member
Hi,
I know I could do this differently say with Geared DC motors, but I have a number of old both used and new stepper motors and L298N modules available. ............ I am trying to keep the design as simple as possible.
I think a mechanical belt or geared reduction drive is probably the "simplest" solution, but if you want to do it purely with electronics then it might be possible to emulate a simple 2-bit (or 3-bit) DAC by using two (or more) L298Ns and two PICaxe output pin sets for each Stepper Motor. Thus each motor would require a dedicated PICaxe 18M2 with two (or three) L298Ns and some "mixing" resistors (or, perhaps better, Inductors) to deliver reasonably well-defined drive currents.

Basically you need output stages that can drive currents of "i" and "i"/2 (and perhaps "i"/4) through each stepper coil. That would be best done with custom-designed driver stages, however it might be possible to use L298N stages (which basically give a constant output voltage) driving the coils via appropriate resistor (and/or inductor) values (but not very power-efficiently). Thus one PICaxe output pin (high) would drive "i" amps through its associated coil, a second pin drive "i" / 2 amps and both together would deliver 1.5 * "i" amps. Four coil-pins would thus need the whole of PortB and a three-bits-per-coil version would need half of PortC as well.

In software terms, the first thing would be to convert your existing code to a "Lookup Table" looping version, which I've done below (untested) [edit] . Note that the original comments are incorrect because the state %1000000 actually drives pin B.7, not B.4, etc., as can be seen by running the program in the Simulator. But this version does already include "high-current" 45 degree phases compared with an alternative "fixed current" (90 degree) version which would use a table of only "data 0 , (%1000 0000 , %0100 0000 , %0010 0000 , %0001 0000 )". An even higher current version is also possible using the sequence 1001 , 1100 , 0110 , 0011 .
Code:
#picaxe 18M2
DirsB = %11110000    ; set pins as outputs
data 0 , ( %10000000 , %11000000 , %01000000 , %01100000 , %00100000 , %00110000 , %00010000 , %10010000 )
do
   for b1 = 0 to 7
      read b1 , b2
      let PinsB = b2
      pause w2
   next
loop
Then the table can be expanded to handle all the additional current levels, which will be quite complicated so I have just guessed how it might start, showing the lower-weighted bits in the lower nibble (i.e. %0000 1111). Note that the "Rate of change of current (with time)" in a sine wave is not constant, so you would not necessarily just use a "DAC" sequence of 00 , 01 , 10 and 11 (for currents of 0 * i , 0.5 * i , 1.0 * i and 1.5 * i) but perhaps 00 , 01 , 10 , 10 , 11 , 11 , 11 , 10 etc. . For clarity I have put spaces between the low and high nibbles, but the PICaxe compiler will object to this as a syntax error !
Code:
#picaxe 18M2
dirsB = %1111 1111     ; Space must be removed before syntax check !
data 0 , ( %1000 1000 )   ;  "Coil 1" at full current : ie.  b.7 gives current i , b.3 gives current i / 2  (in same coil)
data ( %1000 1100 )      ;  "Coil 1" at full current , Coil 2 at low current : ie. also b.2 gives current i / 2
data ( %1100 0000 )    ;  "Coil 1" and "Coil 2" at medium current : ie. b.7 and b.6 each give a current i (45 degrees)
data ( %0100 1100 )    ; "Coil 1" at low current and "Coil 2" at full current : ie.  b.3  and b.2 each give current i / 2
data ( %0100 0100 )    ;  "Coil 2" at full current :  : ie.  b.6 gives current i , b.2 gives current i / 2   (90 degrees phase)
data ( %0100 0110 )   ; Typically "Coil 1" at low reversed current : ie. b.1 gives current i / 2 in reverse direction
; etc.
do
   for b1 = 0 to 15        ; 16 data entries required for full cycle !
      read b1 , b2
      pinsB = b2
      pause w2
   next
loop
Cheers, Alan.
 
Last edited:

AllyCat

Senior Member
Hi,
I never played much with stepper motors, things that get hot worry me !
Yes indeed, both the L298N(s) and the Stepper Motors themselves might get VERY Hot. :(

The L298N is now a very "old" bipolar transistor design, using a Darlington Output Transistor configuration, which by its nature must drop at least one volt at higher currents, regardless of the supply voltage. That reduces the amount of drive voltage available to the Motor and of course heats up the Integrated Circuit.

Also, if the Stepper Motors are operated with a pulse period much longer than their "intended" speed, then the effect of the inductance of their coils disappears and the current may rise to that defined by the (quite low) "dc" resistance of the coils. Hence a current-driving (or limiting) circuit might be more appropriate than a simple voltage drive.

So indeed, the "simple" solution is probably to send $15 to a Chinese gentleman, and in a few weeks time you may receive a module that is able to drive a stepper motor (or 4 !) far more efficiently than we can design here. But this is intended as an "Educational" Forum, so it's interesting to see how close it might be possible to get to the original stated target. My final thought (at least until we receive any feedback from the OP) is that the L298Ns have "Enable" Inputs that could be driven from a PICaxe's PWM output. Thus perhaps a pair of high frequency PWM outputs, time-modulated by two low-frequency sinusoids (from a lookup table) having a 90 degree phase offset, might be sufficient to reduce the "judder" and/or the heating of the motors, without any major change to the present (proposed/existing ?) Hardware configuration.

Cheers, Alan.
 
Last edited:

clockwork

Member
First of all a very big thankyou to KFJL, Alleycat (Alan) and PieM for their relies. They have all provided useful information and possible ways forward.
I have now completed making the electronic parts of the project and have started to work on the mechanical design.

The stepper motors will move mechanical arms (via cranks) linked together by pivots. The rotational speed of the motors ranges from about 4 rpm to about 30 rpm (far too fast for the mechanical arms to cope with) so I will keep the max rotational speed to round 15 rpm. This may change as soon as I can test the different speeds. I will have to see if changes in motor speed improves things or if some form of damping of the mechanical arms will be required.

Due to the lever effect of unequal arm lengths to the pivot point this should reduce the level of "Judder" (non uniform rotational speed of the stepper motors). However there is the possiblitity of the amount of "Judder" increasing and descreasing due to the two motors being in phase or not. We will see.

As I am making all the moving parts adjustable in length, position of the pivots and length of the cranks on the motors, it will be a case of change something and see what happens, which should prove interesting. Drawing machines built by others have all sorts of means of adjustment including ability to move the position of the driver motors, sliding pivots and so on. This is the area that starts to make the patterns drawn onto the paper virtually infinite, and all the more interesting.

As correctly pointed out the heatsinks and motors can become very hot in operation. Whilst there are some very complex ways to reduce this problem I have opted for the simplest of inserting a 22 ohm 25 watt rated Metal housed resistor in each coil circuit. I have made a seperate board to mount the two resistors required for each motor. Incidentally these power resistors were originally included in the power lead of some subtantial unipolar stepper motors (200 step) use to directly drive each drum of the traditional One Arm Bandit. So once again they were something I already had.

It was suggested that I use DRV8825 or A4988 modules instead of the L298N modules I have used. I have purchased some of these modules and intend to use them in my next project. They appear to be far easier to use that what I am currently using

I started this project a while back when I purchased a 3018 CNC machine with the intention of producing my own engraved PCB's. This project has followed on from there. It has been a lot of new information to take in for my rather ancient grey calls, so everything has taken time.

I am trying not to make any big changes to anything in my design of drawing machine as I am hoping to have some form of prototype working by next month for an upcoming exhibition. I forgot to mention that my main hobby is as an artist specialising in landscapes and portraiture.

Many thanks to everybody for their very useful input. Clockwork G8RIW
 
Top