Pages: [1]   Go Down
Author Topic: 2A Dual Motor Controller + PWM Problem  (Read 611 times)
0 Members and 1 Guest are viewing this topic.
Germany
Offline Offline
Jr. Member
**
Karma: 1
Posts: 55
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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/
Logged


Johannesburg UTC+2
Offline Offline
Faraday Member
**
Karma: 60
Posts: 3242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Have you looked for answers in the Learning, Reference, Products and Playground tabs on http://arduino.cc/en/ ?
Look here http://electronicsclub.info/ for basic electronics

0
Offline Offline
Shannon Member
****
Karma: 161
Posts: 10442
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The PWM pins are marked with a printed "~" on the board.  analogWrite on a non-PWM pins acts just as you've described.
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: