Stepper Motors - a basic tutorial

westaust55

Moderator
Attached is a brief tutorial I put together covering stepper motors.

Reference is made in the early part of the tutorial to a microchip application note and a website at the University of Iowa. readers should in particular also download and read the mentioned Microchip application note for greater detail and understanding.

Since the links are not active in the attached pdf file here they are for convenience:

I have included some example PICAXE program code for full, wave and half step modes of control. These have been tested with a bipolar stepper motor and should work with a unipolar stepper motor as well.

I have also done some serious current limiting using a 3V 2.3 Ohm bipolar stepper motor taken form an old printer (no datasheet available :rolleyes: ). Running at 4.5V and 6V with 8.2 Ohm 5 Watt resistors in series with each winding that limit the current to around 12 - 15% of the rated motor current.
The stepper motor would still turn with my finger applied with moderate-light pressure to the end of the 6mm diameter shaft.


Read and above all have fun . . . . :)
 

Attachments

westaust55

Moderator
(You must have had a very quiet New years celebs :) )
Far from it Dippy. :D
Dining and dancing the night away till 1am with a group of great friends to a reasonable band (one you can do some real dancing to like cha cha, rhumba, swing, waltz, jive etc) - even saw the blue moon (first once for ages and a rare event to have one on New Years Eve and Day.

My stepper motor reseach started a while back and the bipolar stepper motors were sourced months ago. Like to have a "play" before I commit to writing words.
 

westaust55

Moderator
Here is another example of code I wrote predominantly for the bipolar stepper motor I have but flexible enough for others to use with other stepper motors.

Compared with the example in my tutorial for half stepping which occupies 127 bytes, for a further 34 bytes, one can have a far more flexible piece of code as a subroutine which can be called with requirements defined in the main program for direction, step mode and number of revolutions.

The example below sets up four different sequences in the main program and calls the stepper motor driver subroutine Moveit: to perform the required motor movement.

Code:
; =================================================
;   File....... Bipolar Stepper Motor Control
;   Purpose.... 
;   Author..... Westaust55
;   E-mail.....
;   Started.... 04-01-2010
;   Updated.... 
; =================================================
;
; -----[ Program Description ]---------------------------------------------
;
; A program to demonstrate control of a bipolar stepper motor in both
; full step and half-step modes.
; The stepper motor has 200 steps/1.8 deg increments in full step mode
; which equates to 400 steps/ 0.9 deg increments in half-step mode 
;
; User should define the number of steps for one revolution in full step mode
;
; User can set up direction, step mode and the number of rotation in 0.1 increments
; 
;
; -----[ Revision History ]------------------------------------------------
;
; 
;
; -----[ I/O Definitions ]-------------------------------------------------
;
; - - - DIGITAL INPUT PINS  - - -

; - - - DIGITAL OUTPUT PINS - - -
SYMBOL Enable = 3 ; Enable line for the L293D H-bridge driver
;
;
; -----[ Constants ]-------------------------------------------------------
;
SYMBOL delay = 0	; delay period between each step
SYMBOL clockwise = 1
SYMBOL anticlock  = 2
SYMBOL full = 1
SYMBOL half = 2

SYMBOL total = 200	; total steps for one revolution at full step increment
;
;
; -----[ Variables ]-------------------------------------------------------
;
SYMBOL position      = w0		; Stepper motor postion counter
SYMBOL stepcount   = w1		; variable for number of steps to undertake
SYMBOL direction     = b4		; flag to define the direction of rotation
SYMBOL stepping     = b5		; flag to define step increment full/half
SYMBOL revs	    = b6		; variable for number of revolution to perform
SYMBOL cyclesteps  = b7		; number of actual steps - 1 before cycle repeats
SYMBOL codeindex   = b8		; pointer to stepper motor codes 
SYMBOL motordata   = b9		; current cond to send to the stepper motor
SYMBOL temporary    = b10		; temporary
; 
; -----[ EEPROM Data ]-----------------------------------------------------
;
;
;
; -----[ Initialization ]--------------------------------------------------
;
#PICAXE 40X1
SETFREQ m8

Init:  LOW Enable			;disable the L293D h-bridge stepper motor drive IC
	 LOW 4 			; winding 1 end 1
	 LOW 5			; winding 1 end 2
	 LOW 6 			; winding 2 end 1
	 LOW 7			; winding 3 end 2
;
; -----[ Main Program ]--------------------------------------------------
;
Main:
	; anticlockwise, full step mode and 1.5 revolutions
	direction = anticlock
	stepping = full
	revs = 15			; = total number of revolutions * 10
	GOSUB Moveit
	PAUSE 5000
	
	; anticlockwise, half step mode and 1.0 revolutions
	direction = anticlock
	stepping = half
	revs = 10			; = total number of revolutions * 10
	GOSUB Moveit
	PAUSE 5000
	
	; clockwise, full step mode and 2.0 revolutions
	direction = clockwise
	stepping = full
	revs = 20			; = total number of revolutions * 10
	GOSUB Moveit
	PAUSE 5000
	
	; clockwise, half step mode and 0.5 revolutions
	direction = clockwise
	stepping = half
	revs = 5			; = total number of revolutions * 10
	GOSUB Moveit
	PAUSE 5000
	
	GOTO Main
;
;
; -----[ Subroutines ]-----------------------------------------------------
;
Moveit:
	 IF stepping = full THEN
	 	cyclesteps = 3
	 ELSE
	 	cyclesteps = 7
	 ENDIF
	 
	 stepcount = total * revs * stepping / 10
	 
	 FOR position = 1 to stepcount  ; for the desired number of rotations

	 	IF direction = clockwise THEN
	 		codeindex = codeindex - 1 AND cyclesteps
	 	ELSE
			codeindex = codeindex + 1 AND cyclesteps
	 	ENDIF
	 	
	 	b10 = codeindex
	 	IF stepping = full THEN
	 		temporary = temporary * 2
	 	ENDIF
	 	LOOKUP temporary, (%1010, %1000, %1001, %0001, %0101, %0100, %0110, %0010 ), motordata
	 		 
	 	temporary = motordata * 16 + 8 	; move data to high nybble and add in the Enable pin as ON
	 	pins = temporary				; set the outputs
	 	PAUSE 10 					; use 5 for 4MHz else 10 when clock freq = 8MHz
	 	LOW Enable
	 	PAUSE delay
	 NEXT position
	 RETURN
;
; - - - - THE END - - - - -
 
Top