Go Down

Topic: 2A Dual Motor Controller + PWM Problem (Read 792 times) previous topic - next topic

Hi,

i have this Motor Controller from DFRobot

http://www.dfrobot.com/index.php?route=product/product&path=51_105&product_id=66#.UVVjrqPQiE8


PWM Value from 0-127 didn't work (LEDs didn't showing)
PWM Value from 128-255 works fine, but running same fast.

How did it?

Here the code.
Code: [Select]

int E1 = 13;                       
int M1 = 12;                       
int E2 = 11;
int M2 = 10;
   
   
void setup()
{
    pinMode(E1, OUTPUT);
    pinMode(M1, OUTPUT); 
    pinMode(E2, OUTPUT);
    pinMode(M2, OUTPUT);
    Serial.begin(9600);
}

void loop()
{
  int value;
  char val;
  while(1)
  {
    val=Serial.read();
    if(val!=-1)
    {
      switch(val)
      {
        case '1': value=100;  //<------------- PWM didn't work, Motor not running!!!!!!
        break;
       
        case '2': value=255;
        break;
       
        case 's'://stop
        digitalWrite(M1, LOW);
        digitalWrite(E1, LOW); //<------------- Motor Speed
        digitalWrite(M2, LOW);
        digitalWrite(E2, LOW);
        break;
       

        case 'q'://Forward left
        digitalWrite(M1, HIGH);
        analogWrite(E1, value); //<------------- Motor Speed
        digitalWrite(M2, LOW);
        digitalWrite(E2, HIGH);
        break;
                   
        case 'w'://Forward
        digitalWrite(M1, HIGH);
        analogWrite(E1, value); //<------------- Motor Speed
        digitalWrite(M2, LOW);
        digitalWrite(E2, LOW);
        break;
               
        case 'e'://Forward right
        digitalWrite(M1, HIGH);
        analogWrite(E1, value); //<------------- Motor Speed
        digitalWrite(M2, HIGH);
        digitalWrite(E2, HIGH);
        break;
                           
        case 'y'://Backward left
        digitalWrite(M1, LOW);
        analogWrite(E1, value); //<------------- Motor Speed
        digitalWrite(M2, LOW);
        digitalWrite(E2, HIGH);
        break;
                               
        case 'x'://Backward
        digitalWrite(M1, LOW);
        analogWrite(E1, value); //<------------- Motor Speed
        digitalWrite(M2, LOW);
        digitalWrite(E2, LOW);
        break;
                       
        case 'c':// Backward right
        digitalWrite(M1, LOW);
        analogWrite(E1, value); //<------------- Motor Speed
        digitalWrite(M2, HIGH);
        digitalWrite(E2, HIGH);
        break;
      }
    }
  }





http://www.christian-elektronik.de/
I'm deaf.

www.christian-elektronik.de

JimboZA

For PWM you need to analog write the Enable (E1 (13) , E2 (11)) pins, not digital write... But pin 13 isn't a PWM pin in the first place.

Check the sample code at the site you linked.
Arduino ethernet server here.... http://jimboza.gotdns.com:8085/

No PMs for help please

MarkT

The PWM pins are marked with a printed "~" on the board.  analogWrite on a non-PWM pins acts just as you've described.
[ I won't respond to messages, use the forum please ]

Go Up