Motor runs only at 255 PWM...why?

Hello Everybody,

i have that “Pololu 24v12 Motor Driver” (http://www.pololu.com/catalog/product/757) and I am wondering why I only can run my Motor (Standard RC-Car-Motor) at 255 PWM …
If i change the PWM to 254 or lower it doesn´t move ?!

//        This is for Forward / Backward

               if (data[1] <= -1)
                {
                  digitalWrite(13, HIGH); // Set direction as forward
                  analogWrite(10, 255);  // Set the speed as full
                }
                
                else if (data[1] >= 1)
                {
                   digitalWrite(13, LOW); // Set direction as backwards
                   analogWrite(10, 255);
                }

“Data[1]” is the variable from my Gyro sensor.

Any Idea what´s the Problem here?

Thank you very much
Greetings
Kelevra86

Your code snippet looks ok. Maybe the problem is somewhere else in the code? We can only guess...

Maybe the problem is how you have it wired up. Again, we can only guess...

Yeah if its just a little brushed motor it should work just fine. And if you had a brushless or something else it probably just wouldn't work. Perhaps Pics or a schematic would help?

Got it Standard-Wired, according to the Scheme in the Link from “Pololu”.

Here´s my complete Code:
I am using “Amarino” to control the Motor. At 255 the Motor will turn For- or Backward, according to my Smartphone.
But not at any other PWM-Frequenzy …

#include <MeetAndroid.h>
#include <Servo.h> 

// *********************************************
//       Programm by: T.Knaab
//       Connect Servo as follows:
//       ::: BLACK --> GND :::
//       ::: RED --> 5V :::
//       ::: Signal --> PIN 9 ::: 
// *********************************************





 
Servo myservo;  // create servo object to control a servo 
               
 
int pos = 90;        // variable to store the servo position 
int speedpos = 0;        // variable to store the motor speed
int servopin = 9;
MeetAndroid meetAndroid(error);
float data[3] = {0};
int intdata[3] = {0};
int i = 0;


void error(uint8_t flag, uint8_t values)   // Error Handling
{
  Serial.print("ERROR: ");
  Serial.print(flag);
}





void setup() 
{ 
  pinMode(servopin, OUTPUT);
  pinMode(13, OUTPUT);    // Set Pin 13 as output, this is the direction control
  Serial.begin(115200);
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object    
  meetAndroid.registerFunction(floatValues, 'A');  //use event A in amarino
} 
 
 
void loop() 
{ 
  meetAndroid.receive(); // you need to keep this in your loop() to receive events
}

void floatValues(byte flag, byte numOfValues)
{
  // create an array where all event values should be stored
  // the number of values attached to this event is given by
  // a parameter(numOfValues)
  
  // call the library function to fill the array with values
  meetAndroid.getFloatValues(data);
  
  // access the values
  for (int i=0; i<3;i++)
  {
    meetAndroid.send(data[i]);
  }
  
//        ..===========================================..
//        ||                                           ||
//        ||     Control Algorithmus                   ||
//        ||                                           ||
//        ''===========================================''
  
   
   
  
  //        This is for Turn Left/Turn Right
    
                if (data[0] <= -1)
                {
                    
                
                 intdata[0] = int(data[0]); //Cast the X axis float value to int
                 intdata[0] = intdata[0]+10;
                 pos = intdata[0]*9;
                 myservo.write(pos);
                 
                                    
  
                }
                
                else if (data[0] >= 1)
                {
                  intdata[0] = int(data[0]); //Cast the X axis float value to int
                 intdata[0] = intdata[0]+10;
                 pos = intdata[0]*9;
                 myservo.write(pos);
                 
                  
                 
                }
               
    
    
      //        This is for Forward / Backward

               if (data[1] <= -1)
                {
                  digitalWrite(13, HIGH); // Set direction as forward
                  analogWrite(10, 255);  // Set the speed as full
                }
                
                else if (data[1] >= 1)
                {
                   digitalWrite(13, LOW); // Set direction as backwards
                   analogWrite(10, 255);
                }
                
     
    
    
}

Weird, weird, weird...!

Are you seeing the pin 13 direction LED changing as you expect?

I wonder if the PWM signal is somehow mucking-up your gyro data?? If data[1] is zero, it won't do anything... You might try taking-out the if-statements, or forcing data[1] to a known value.

Also, try hooking-up an LED (and resistor) to pin 10 to "see" what's happening. From what you're saying, the LED should turn off (or go very dim) at 254. But, if the PWM is working properly, you won't see much change between 254 and 255, and you might not be able to detect any difference at all.

data[1] is an array element... Is that correct?

Good Idea DVDdoug,

I now I am using this Code (same function, but without Amarino):

I have hooked up an LED to Pin10.
At 255 → LED on
Anything other → LED off

Arduino… Y U NO PWM?!

// *********************************************
//    
//       Connect Servo as follows:
//       ::: BLACK --> GND :::
//       ::: RED --> 5V :::
//       ::: Signal --> PIN 9 ::: 
//
// *********************************************


#include <Servo.h> 
 
Servo myservo;              // create servo object to control a servo 
                            // a maximum of eight servo objects can be created 
 
int pos=90;                // variable to store the servo position 
char value;
int servopin = 9;


void setup() 
{ 
  pinMode(servopin, OUTPUT);
  Serial.begin(115200);
  myservo.attach(9);          // attaches the servo on pin 9 to the servo object 
} 
 
 
void loop() 
{ 
  if(Serial.available() )
  {;}
  
  value = Serial.read();
  

  if ( value == 'a')       // as long as a send `a` the motor will turn left. 4 degree in every step                         
  {
  myservo.write(pos);
    pos=pos-2;
    Serial.println("left");
    Serial.println(pos);
  }
                                
   if ( value == 'd')      // as long as a send `d` the motor will turn right. 4 degree in every step                        
  {
  myservo.write(pos);
    pos=pos+2;
    Serial.println("right");
    Serial.println(pos);
  }
   
   if ( value == 'w')      // as long as a send `d` the motor will turn backwards.                       
  {
                  digitalWrite(13, LOW); // Set direction as backwards
                   analogWrite(10, 255);
  }
   if ( value == 's')      // as long as a send `s` the motor will turn Forward.                     
  {
                  digitalWrite(13, HIGH); // Set direction as Forward
                   analogWrite(10, 255);
  }
  if ( value == 'q')      // as long as a send `d` the motor will turn right. 4 degree in every step                        
  {
                  digitalWrite(13, HIGH); // Set direction as backwards
                   analogWrite(10, 0);
  }
   if (pos <=  70 || pos >= 120 )
   {
     Serial.println("DANGER");
   }




}

You are using servo library, which is based on Timer1. PWM pins 9 and 10 also controled by Timer1. Try to move your motor on different pins 3 / 11, or 5 / 6.

Read the Servo library reference page, particularly the bit about PWM on pins 9 and 10

THANK YOU VERY MUCH magician AND awol !

thats it :) I would have never been on it.