Author Topic: cant control speed of motor driver  (Read 694 times)

0 Members and 1 Guest are viewing this topic.

Offline beesnutsTopic starter

  • Newbie
  • Posts: 1
  • Country: th
cant control speed of motor driver
« on: August 20, 2018, 03:04:52 pm »
I'm connecting Tb-6612FNG (motor driver) with arduino mega 2560 R3

The problem is I can't control speed of my motor with analogWrite.
motor speed between 0-119 motor will not working.It will working on 120-255 but not matter how much is it.It will usually run at the same speed

my code\\
int STBY = 22; //standby

//Motor A
int PWMA = 30; //Speed control
int AIN1 = 34; //Direction
int AIN2 = 32; //Direction

//Motor B
int PWMB = 42; //Speed control
int BIN1 = 40; //Direction
int BIN2 = 44; //Direction

void stop(){
//enable standby
digitalWrite(STBY, LOW);
}

void move(int motor, int speed, int direction){
//Move specific motor at speed and direction
//motor: 0 for B 1 for A
//speed: 0 is off, and 255 is full speed
//direction: 0 clockwise, 1 counter-clockwise

digitalWrite(STBY, HIGH); //disable standby

boolean inPin1 = LOW;
boolean inPin2 = HIGH;

if(direction == 1){
inPin1 = HIGH;
inPin2 = LOW;
}

if(motor == 1){
digitalWrite(AIN1, inPin1);
digitalWrite(AIN2, inPin2);
analogWrite(PWMA, speed);
}else{
digitalWrite(BIN1, inPin1);
digitalWrite(BIN2, inPin2);
analogWrite(PWMB, speed);
}
}

void setup(){
pinMode(STBY, OUTPUT);

pinMode(PWMA, OUTPUT);
pinMode(AIN1, OUTPUT);
pinMode(AIN2, OUTPUT);

pinMode(PWMB, OUTPUT);
pinMode(BIN1, OUTPUT);
pinMode(BIN2, OUTPUT);
stop();
delay(5000);
}

void loop(){
move(1, 255, 1); //motor 1, full speed, left
move(2, 255, 1); //motor 2, full speed, left

delay(1000); //go for 1 second
stop(); //stop
delay(250); //hold for 250ms until move again

move(1, 100, 0); //motor 1, half speed, right
move(2, 100, 0); //motor 2, half speed, right

delay(1000);
stop();
delay(250);
}




 

Offline JS

  • Frequent Contributor
  • **
  • Posts: 947
  • Country: ar
Re: cant control speed of motor driver
« Reply #1 on: August 20, 2018, 04:07:42 pm »
What kind of motor are you using?

It looks like you should stop the PWM generators in the stop function or the motors will start running at the speed they were, even the motor that is not supposed to turn.

The PWM freq might be too slow, if you can try setting up (with registers) the PWM to run faster with less bits, or use a pwm genrrator from another source to test it.

JS

If I don't know how it works, I prefer not to turn it on.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf