3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Drive a Stepper Motor with an AVR Microprocessor

Step 6I never half-step, because I'm not a half-stepper...

Quest lyric aside, half-stepping your motor is where it's at. You get more peak current, more instantaneous torque, and twice the angular resolution.

Half-stepping in a nutshell: Instead of Blue, Black, Red, Yellow, you drive the motor with Blue, Blue+Black, Black, Black+Red, Red, Red+Yellow, Yellow, Yellow+Blue. The upshot is that for half the time you're engaging both magnets at once.

And during the times that both sets are engaged, the motor points halfway between the two, shrinking the angle between "steps" and making the motor turn more smoothly. Can you tell from the video? I'm not sure...

Now the part of the code that does the half-stepping looks like this:
void halfStepping(uint16_t delay, uint8_t direction[]){  uint8_t i;  for ( i=0; i<=3; i++ ){	    PORTB = direction[i];	/* single-coil part */    _delay_ms(delay);        PORTB |= direction[i+1];	/* add in half-step */    _delay_ms(delay);  }}

The first PORTB command sets a single pole to positive and all the rest to negative. Then it waits. Then the second PORTB command sets a second pole (on the other winding) to positive, engaging both windings for 1.4x the torque (and 2x the current).

A full program listing is attached below. Two arrays are now defined (clockwise, counterclockwise) and both have 5 elements each to allow for the i+1 entry in the halfStepping function.

« Previous StepDownload PDFView All StepsNext Step »
3 comments
Mar 17, 2008. 12:57 PMTurboTronix says:
Yes it works but not clean. I need to get the H-bridge going... Also can you by any chance give me an example code where I'll use this setup with an input pin (i.e. a photocell which will base the rotation side of the motor based on its input)? I tried but could not get it going well.
Mar 16, 2008. 2:20 PMTurboTronix says:
All worked until I used the code in your stepperMotor.c Nothing happens, the motor does not run anymore...

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
95
Followers
7
Author:The Real Elliot