Stepper Motor - Operation, Interfacing and Control
Stepper Motor - Operation, Interfacing and Control
• The stepper motor uses the theory of operation for magnets to make the motor
shaft turn a precise distance when a pulse of electricity is provided. The stator
has eight poles, and the rotor has six poles. The rotor will require 24 pulses of
electricity to move the 24 steps to make one complete revolution. Another way
to say this is that the rotor will move precisely 15° for each pulse of electricity
that the motor receives.
Stepper Motor Control Theory
Advantages of Stepper Motor:
• Precise positioning and repeatability of movement since good stepper motors have an accuracy of 3 – 5%
of a step and this error is non cumulative from one step to the next.
• Very reliable since there are no contact brushes in the motor. Therefore the life of the motor is simply
dependent on the life of the bearing.
• The motors response to digital input pulses provides open-loop control, making the motor simpler and
less costly to control.
• It is possible to achieve very low speed synchronous rotation with a load that is directly coupled to the
shaft.
• A wide range of rotational speeds can be realized as the speed is proportional to the frequency of t
Stepper Motor Control Theory
• A bipolar stepper motor : the opposing coils are wired in parallel and therefore the device
has just four terminals.
• The motor must be driven using circuitry that can drive current through each pair of coils in
either direction.
• This is achieved using an H-Bridge driver for each coil – this can be most easily implemented
using bridge driver ICs such as the L298 or L6201/2/3 for which behavioral simulator
models are also provided.
L298 Driver for Motor
Parameters Value
Operating Voltage Upto 46 V
DC Current 4A
LED-GREEN
FORWARD
D1 20 25
RESET PD0/SCL/INT0
26
PD1/SDA/INT1
24 27
XTAL1 PD2/RXD1/INT2
LED-BLUE 23 28
XTAL2 PD3/TXD1/INT3
REVERSE 29
PD4/ICP1
51 30
PA0/AD0 PD5/XCK1
50 31
PA1/AD1 PD6/T1
49 32
PA2/AD2 PD7/T2
48
PA3/AD3
47 2
PA4/AD4 PE0/RXD0/PDI
46 3
PA5/AD5 PE1/TXD0/PDO
45 4
PA6/AD6 PE2/XCK0/AIN0
44 5
PA7/AD7 PE3/OC3A/AIN1
6
PE4/OC3B/INT4
10 7
PB0/SS PE5/OC3C/INT5
11 8
PB1/SCK PE6/T3/INT6
12 9
PB2/MOSI PE7/ICP3/INT7
13
PB3/MISO
14 61
PB4/OC0 PF0/ADC0
15 60
PB5/OC1A PF1/ADC1
B1 16 59
PB6/OC1B PF2/ADC2
17 58
PB7/OC2/OC1C PF3/ADC3
57
PF4/ADC4/TCK
35 56
PC0/A8 PF5/ADC5/TMS
36 55
12V PC1/A9 PF6/ADC6/TDO
37 54
PC2/A10 PF7/ADC7/TDI
38
PC3/A11
39 33
PC4/A12 PG0/WR
40 34
PC5/A13 PG1/RD
41 43
PC6/A14 PG2/ALE
42 18
PC7/A15 PG3/TOSC2
19
PG4/TOSC1
62
AREF
64 1
AVCC PEN
ATMEGA128
9 4 U2
5
IN1 VCC VS
7 2 +88.8
IN2 OUT1 A
10
IN3
12 3
IN4 OUT2 B
6
ENA
11 13
ENB OUT3 C
1 14
SENSA OUT4 D
15
SENSB GND
8 L298
C Code – Stepper Motor Control
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <util/delay.h>
main()
{
// Write your code here
DDRA=255;
DDRB=0;
PORTB=255;
PORTA=0;
while (1)
{
C Code – Stepper Motor Control
if(PINB==0b11111110) / /Forward
{
}
C Code – Stepper Motor Control
if(PINB==0b11111101) / /Reverse
{
// PORTA=0b11000100;
PORTA|=(1<<6); // Set the Sixth (D6) bit of Port A
_delay_ms(100);
PORTA&=~(1<<6); // Clear the Sixth (D6) bit of Port A