Motor Shield Trouble

by zonk on Mon Mar 11, 2013 8:41 am

Hello There,

i am working with the Adafruit Motor Shield (v1.2), in whole I am quite satisified but things don't work 100% as they should.

TECHNICAL SETUP
motors:
3 x dc motor 10V / 800mA Peak (Datasheet: http://www.produktinfo.conrad.com/daten ... 1M9A04.pdf)
1 x geared dc Motor 12V / 1600mA Peak (Datasheet: http://www.produktinfo.conrad.com/daten ... _1_600.pdf)

external powersource:
11V / 5000mA

Controller:
Arduino UNO SMD

MY PROBLEM
If I attach any of the smaller DC Motors (10V/800mA Peak) to the Connectors M3 or M4 they work very very limited and got almost no tourque. They get switched pretty fast between Backward and Forward and especially when the run Forward they dont really run, they just try :) (The geared 12V Motor works on M3 and M4 but doesn't get switched between Backward and Forward).

What I did until know:
- attached 10V Motors to M1 and M2 - they worked as they should on M1 and M2 but work hardly on M3 and M4
- switched L293D H-Bridges - Problem is still there, M3 and M4 work very limited
- Piggybagged L293D H-Bridges - Problem is still there, M3 and M4 work very limited
- checked the soldering connections and reheated when in doubt - Problem is still there, M3 and M4 work very limited

Notes
- The H-Bridges get warm but not hot
- I accelerat and brake the small DC-Motors with motorXX.setSpeed(basicSpeed + speedValue), basicSpeed always stays the same, speedValue changes very rapidly. If I increase the basicSpeed for Motors attached to M3 and M4 they work a bit better but it doesn't solve the Problem.
- Power Indicator LED is on

I attached pictures of the top and bottom of my motorshield, maybe somebody can help.

Thanks a lot in advance and cheers form Berlin, Germany
Simon
Attachments
mShield_top_2.jpg
mShield_top_2.jpg (712.96 KiB) Viewed 804 times
mShield_bottom_2.jpg
mShield_bottom_2.jpg (685.56 KiB) Viewed 804 times
zonk
 
Posts: 8
Joined: Mon Mar 11, 2013 7:49 am

Re: Motor Shield Trouble

by adafruit_support_bill on Mon Mar 11, 2013 8:50 am

I don't see any obvious problems with your assembly. Can you post the code you are using?
User avatar
adafruit_support_bill
 
Posts: 28161
Joined: Sat Feb 07, 2009 9:11 am

Re: Motor Shield Trouble

by zonk on Mon Mar 11, 2013 9:19 am

That was fast!
thank you very much for your reply,

Just a few more words: The 10V DC motors (motorYellow, motorBlue, motorRed) move the sliders of motorized faders.
I am using the values of the built in potentiometers (wiperYellow, wiperBlue, wiperRed) to adjust the positions of the sliders relative to data,
which gets sent in via Serial. The geared Motor feeds the Paper (motorFeed);
The project is basically a homebrewn chart recorder and part of my bachelorthesis.

Notes:
- The 10V Motors are controlled by the Method moveFaders(), you will find it at the bottom of the code.
- I am using an PID Library to controll the movement of the motors (http://playground.arduino.cc//Code/PIDLibrary)

Anyway here is my code, Thanks a lot in advance:

Code: Select all | TOGGLE FULL SIZE
#include <SoftwareSerial.h>
#include <AFMotor.h>
#include <PID_v1.h>


//Arduino Pin Assignments

// Fader Motoren

AF_DCMotor motorYellow(4);
AF_DCMotor motorBlue(3);
AF_DCMotor motorRed(2);

// Slidefader

const int wiperYellow      = 4;   //Position of fader relative to GND (Analog 0)
const int wiperBlue        = 3;   //Position of fader relative to GND (Analog 0)
const int wiperRed        = 2;   //Position of fader relative to GND (Analog 0)


// Motor Feed
AF_DCMotor motorFeed(1);

//Variables fader
double faderMax        = 0;   //Value read by fader's maximum position (0-1023)
double faderMin        = 0;   //Value read by fader's minimum position (0-1023)

int minSpeed = 65;

int speedYellow = 200;
int speedBlue = 200;
int speedRed = 200;

int targetYellow = 0;
int targetBlue = 0;
int targetRed = 0;

// Fader Set Target Intervall
long previousMillisSetTarget = 0;
int setTargetState = LOW;
long intervalSetTarget = 200;            // villeicht nicht kleiner als PID SetSampleTime() (200ms Standard) ?

// --- PID Variables

double setpointYellow, inputYellow, outputYellow;
double setpointBlue, inputBlue, outputBlue;
double setpointRed, inputRed, outputRed;

//Specify the links and initial tuning parameters
PID yellowPID(&inputYellow, &outputYellow, &setpointYellow,1,0.01,0.0019, DIRECT); // für gelben und blauen Fader (vermutlich noch nicht so gapud)
PID bluePID(&inputBlue, &outputBlue, &setpointBlue,1,0.01,0.0019, DIRECT); // für gelben und blauen Fader (vermutlich noch nicht so gapud)
PID redPID(&inputRed, &outputRed, &setpointRed,1,0.01,0.0019, DIRECT);
// --- Serial Communication

//BinaryDataFromProcessing

#define HEADER        '|'
#define DATAY         'Y'
#define DATAB         'B'
#define DATAR         'R'


#define MESSAGE_BYTES  4  // the total bytes in a message

long difMillis = 0;
long millisLastBit = 0;

int serialValRaw = 0;
int serialValueYellow = 0;
int serialValueBlue = 0;
int serialValueRed = 0;

// ---  ablauf
int pushButton = 2;
int buttonState = 0;
int writeState = 0;
int ledPin = 13;

void setup() {   

  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("lininschreiber_bahn_05");
  Serial.println("----");
  delay(500);

  pinMode (pushButton, INPUT);
  pinMode (ledPin, OUTPUT);


  // UNBEDINGT LASSEN SONST KRACHT SCHREIBER IN DIE WAND
  faderMax = 1000;
  faderMin = 20;


  Serial.print("faderMax = ");
  Serial.println(faderMax);

  Serial.print("faderMin = ");
  Serial.println(faderMin);


  motorYellow.setSpeed(speedYellow);
  motorBlue.setSpeed(speedBlue);
  motorRed.setSpeed(speedRed);
  motorFeed.setSpeed(255);


  targetYellow = faderMin;
  targetBlue = faderMin;
  targetRed = faderMin;

// turn the PID on
  yellowPID.SetMode(AUTOMATIC);
  bluePID.SetMode(AUTOMATIC);
  redPID.SetMode(AUTOMATIC);

  yellowPID.SetOutputLimits(-100,100); 
  bluePID.SetOutputLimits(-100,100);
  redPID.SetOutputLimits(-100,100); 

yellowPID.SetSampleTime(1);
bluePID.SetSampleTime(1);
redPID.SetSampleTime(1);



  // reseting Faders

  motorYellow.run(FORWARD);
  while (targetYellow < analogRead(wiperYellow)) {
  };  //Loops until motor is done moving
  motorYellow.run(RELEASE);

  motorBlue.run(FORWARD);
  while (targetBlue < analogRead(wiperBlue)) {
  };  //Loops until motor is done moving
  motorBlue.run(RELEASE);

  motorRed.run(FORWARD);
  while (targetRed < analogRead(wiperRed)) {
  };  //Loops until motor is done moving
  motorRed.run(RELEASE);

  delay(100);




}

// -------------------------------

void loop() {


  // ----- Serial Data

  buttonState = digitalRead(pushButton);
  digitalWrite(ledPin, writeState);

  if ( Serial.available() >= MESSAGE_BYTES)
  {

    writeState = HIGH;
    millisLastBit = millis();

    if( Serial.read() == HEADER)
 {
      char tag = Serial.read();
     
      if(tag == DATAY) {
        int valYellow = Serial.read() * 256;
        valYellow = valYellow + Serial.read();
//        Serial.print("dataYellow: ");
//        Serial.println(valYellow);
        int serialValRawYellow = valYellow;
        serialValueYellow = map(serialValRawYellow, 0 ,1023, faderMin, faderMax);
                setpointYellow = serialValueYellow;

      }
         if(tag == DATAB) {
        int valBlue = Serial.read() * 256;
        valBlue = valBlue + Serial.read();
//        Serial.print("dataBlue: ");
//        Serial.println(valBlue);
        int serialValRawBlue = valBlue;
        serialValueBlue = map(serialValRawBlue, 0 ,1023, faderMin, faderMax);
        setpointBlue = serialValueBlue;
      }
      if(tag == DATAR) {
        int valRed = Serial.read() * 256;
        valRed = valRed + Serial.read();
//        Serial.print("dataRed: ");
//        Serial.println(valRed);
        int serialValRawRed = valRed;
        serialValueRed = map(serialValRawRed, 0 ,1023, faderMin, faderMax);
        setpointRed = serialValueRed;
      }
    else
      {
//        Serial.print("got message with unknown tag ");
//        Serial.println(tag);
      }
    }
  }
 
 

  // ---- checking Serial, switching of Motor if long time no serial

  difMillis = millis() -  millisLastBit;
  if(difMillis > 500){
    writeState = false;
  }

  // ------

  if(writeState){

    unsigned long currentMillis = millis();
    motorFeed.run(FORWARD);

    // --- controlling slidefaders ------------------------

    moveFaders();

  }
 
  else {

    if(buttonState == HIGH){
      Serial.println("button pressed");
      motorFeed.run(FORWARD);
    }
    else {
      motorYellow.run(RELEASE);
      motorBlue.run(RELEASE);
      motorRed.run(RELEASE);
      motorFeed.run(RELEASE);

    }
  }
}


void moveFaders(){

  // reading wipers on fader
inputYellow = analogRead(wiperYellow);
inputBlue = analogRead(wiperBlue);
inputRed = analogRead(wiperRed);

// compute PID
yellowPID.Compute();
bluePID.Compute();
redPID.Compute();

// move the faders based on computed PID
  if(outputYellow < 0){
  speedYellow = minSpeed + (outputYellow*-1);
  motorYellow.setSpeed(speedYellow); 
  motorYellow.run(FORWARD);
  } if (outputYellow > 0) {
  speedYellow = minSpeed + outputYellow;
  motorYellow.setSpeed(speedYellow); 
  motorYellow.run(BACKWARD); 
  } else {
      motorYellow.setSpeed(0); 
      speedYellow = 0;
  }

    if(outputBlue < 0){
  speedBlue = minSpeed + (outputBlue*-1);
  motorBlue.setSpeed(speedBlue); 
  motorBlue.run(FORWARD);
  } if (outputBlue > 0) {
  speedBlue = minSpeed + outputBlue;
  motorBlue.setSpeed(speedBlue); 
  motorBlue.run(BACKWARD); 
  } else {
    motorBlue.setSpeed(0); 
  speedBlue = 0;
  }

    if(outputRed < 0){
  speedRed = minSpeed + (outputRed*-1);
  motorRed.setSpeed(speedRed); 
  motorRed.run(FORWARD);
  } if (outputRed > 0){
  speedRed = minSpeed + outputRed;
  motorRed.setSpeed(speedRed); 
  motorRed.run(BACKWARD); 
  } else {
  motorRed.setSpeed(0);
 speedRed = 0;
  }

}

zonk
 
Posts: 8
Joined: Mon Mar 11, 2013 7:49 am

Re: Motor Shield Trouble

by adafruit_support_bill on Mon Mar 11, 2013 9:59 am

To rule out a software problem, let's start with something simpler: Run the "MotorTest" example from the AF_Motor Library on each of the 4 motor ports and see how the motors perform.
User avatar
adafruit_support_bill
 
Posts: 28161
Joined: Sat Feb 07, 2009 9:11 am

Re: Motor Shield Trouble

by zonk on Mon Mar 11, 2013 10:32 am

Hey there, thank you so much for caring
I tested all 4 Motor Ports with the same 10V Motor,
this is how the motor performend (in words since no pro measuring equipment) on the individual ports.

M1 - Motor accelerates with low frequent gentle noise / noticable resistance when holding the slider while motor moves
M2 - Motor accelerates with low frequent gentle noise / noticable resistance when holding the slider while motor moves
M3 - Motor accelerates with high frequent buzzing noise / almost no noticable resistance when holding the slider while motor moves
M4 - Motor accelerates with high frequent buzzing noise / almost no noticable resistance when holding the slider while motor moves
zonk
 
Posts: 8
Joined: Mon Mar 11, 2013 7:49 am

Re: Motor Shield Trouble

by adafruit_support_bill on Mon Mar 11, 2013 10:47 am

Running the same tests - what is the range of voltages measured on the motor terminals for each port?
User avatar
adafruit_support_bill
 
Posts: 28161
Joined: Sat Feb 07, 2009 9:11 am

Re: Motor Shield Trouble

by zonk on Mon Mar 11, 2013 11:20 am

M1 +/- 0V -> 8,42V
M2 +/- 0V -> 8,4V
M3 +/- 0V -> 8,42V
M4 +/- 0V -> 8,45V

thank you
zonk
 
Posts: 8
Joined: Mon Mar 11, 2013 7:49 am

Re: Motor Shield Trouble

by adafruit_support_bill on Mon Mar 11, 2013 12:06 pm

Those measurements are with the motor connected? It sounds as if the shield is functioning normally.
User avatar
adafruit_support_bill
 
Posts: 28161
Joined: Sat Feb 07, 2009 9:11 am

Re: Motor Shield Trouble

by zonk on Mon Mar 11, 2013 12:40 pm

Hey there,

jap, they are connected to the motor and you are right, it sounds like the shield is allright.
Sadly it still doesnt work :(

Summarized:
Two identical 10V Motors wired to Port 1 & Port 4 at the same time (should perform exactly equal):
- Motor on Port 1 emits a low frequent noise and works.
- Motor on Port 4 emits a higher frequent noise, also works but accelerates less spontaneous and delayed compared to Motor on Port 1.
The same 10V Motor alternately on Port 1 or Port 4:
- on Port 1 low frequent noise
- on Port 4 higher frequent noise

strange, any other suggestions?
thank you very much
zonk
 
Posts: 8
Joined: Mon Mar 11, 2013 7:49 am

Re: Motor Shield Trouble

by adafruit_support_bill on Mon Mar 11, 2013 1:13 pm

The difference in noise is probably the frequency of the PWM signal. Motor efficiency can change with PWM frequency, but at full speed (255), the duty cycle will be 100% and the frequency will be irrelevant.

If you change MotorTest to just run the motors at full speed, do you still feel a difference in torque for M3 and M4?
User avatar
adafruit_support_bill
 
Posts: 28161
Joined: Sat Feb 07, 2009 9:11 am

Re: Motor Shield Trouble

by zonk on Mon Mar 11, 2013 2:25 pm

Hey, this sounds very interesing.
if i run all three 10V motors at full speed they perform very equal (no noise, equal reaction to change in direction and equal torque).
It would be hard to give up PWM. I am using it to adjust the motors to get nice smooth curves on the paper (chart recorder),
without it the lines looks kind of stiched because the slider moves over a given target, changes into the other direction, moves over it again and back again …

However, Thanks for caring again, you are doing a great job
zonk
 
Posts: 8
Joined: Mon Mar 11, 2013 7:49 am

Re: Motor Shield Trouble

by adafruit_support_bill on Mon Mar 11, 2013 3:23 pm

Unfortunately, the PWM frequency of M3 and M4 is fixed at 1KHz. This is because the PWM pins for these ports are tied to Timer 0 and Timer 0 is used internally by the Arduino for other purposes (e.g. millis()). (This is true for regular Arduinos. The Mega supports different frequencies for M3 & M4).

Most motors work fine with 1KHz PWM frequency. I suspect Alps may be using "coreless" motors in those pots. Coreless motors have lower inductance and don't operate well at low PWM frequencies.
User avatar
adafruit_support_bill
 
Posts: 28161
Joined: Sat Feb 07, 2009 9:11 am

Re: Motor Shield Trouble

by zonk on Mon Mar 11, 2013 4:42 pm

I learned something today :).
I'll think about it, probably go get a mega and see how that works.
Thank you so much for your help, I will tell how i solved the problem.
Motorshield is still great!!

Cheers from Berlin
Simon
zonk
 
Posts: 8
Joined: Mon Mar 11, 2013 7:49 am

Re: Motor Shield Trouble

by zonk on Tue Mar 12, 2013 6:01 am

SOLVED
you were absolutely right, the trick was to get a MEGA and change the PWM frequency of
the pins controlling the Motors. All four pins produce a 488.28125 hz PWM Signal now
and it works like a charm. This helped a lot -> http://sobisource.com/?p=195
Thanks again for helping, have a nice day

cheers from Berlin
zonk
 
Posts: 8
Joined: Mon Mar 11, 2013 7:49 am