booksbybibin Forum Index booksbybibin
Bibin John's electronics forum
 
  FAQFAQ    SearchSearch    MemberlistMemberlist    UsergroupsUsergroups    fchat fChat  RegisterRegister  
  ProfileProfile    Log in to check your private messages Log in to check your private messages    Log in Log in 

stepper motor interfacing with AVR ( C)(unipolar stepper)

 
Post new topic   Reply to topic    booksbybibin Forum Index -> Microcontrollers
View previous topic :: View next topic  
Author Message
yogi



Joined: 25 Jun 2006
Posts: 185

PostPosted: Wed Jun 28, 2006 4:56 pm    Post subject: stepper motor interfacing with AVR ( C)(unipolar stepper) Reply with quote

This tutorial is taken from the book
MY EXPERIENCE IN PROGRAMMING AVR MICROCONTROLLER
IN C USING WINAVR/AVRGCC.

you can download it free from the files
section(FILE-AVRBOOK.RAR) of yahoo group-booksbybibin

http://groups.yahoo.com/group/booksbybibin/

comments about this book on
www.booksbybibin.blogspot.com


UNIPOLAR STEPPER MOTOR INTERFACING
Here I used power transistors instead of ULN2003. The NPN power transistors are used for driving. The base of transistor are connected to the microcontroller ports and emitter grounded and the collector is connected to the points of the stepper motor. The common ends of both coils are connected to the Vcc=12V (from adapter) of the power supply.
FOLDER:unipolarstepper(yahoo group-booksbybibin, file-avrbook.rar)



Have a closer look









Code:

/*----------------------------------------------------------------
-----------------HEADER FILES-------------------------------------
-----------------------------------------------------------------*/
#include<avr/io.h>


/*----------------------------------------------------------------
-------------CONNECTION BETWEEN L293D AND ATMEGA32---------------
-----------------------------------------------------------------*/
#define L293D_DDR    DDRC
#define L293D_PORT     PORTC
#define Pin_1         0
#define Pin_2        1
#define Pin_3         2
#define Pin_4        3
#define L293D_Mask   0x0f


/*----------------------------------------------------------------
-----------------FUNCTIONS---------------------------------------
-----------------------------------------------------------------*/
void Init_Ports(void);
void delay_ms(unsigned char time_ms);

void main()
{
int i;
int steps[]={9,3,6,12};
Init_Ports();
i=0;
do
{
L293D_PORT=steps[i];
i++;
if(i>4) i=0;
delay_ms(50);
}
while(1);
}



/*----------------------------------------------------------------
-----------------FUNCTIONS TO INITIALIZE PORTS--------------------
-----------------------------------------------------------------*/
void Init_Ports(void)
{
L293D_DDR|=(_BV(Pin_1 )|_BV(Pin_2)|_BV(Pin_3 )|_BV(Pin_4)); //setting pins for output
L293D_PORT&=~(_BV(Pin_1 )|_BV(Pin_2)|_BV(Pin_3 )|_BV(Pin_4));//starting motor is Off
}
/*----------------------------------------------------------------
--------FUNCTION TO GENERATE DELAY IN MILLISECONDS----------------
-----------------------------------------------------------------*/
void delay_ms(unsigned char time_ms)
{
   unsigned short delay_count = F_CPU / 400;

   unsigned short cnt;
   asm volatile ("n"
                  "L_dl1%=:nt"
                  "mov %A0, %A2nt"
                  "mov %B0, %B2n"
                  "L_dl2%=:nt"
                  "sbiw %A0, 1nt"
                  "brne L_dl2%=nt"
                  "dec %1nt" "brne L_dl1%=nt":"=&w" (cnt)
                  :"r"(time_ms), "r"((unsigned short) (delay_count))
   );
}






/*----------------------------------------------------------------
-------------CONNECTION BETWEEN L293D AND ATMEGA32---------------
-----------------------------------------------------------------*/
#define L293D_DDR DDRC
#define L293D_PORT PORTC
#define Pin_1 0
#define Pin_2 1
#define Pin_3 2
#define Pin_4 3
#define L293D_Mask 0x0f
int steps[]={9,3,6,12};
Here only steps changed,rest remain same. Remember to put the program in infinite loop for continuous rotation of motor.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    booksbybibin Forum Index -> Microcontrollers All times are GMT


Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum