Interfacing Stepper Motor with Starter AVR Using A4988 Revision as of 13:13, 14 April 2016 by Vaibhav Katkar (Talk | contribs)
In this tutorial we'll interface stepper motor with Starter AVR board using A4988 driver. For driving one stepper motor, one A4988 driver is required. A4988 has inbuilt translator so we can control this driver by just two pins, one for direction and one for controlling the steps.
Basic
Hookup
Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/io.h> | |
#include "delay.h" | |
#define stepPin PD7 //Define Step pin | |
#define dirPin PD6 //Define Direction pin | |
#define Enable PD5 //Define Enable pin | |
int main(void) | |
{ | |
int x,y; | |
DDRD |= (1<<5)|(1<<6)|(1<<7); // Configure PORTD5, PORTD6, PORTD7 as output | |
PORTD &= ~(1<<5); // Enable driver | |
while (1) | |
{ | |
PORTD |= (1<<6); //Make PORTD6 high to rotate motor in clockwise direction | |
for(x=0; x<4; x++) //Give 50 pulses to rotate stepper motor by 90 degree's in full step mode | |
{ | |
for(y=0; y<50; y++) | |
{ | |
PORTD |=(1<<7); | |
DELAY_us(700); | |
PORTD &=~(1<<7); | |
DELAY_us(700); | |
} | |
DELAY_ms(1000); | |
} | |
PORTD &= ~(1<<6); //Make PORTD6 high to rotate motor in anti-clockwise direction | |
for(x=0; x<4; x++) //Give 50 pulses to rotate stepper motor by 90 degree's in full step mode | |
{ | |
for(y=0; y<50; y++) | |
{ | |
PORTD |=(1<<7); | |
DELAY_us(700); | |
PORTD &=~(1<<7); | |
DELAY_us(700); | |
} | |
DELAY_ms(1000); | |
} | |
} | |
} |
Demo
For full demo video visit our youtube channel https://www.youtube.com/watch?v=fYsiDZhr1ZU&feature=youtu.be
Downloads