Welcome! Log In Create A New Profile

Advanced

Adapting Sprinter for new electronics

Posted by MaxPro3D 
Adapting Sprinter for new electronics
January 27, 2014 11:42AM
Hi every one,

I'm currently working, with my project group, on a new version of a PCB using L298 for Mendel printer. Our PCB is working well, and now we are adapting Sprinter to our PCB. We have some troubles because we use the "stepper.h" library and the .step function in the ISR(TIMER1_COMPA_vect) function. Unfortunately it doesn't work and we don't see where is the mistake. For example, when I send "G1 X20.0", the stepper make 1 or 2 steps and stop, and Pronterface freeze. My code is on GitHub (MaxPro3D/Spinter-master) and our PCB is on our website (https://sites.google.com/site/imppro3den/material-part).

Thank you for your help !
Re: Adapting Sprinter for new electronics
January 30, 2014 02:28PM
Hey,

I don't know if you're still stuck on this problem and I haven't seen your PCB design or your code but I originally used the L298 as well.

The stepper library in arduino is for stepper motors that are being directly driven from the arduino by transistors, whereas the L298 simply has the ability to reverse the polarity over two coils. There's a good chance that this might be the issue. To amend it, I simply modified the library slightly so that instead of having two pins high at once, you only have one pin high at once.

I'm having trouble explaining what I mean, but essentially you want to find the code in Stepper.cpp that says this:

void Stepper::stepMotor(int thisStep)
{
  if (this->pin_count == 2) {
    switch (thisStep) {
      case 0: /* 01 */
      digitalWrite(motor_pin_1, LOW);
      digitalWrite(motor_pin_2, HIGH);
      break;
      case 1: /* 11 */
      digitalWrite(motor_pin_1, HIGH);
      digitalWrite(motor_pin_2, HIGH);
      break;
      case 2: /* 10 */
      digitalWrite(motor_pin_1, HIGH);
      digitalWrite(motor_pin_2, LOW);
      break;
      case 3: /* 00 */
      digitalWrite(motor_pin_1, LOW);
      digitalWrite(motor_pin_2, LOW);
      break;
    } 
  }
  if (this->pin_count == 4) {
    switch (thisStep) {
      case 0:    // 1010
      digitalWrite(motor_pin_1, HIGH);
      digitalWrite(motor_pin_2, LOW);
      digitalWrite(motor_pin_3, HIGH);
      digitalWrite(motor_pin_4, LOW);
      break;
      case 1:    // 0110
      digitalWrite(motor_pin_1, LOW);
      digitalWrite(motor_pin_2, HIGH);
      digitalWrite(motor_pin_3, HIGH);
      digitalWrite(motor_pin_4, LOW);
      break;
      case 2:    //0101
      digitalWrite(motor_pin_1, LOW);
      digitalWrite(motor_pin_2, HIGH);
      digitalWrite(motor_pin_3, LOW);
      digitalWrite(motor_pin_4, HIGH);
      break;
      case 3:    //1001
      digitalWrite(motor_pin_1, HIGH);
      digitalWrite(motor_pin_2, LOW);
      digitalWrite(motor_pin_3, LOW);
      digitalWrite(motor_pin_4, HIGH);
      break;
    } 
  }
}

and replace it with this:

void Stepper::stepMotor(int thisStep)
{
  if (this->pin_count == 2) {
    switch (thisStep) {
      case 0: /* 01 */
      digitalWrite(motor_pin_1, LOW);
      digitalWrite(motor_pin_2, HIGH);
      break;
      case 1: /* 11 */
      digitalWrite(motor_pin_1, HIGH);
      digitalWrite(motor_pin_2, HIGH);
      break;
      case 2: /* 10 */
      digitalWrite(motor_pin_1, HIGH);
      digitalWrite(motor_pin_2, LOW);
      break;
      case 3: /* 00 */
      digitalWrite(motor_pin_1, LOW);
      digitalWrite(motor_pin_2, LOW);
      break;
    } 
  }
  if (this->pin_count == 4) {
    switch (thisStep) {
      case 0:    // 1000
      digitalWrite(motor_pin_1, HIGH);
      digitalWrite(motor_pin_2, LOW);
      digitalWrite(motor_pin_3, LOW);
      digitalWrite(motor_pin_4, LOW);
      break;
      case 1:    // 0100
      digitalWrite(motor_pin_1, LOW);
      digitalWrite(motor_pin_2, HIGH);
      digitalWrite(motor_pin_3, LOW);
      digitalWrite(motor_pin_4, LOW);
      break;
      case 2:    //0010
      digitalWrite(motor_pin_1, LOW);
      digitalWrite(motor_pin_2, LOW);
      digitalWrite(motor_pin_3, HIGH);
      digitalWrite(motor_pin_4, LOW);
      break;
      case 3:    //0001
      digitalWrite(motor_pin_1, LOW);
      digitalWrite(motor_pin_2, LOW);
      digitalWrite(motor_pin_3, LOW);
      digitalWrite(motor_pin_4, HIGH);
      break;
    } 
  }
}

I haven't tested this code but there's no reason it shouldn't work, also this will only work on the 4 pin stepper motor because obviously the L298 has a four pin input.

Might I ask why you're opted for the L298? It's a seriously outdated driver that is no longer much cheaper than the A4988, although I do like the idea of using components only solderable by hand (Easier to play with).

Anyway, good luck, i hope this fixes your issue, let me know if not and I'll take a look at your code when i have time smiling smiley

Jordan

P.S. I'm sure you were probably already going to, but I suggest you add this code to a new file in the project source, and call it stepperController.cpp or something. Otherwise people will have to modify their Arduino libraries to prevent the same problem smiling smiley

Edited 2 time(s). Last edit at 01/30/2014 04:04PM by JHart96.
Re: Adapting Sprinter for new electronics
January 31, 2014 02:46PM
Hi Jordan,

Thanks for you response. I will test this the next week but I think it's not the problem. Indeed when I create a sketch like this :
#include 

int nbPas = 200;
int trMin = 30;
int pas = 200;

// Moteur X
int XEN = 45; // X-EN
int AX = 47;   // AX
int BX = 44;   // BX
int CX = 50;   // CX : modif : 40=41 (sans doute faux contact)
int DX = 39;   // DX

Stepper MX (nbPas, AX, BX, CX, DX);

int xmin=14;
int etatX=0;

// Motor Y
int YEN = 43; // Y-EN
int AY = 42;   // AY
int BY = 41;   // BY
int CY = 38;   // CY
int DY = 37;   // DY

Stepper MY(nbPas, AY, BY, CY, DY);

int ymin=16;
int etatY=0;

// Motor Z
int ZEN = 49; // Z-EN
int AZ = 48;   // AZ
int BZ = 46;   // BZ
int CZ = 36;   // CZ
int DZ = 35;   // DZ

Stepper MZ(nbPas, AZ, BZ, CZ, DZ);

int zmin=18;
int etatZ=0;

// Motor E0
int E0EN = 31; // E0-EN
int AE0 = 33;   // AE0
int BE0 = 34;   // BE0
int CE0 = 30;   // CE0
int DE0 = 32;   // DE0

Stepper ME0(nbPas, AE0, BE0, CE0, DE0);

// Motor E1
int E1EN = 26; // E1-EN
int AE1 = 28;   // AE1
int BE1 = 29;   // BE1
int CE1 = 25;   // CE1
int DE1 = 27;   // DE1

Stepper ME1(nbPas, AE1, BE1, CE1, DE1);

//Alim
int led=13;

void setup() {
  pinMode(XEN, OUTPUT);
  pinMode(xmin, INPUT);
  MX.setSpeed(trMin);
  pinMode(YEN, OUTPUT);
  pinMode(ymin,INPUT);
  MY.setSpeed(trMin);
  pinMode(ZEN, OUTPUT);
  pinMode(zmin,INPUT);
  MZ.setSpeed(trMin);
  pinMode(E0EN, OUTPUT);
  ME0.setSpeed(trMin);
  pinMode(E1EN, OUTPUT);
  ME1.setSpeed(trMin);
  
  pinMode(led, OUTPUT);
  Serial.begin(9600); 
}

void loop() {
  digitalWrite(led,HIGH);

  digitalWrite(XEN, HIGH);
  etatX=digitalRead(xmin);

  while(etatX!=1)
  {
    MX.step(-1);
    etatX=digitalRead(xmin);
  }
  MX.step(pas);
  
  digitalWrite(YEN, HIGH);
  etatY=digitalRead(ymin);
  
  while(etatY!=1)
  {
    MY.step(-1);
    etatY=digitalRead(ymin);
  }
  MY.step(pas);

  digitalWrite(ZEN, HIGH);

  MZ.step(-50);
  
  digitalWrite(E0EN, HIGH);

  ME0.step(100);
  
  digitalWrite(E1EN, HIGH);

  ME1.step(100);
}

All the 5 motors work well. I wonder if this is not a problem of timer because when I tried to debug Sprinter manually with some Serial.print I found that when the program meet the timer part it stops working and I can't use Pronterface anymore without disconnect the printer. Neverless I will test your idea.
Re: Adapting Sprinter for new electronics
February 04, 2014 02:06PM
Sorry for the late reply.

If the stepper library is working for your system then that is great, and my suggestion probably won't fix it sad smiley

I've taken a look at your code and there are a couple of things I would try but I don't know if you've already tried them.

If you have skype or something I'd be quite happy to message about it in real time. I used to have the sketch files for a conversion I made for sprinter to L298 but I lost it when I updated my computer.

If you can't, I would suggest connecting four LEDs to the output pins and try turning the motor, you should get the 4 LEDs lighting up in a sequence.

Let me know what happens as your code should work smiling smiley

Jordan
Re: Adapting Sprinter for new electronics
February 05, 2014 04:53AM
Hi,

Actually I wrote a new version of Sprinter (keeping the g-code reader and changing the stepper command), and it works correctly (with some little bugs). If you want we can set up a skype I am available on thursday afternoon. I sent you an MP with my skype adress.
Sorry, only registered users may post in this forum.

Click here to login