Well...it's me again, trying to figure it out. I cannot get my motor driver to reverse the motor. It kills the voltage.
Here is what I have:
*Arduino UNO
*Toshiba TB67H420FTG mounted on Pololu's module, found here. And this is the specific datasheet.
*9 volt battery for motor power (currently 6 AA batteries in series)
*small DC motor from a starter kit.
*3 buttons to control it.
--One to enable/disable the motor. Push to enable, release to disable.
--One for direction control. Push for clockwise, release for counter clockwise.
--One for speed control. Push for analog write full speed, release for analog write slow speed.
Here is what I want to happen:
*After startup, push and hold enable button to enable motor in whichever direction the direction button is held or released in, CW or CCW. While the enable button is held and the direction button is held or released, push the speed button for fast speed or release it for slow speed. So all of these buttons are not push once and it stays in that mode, but push it and while it's held do something or release it and while it's released do something different.
Here is what is happening:
*According to the serial prints, the buttons ARE working, or registering HIGH and LOW. So I know the arduino is getting the command from the buttons.
*The enable button does indeed enable while pushed and disable while released.
*The speed button does indeed do slow speed while released and fast while pushed.
*The problem here is the direction button. Everything works flawless in one direction but when I try to reverse the direction, it all stops. I removed the motor and used the multimeter in it's place. It showed that the voltage drops when the direction is changed.
*In CW mode, the slow and fast voltages are .94 and 1.49 while enabled.
*But while enabled and in CCW mode the voltages are correct. Slow is -5 and fast is -8.6.
*And while disabled, all voltages are 0, as it should be.
I want to post some pics and code and was hoping someone show me where I am going wrong. It has to be something simple.
The driver is set up for dual motor, even though I am just controlling one motor for now. I figured that it is no different than hooking up two motors but only telling one of them what to do. Correct me if I am way off base here...
I have the code split into multiple tabs in my ide, but I will get it all posted here. Here is the main code:
//CONTROL MOTOR WITH POLOLU TB67H420FTG MOTOR DRIVER
//For dual or single motors
/*-----FORMULAS----------------------------------------------
---Current sensing---Per Toshiba TB67H420FTG datasheet pg13
---NEEDS MORE RESEARCH TO CONTROL CURRENT!!!
If HBMODE == HIGH (Driver is in single channel mode)
Iout=Vref * 2.5
If HBMODE == LOW (Driver is in dual channel mode)
motorA current = Iout=Vref * 1.25
motorB current = Iout=Vref * 1.25
*/
/*-----Wiring------------------------------------------------
---Power to board is supplied via 10V to 47V VIN pin.
---GROUND THE BOARD!
*/
// Declare other .ino tab codes
void motor1Stop();
void motor1CW();
void motor1CCW();
void motor2Stop();
void motor2CW();
void motor2CCW();
//-----DEFINES-----------------------------------------------
//Button inputs
#define PUSHED LOW
#define RELEASED HIGH
//Motor Speed
#define FAST 255
#define SLOW 150
//-----PIN ASSIGNMENTS---------------------------------------
//Motor control
const int motor1SpeedPin = 9; // Primary PWM pin
const int motor2SpeedPin = 10; //Secondary PWM pin
int motorSpeed; //Two choices, FAST or SLOW
const int motor1CWPin = 3; //Direction control motor1
const int motor1CCWPin = 2; // Direction control motor2
const int motor2CWPin = 5; //Direction control motor2
const int motor2CCWPin = 6; //Direction control motor2
//Buttons/Switches
const int enableButtonPin = 7; // Motor enable button
const int directionButtonPin = 11; // Direction control button
const int motorSpeedPin = 12; //push button for fast speed, release for slow speed
//Current sensing pins---Writes data TO the motor controller.
const int motor1Sensor = A0; //Write analog voltage to VrefA
const int motor2Sensor = A1; //Write analog voltage to VrefB
//-----MOTOR DRIVER SETUP--------------------------------------
const int HBMODE = 13; //In SETUP, set to HIGH for single motor, LOW for dual motor
bool isSingle = true; //Is driver in single or dual mode?
//-----TIMERS---------------------------------------------------
unsigned long lastCheckTime = 0; //Check debounce timers
const int debounceDelay = 50; //50 mS debounce delay
unsigned long lastSpeedTime = 0; //Keep track of speed button
unsigned long lastEnableTime = 0; //Keep track of enable button
unsigned long lastDirectionTime = 0; //Keep track of direction button
//-----BOOLEANS-------------------------------------------------
bool isEnabled = true; //Is the enable button pushed?
//bool isDisabled = false; //Is the enable button released? Probably not needed. I can assume if it is not enabled, it is disabled.
bool isCW = false; //Is the direction button pushed?
//bool isCCW = true; //Is the direction button pushed? Probably not needed. I can assume if it is not CW, it is CCW.
//---E N D O F V A R I A B L E S-------------------------------
void setup() {
Serial.begin(9600);
// Motor control pin modes
pinMode(motor1SpeedPin, OUTPUT);
pinMode(motor2SpeedPin, OUTPUT);
pinMode(motor1CWPin, OUTPUT);
pinMode(motor1CCWPin, OUTPUT);
pinMode(motor2CWPin, OUTPUT);
pinMode(motor2CCWPin, OUTPUT);
// Button control pin modes
pinMode(enableButtonPin, INPUT_PULLUP); //digital read LOW (PUSHED) to enable
pinMode(directionButtonPin, INPUT_PULLUP); //digital read LOW (PUSHED) for CCW and HIGH (RELEASED) for CW
pinMode(motorSpeedPin, INPUT_PULLUP); //digital read LOW (PUSHED) for FAST speed and HIGH (RELEASED) for SLOW speed
// Start with motor off
analogWrite(motor1SpeedPin, 0);
analogWrite(motor2SpeedPin, 0);
// Setup HBMODE for single or dual motor.
//IF CHANGING # OF MOTORS, change HIGH to LOW and change isSingle to false.
pinMode(HBMODE, OUTPUT);
digitalWrite(HBMODE, LOW); //Change to LOW for dual motor, HIGH for single motor with extra current
isSingle = false; //Change to false for dual motor, true for single configuration
// Setup Booleans
isEnabled = false; //Start program with button released
isCW = true; //Start program with button released
}//---E N D O F S E T U P-----------------------------------------
void loop() {
//---CHECK MOTOR SPEED BUTTON-----
if (millis() - lastSpeedTime >= debounceDelay){ //Debounce timing
if (digitalRead(motorSpeedPin) == PUSHED){ //Is button pushed?
motorSpeed = FAST; //Run motor(s) fast
lastSpeedTime = millis(); //Reset timer
}
else { //Is button released?
motorSpeed = SLOW; //Run motor(s) slow
lastSpeedTime = millis();
}
}
//---CHECK ENABLE BUTTON-----
if (millis() - lastEnableTime >= debounceDelay){ //Debounce timing
if (digitalRead(enableButtonPin) == PUSHED){ //Is button pushed?
isEnabled = true; //Set enabled
lastEnableTime = millis(); //Reset timer
}
else{ //Is button released?
isEnabled = false; //Set disabled
lastEnableTime = millis(); //Reset timer
}
}
//---CHECK DIRECTION BUTTON-----
if (millis() - lastDirectionTime >= debounceDelay){ //Debounce timing
if (digitalRead(directionButtonPin) == PUSHED){ //Is button pushed?
isCW = false; //If pushed, set for CCW
lastDirectionTime = millis(); //Reset timer
}
else{ //Is button released?
isCW = true; //If released, set for CW
lastDirectionTime = millis(); //Reset timer
}
}
//---DISABLE MOTOR(S)-----
if (isEnabled == false){ //Is enable button released?
motor1Stop();
motor2Stop();
}
//---RUN MOTOR(S)-----
if (isEnabled == true){ //Is enable button pushed?
analogWrite(motor1SpeedPin, motorSpeed); //turn on motor1
analogWrite(motor2SpeedPin, motorSpeed); //turn on motor2
if(isCW == true){ //Is direction button released?
motor1CW();
motor2CW();
}
else { //Is direction button pushed?
motor1CCW();
motor2CCW();
}
}
/*Serial.print("EnButton= ");
Serial.print(digitalRead(enableButtonPin));
Serial.print(" SpeedButton= ");
Serial.print(digitalRead(motorSpeedPin));
Serial.print(" DirButton= ");
Serial.print(digitalRead(directionButtonPin));
Serial.print(" isEnabled= ");
Serial.println(isEnabled);*/
}//---E N D O F L O O P-------------------------------------------
Here is the motor control code:
void motor1CW(){
digitalWrite(motor1CWPin,HIGH);
digitalWrite(motor1CCWPin,LOW);
}
void motor1CCW(){
digitalWrite(motor1CWPin,LOW);
digitalWrite(motor1CCWPin,HIGH);
}
void motor1Stop(){
analogWrite(motor1SpeedPin, 0);
digitalWrite(motor1CWPin,LOW);
digitalWrite(motor1CCWPin,LOW);
}
void motor2CW(){
digitalWrite(motor2CWPin,HIGH);
digitalWrite(motor2CCWPin,LOW);
}
void motor2CCW(){
digitalWrite(motor2CWPin,LOW);
digitalWrite(motor2CCWPin,HIGH);
}
void motor2Stop(){
analogWrite(motor2SpeedPin, 0);
digitalWrite(motor2CWPin,LOW);
digitalWrite(motor2CCWPin,LOW);
}
Here are some pics of wiring and my hand drawn "schematic":
Any ideas? I know someone will see something I am missing. Thanks.







