Stepper Motor Interfacing with AVR ATmega32

Stepper Motor Interfacing with AVR ATmega32

Introduction

Stepper Motor
Stepper Motor
Stepper motor is a brushless DC motor that divides the full rotation angle of 360° into number of equal steps.
  • The motor is rotated by applying certain sequence of control signals. The speed of rotation can be changed by changing the rate at which the control signals are applied.
  • Various stepper motors with different step angles and torque ratings are available in the market.
  • Microcontroller can be used to apply different control signals to the motor to make it rotate according to the need of application.
For more information about Stepper Motor and how to use it, refer the topic Stepper Motor in the sensors and modules section.

Interfacing of Stepper Motor with AVR ATmega32

Stepper Motor Interface with ATmega32
Interfacing Stepper Motor With ATmega 32
  • Here we are going to interface 6 wires Unipolar Stepper Motor with ATmega32 controller.
  • Only four wires are required to control stepper motor. 
  • Two common wires of stepper motor connected to 5V supply.
  • ULN2003 driver is used to drive stepper motor.
  • Note that to know winding coil and their centre tap leads measure resistance in between leads. From centre leads we will get half resistance value of that winding.

Example

Let’s program AVR ATmega32 to rotate stepper motor 360° clockwise by half step sequence and 360° anticlockwise by full step sequence.

Program

/*
 * ATmega32 Stepper Motor Control
 * http://www.electronicwings.com
 *
 */ 


#define F_CPU 8000000UL  /* Define CPU Frequency 8MHz */
#include <avr/io.h>  /* Include AVR std. library file */
#include <util/delay.h>  /* Include delay header file */


int main(void)
{
 int period;
 DDRD = 0x0F;  /* Make PORTD lower pins as output */
 period = 100;  /* Set period in between two steps */
 while (1)
 {
  /* Rotate Stepper Motor clockwise with Half step sequence */
  for(int i=0;i<12;i++)
  {
   PORTD = 0x09;
   _delay_ms(period);
   PORTD = 0x08;
   _delay_ms(period);
   PORTD = 0x0C;
   _delay_ms(period);
   PORTD = 0x04;
   _delay_ms(period);
   PORTD = 0x06;
   _delay_ms(period);
   PORTD = 0x02;
   _delay_ms(period);
   PORTD = 0x03;
   _delay_ms(period);
   PORTD = 0x01;
   _delay_ms(period);
  }
  PORTD = 0x09;  /* Last step to initial position */ 
  _delay_ms(period);
  _delay_ms(1000);

  /* Rotate Stepper Motor Anticlockwise with Full step sequence */
  for(int i=0;i<12;i++)
  {
   PORTD = 0x09;
   _delay_ms(period);
   PORTD = 0x03;
   _delay_ms(period);
   PORTD = 0x06;
   _delay_ms(period);
   PORTD = 0x0C;
   _delay_ms(period);
  }
  PORTD = 0x09;
  _delay_ms(period);
  _delay_ms(1000);
 }
}

No comments:

Post a Comment