5 Phase Stepper Driver v.2

I’ve got some unfinished business with my 5 phase stepper motors.  Thought of giving it another try, this time with an Arduino which I had lying around.

With a new Design of L298s driving the phases instead of IRF540s, the results are much better than before.

5-phase-stepper-v2-schematic
Schematic – 5 phase stepper driver v2

The arduino drives the 5 phases according to the same sequence as in my previous atempt (ref. http://www.cs.uiowa.edu/~jones/step/types.html#multiphase). A PWM of 30kHz at 55% duty Cycle keeps the current through the phases at a manageable level of 2A. Digital pins 2-6 of the Arduino drive the phases while Digital pin 10 drives the enable pins of the L298 with the PWM signal. Digital Pins 12, and 13 are the step and direction inputs. The code can currently only do full step.

20160612_223430

Code.


const int phaseA = 2;
const int phaseB = 3;
const int phaseC = 4;
const int phaseD = 5;
const int phaseE = 6;

const int stepInput = 12;
const int dirInput = 13;
const int fullHalfInput = 8;

int eSeq[] = {
  B01011000, // 88
  B01001000, // 72
  B01101000, // 104
  B00101000, // 40
  B00101100, // 44
  B00100100, // 36
  B00110100, // 52
  B00010100, // 20
  B01010100, // 84
  B01010000, // 80
};

int currentPos = 0;
int delayTime = 975; // by trial and error

int lastStepState = 0;

void setup() {
  // initialize the serial port:
  Serial.begin(9600);
  
  DDRD = B01111100;
  DDRB = B00000110; 

  TCCR1A = _BV(COM1A1) | _BV(COM1B1) ; // phase and frequency correct mode. NON-inverted mode
  //phase/frequency correct mode. SELECT THIS FOR INVERTED OUTPUTS.
  TCCR1B = _BV(WGM13) | _BV(CS10);
  
  ICR1=265; // 400 for 20kHz, 265 for 30.1kHz
  int dc = 55.0;
  
  OCR1B = int((dc/100.0)*ICR1);
  OCR1A = int((dc/100.0)*ICR1);
}

void loop() {
/* 
  // Uncomment for continuous operation.
  while(1){
    int pos = getNextPos();
   
    PORTD = B11111111 & eSeq[pos];
    //Serial.println(PORTD);
    delayMicroseconds(delayTime);
  }
*/

  // Full step sequence drive
  int currentStepState = digitalRead(stepInput);
  if(currentStepState != lastStepState){
    if( currentStepState == HIGH ){
      //Serial.println("step on");
      int pos = getNextPos();
      PORTD = B11111111 & eSeq[pos];
      delayMicroseconds(delayTime);
      //Serial.println(eSeq[pos]);
    }
  }
  
  lastStepState = currentStepState;
  
}

int getNextPos(){
  if(digitalRead(dirInput) == HIGH){
    currentPos = currentPos+1;
    if(currentPos > 9){
      currentPos = 0; 
    }
  }else{
    currentPos = currentPos-1;
    if(currentPos<0){
      currentPos=9;
    }
  }
  
  return currentPos;
}
Next steps : 
Use the ADC to sense the voltage across the 0.5OHM resistor, and automatically control the current by adjusting the pwm.
Use the enable pins to emulate a 0V position to do 4-phase and 4-5phase drives as in http://www.orientalmotor.com/technology/articles/2phase-v-5phase.html

References : 
http://www.oxgadgets.com/2011/04/creating-a-variable-frequency-pwm-ouhttps://easyeda.comtput-on-arduino-uno.html
https://sites.google.com/site/qeewiki/books/avr-guide/pwm-on-the-atmega328

Schematics drawn using : https://easyeda.com online schematic tool
Advertisements

3 thoughts on “5 Phase Stepper Driver v.2

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s