PDA

View Full Version : What should b the sequence for steppermotor frm PIC16F876A?


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.

KISS
May 18, 2010, 09:18 AM
Mmmm. I lost most of my stepper info, but I don't see that interface resembling an H bridge at all.

There seems to be no way to reverse the flow of current..

4 H-bridge to work, you need 4 drivers for phase. You only have 4 total.

That interface would be more suitable for a 6 wire stepper. Oddly a 24 V stepper would typically be used on a 12 V supply where the center tap is at 12V.

You need to be able to put +5 and -5 V to both windings. I don't believe you can.

Microstepping, where you use discrete values of current allows smoother transitions ad that's even more complicated.

PS: I added URL tags to your post
PPS: I believe after you're a member for a day, you can post pics directly using "Go advanced/Manage attachments"

KISS
May 18, 2010, 09:24 AM
Here is a document that might help:

Stepper Motor Switching Sequence - Developer Zone - National Instruments (http://zone.ni.com/devzone/cda/ph/p/id/247)