HowTo: controlling a stepper motor with an attiny2313

Here is how I controlled a stepper motor with an Atmel attiny2313. I found an old stepper motor in my junk box. I remembered it was a unipolar stepper but that was about it. Google couldn't find the part number, so I had no data sheet.

stepper motor

A unipolar stepper motor has four magnet/coils. Each coil must energize in sequence to spin the motor. The coils are in pairs. Each pair shares a common positive line.

The motor has 6 wires so I had to figure out what each was. The colors where: white, black, blue/red, white/blue, white/black. I pulled out my meter and checked the resistance between each set of wires.

Black wire to white wire had a resistance of about 700 ohms that meant they were a magnet/coil set. They each had low resistance to the black/white wire. They are powered by the black/white wire.

Red wire to blue wire also had resistance of about 700 ohms, so they are a set. They are powered by the blue/white wire.

To control the stepper I used an attiny2313 micro-controller and a ULN2803 darlington transistor array. The black/white and blue/white wire go straight to VCC.

The ULN2803 then turns on each coil by individually ground each of the other four wires. The attiny2313 controls the stepping sequence by sending TTL signals to the UNL2803. When a TTL signal is sent, the ULN2803 will ground a wire causing a coil to energize and spin the motor.

stepper schematic

My source code can be found here. This stepper motor has a pretty high resolution. It moves about 1.8 degrees per step, so it spins very slowly. The motor does not have a lot of torque, but you can have it spin very accurately both forwards and reverse.

stepper motor control, and the speed...

Hi Chad,

I'm currently just starting out doing some atmel programming. I've done some assembler and C already, so I've got that out of the way. Now I'm looking at interacting with different components. This is a hobby of mine.

What I'm wondering is why do you want 1000ms per pulse? can it shorten to say 500ms? shorter? I'm just wondering why you chose 1000ms, and if that's just an arbitrary delay that you chose. Can it pulse quicker?

Would it be possible to use the same code (I'm converting it to assembler) you've shown for your example, and bypass the ULN2803? I mean to short the pairs by using the controller directly instead of using the ULN2803.

Thanks,

Chris-

1000ms was just an arbitrary

1000ms was just an arbitrary number I picked.

I don't think the controller could source enough current to run the motor directly. That is why I use the ULN2803.

If you are new to micro controllers, I would suggest you try an Arduino. It used an atmel chip and comes with a stepper motor library that makes things much easier to program.

Nice writeup!

I really appreciate your writeup. Thanks for taking the time to put it all down for everyone to see.
I'm wondering, how can your setup be modified to run a stronger stepping motor?

The code should work fine.

The code should work fine. You would just need to use bigger relays. The ULN2803 max out pretty quickly. You would just need replace them with a higher capacity solid state relay.

Criticisms of outsourcing

Criticisms of outsourcing from much of the American public have been a response to what they view as very poor customer service and technical support being provided by overseas workers attempting to communicate with Americans.

Code

Nice writup,

Was experementing with Steppers too, so the code was a bonus.

Maby i'm wrong but i noticed that the two loops Reverse and Foreward both have an extra mydelay() at the end (or the beginning), This would cause the motor to stall a little at every turn (if i'm right that is)

{
mydelay (); //
PORTB = 5;
mydelay (); //
PORTB = 9;
mydelay (); //
PORTB = 10;
mydelay (); //
PORTB = 6;
mydelay (); // <-------
}

re: help

I would use winavr to program any ATmega or ATtiny. As for communicating back to the pc, i can't help you there.

http://winavr.sourceforge.net

Help, please...

Well... I nedd to control a Setepper Motor for a school project and I'm so confused because my Professor is... Huh... "Bad Teaching".

So... I need a program to control it. We use Borland Builder C++ as compliler. In fact, we (my classmates and I) have a pilot program, but it doesn't work.

I would like your help to explain me how to creat a nice programm for my motor, we have a bipolar one and use a UL2803. Te idea is use it for move a little car (a toy). Just go ahead and go back. So... There is a posibility?

Thanks...

help

How to do programming AVR Atmega8535 using C programming?

I want to read ADC input then the output will direct to PC through visual basic..

Can anyone help me?

cindy
harhariyanti@yahoo.com.sg

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is used to make sure you are a human visitor and to prevent spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.