Stepping quickly

Stepper controller prototype

Finally getting around to designing up a stepper motor controller for this chemical mixing robot that I picked up this summer. So, here is a super simple controller to drive one axis! Right now it’s using Arduino on an Atmega168, but I think i’ll switch to something lighter, give each module it’s own micro (with limit switch and encoder support), and talk to them from a master controller using some serial bus. Or just talk to them all using a parallel port on a PC ;-). Sample code for this guy after the break.

 
// _Simple_ half-stepping driver for a unipolar stepper motor
// 
// Written by Matt Mets in 2010
//
// Generates a waveform that looks like this:
//
//    ______
// A |      |_____________
//   
//         ______
// B _____|      |________
//   
//              ______  
// C __________|      |___
//   
//   _               _____  
// D  |_____________|     
 
 
// Digital I/O pins to which the n-channel FET drivers are connected
unsigned char motorPins[] = {2, 4, 5, 3};
 
 
void setup() {
  // Set all the pins to outputs, and turn them off.  
  for (unsigned char i = 0; i < 4; i++) {
    pinMode(motorPins[i], OUTPUT);
    digitalWrite(motorPins[i], LOW);
  }
}
 
// number of times the complete cycle is repeated
#define rotations 50
 
// microsecond delay between half-steps
#define delayLength 2000
 
void loop() {
  // walk forward in half-steps
  for (unsigned char j = 0; j < rotations; j++) {
    for (unsigned char i = 0; i < 4; i++) {
      digitalWrite(motorPins[(i+1)%4], HIGH);
      delayMicroseconds(delayLength);
      digitalWrite(motorPins[i], LOW);
      delayMicroseconds(delayLength);
    }
  }
 
  delay(100);
 
  // then backward
  for (unsigned char j = 0; j < rotations; j++) {
    for (unsigned char i = 0; i < 4; i++) {
      digitalWrite(motorPins[3 - ((i+1)%4)], HIGH);
      delayMicroseconds(delayLength);
      digitalWrite(motorPins[3-i], LOW);
      delayMicroseconds(delayLength);
    }
  }
 
  delay(100);
}
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>