elex11
May 18, 2010, 05:55 AM
I am using Fraen 6405-1512 stepper motor controlled by PIC16F876A (ULN2003A as driver along with transistors to form a H-bridge) to drive a pointer of a speedometer. I need to know about the sequence (if possible in C language) which should be given to the motor windings in order to have a smooth rotation. Till now, I have achieved the motion but it's not smooth nor have I got control over it's direction of rotation. The code I wrote is given below.
the link for circuit diagram of PIC-motor interface is:
http://farm5.static.flickr.com/4064/4616205852_e22feddf86_b.jpg
the link for datasheet and other details of motor is:
http://www.fraenamd.com/steppermotor.htm
If further details are required please let me know.
code:
#include<pic.h>
int msec;
#define wait 10
interrupt void isr()
{
if (TMR2IF)
{
TMR2IF=0;
msec++;
}
}
void init_timer()
{
PIE1=0x02;
PIR1=0x00;
T2CON=0x06;
PR2=0xFA; //count to generate 1ms delay, freq of crystal is 16Mhz
INTCON=0xC0;
}
void delay( unsigned int n)
{
msec =0;
init_timer();
while (msec!=n);
msec++;
T2CON= 0x00;
}
void main()
{ TRISB = 0x00;
while(1)
{
PORTB = 0x22; // A2 B2
delay(wait); /* generates a delay of
as many millisecs as the
count in 'wait' variable */
PORTB = 0x20; // A2
delay(wait);
PORTB = 0x24; // A2 A1
delay(wait);
PORTB = 0x04; // A1
delay(wait);
PORTB = 0x14; // A1 B2
delay(wait);
PORTB = 0x10; // B2
delay(wait);
PORTB = 0x12; // B2 B1
delay(wait);
PORTB = 0x02; // B1
delay(wait);
}
}
please help me out asap.
the link for circuit diagram of PIC-motor interface is:
http://farm5.static.flickr.com/4064/4616205852_e22feddf86_b.jpg
the link for datasheet and other details of motor is:
http://www.fraenamd.com/steppermotor.htm
If further details are required please let me know.
code:
#include<pic.h>
int msec;
#define wait 10
interrupt void isr()
{
if (TMR2IF)
{
TMR2IF=0;
msec++;
}
}
void init_timer()
{
PIE1=0x02;
PIR1=0x00;
T2CON=0x06;
PR2=0xFA; //count to generate 1ms delay, freq of crystal is 16Mhz
INTCON=0xC0;
}
void delay( unsigned int n)
{
msec =0;
init_timer();
while (msec!=n);
msec++;
T2CON= 0x00;
}
void main()
{ TRISB = 0x00;
while(1)
{
PORTB = 0x22; // A2 B2
delay(wait); /* generates a delay of
as many millisecs as the
count in 'wait' variable */
PORTB = 0x20; // A2
delay(wait);
PORTB = 0x24; // A2 A1
delay(wait);
PORTB = 0x04; // A1
delay(wait);
PORTB = 0x14; // A1 B2
delay(wait);
PORTB = 0x10; // B2
delay(wait);
PORTB = 0x12; // B2 B1
delay(wait);
PORTB = 0x02; // B1
delay(wait);
}
}
please help me out asap.