Using DRV8835 Dual Motor Driver on 8Mhz Arduino

I would love to use these boards on a 3.3v system.
I tried hooking it to a 8MHz Pro Mini but get erratic results and dont get the full duty cycle with the library.

Looking at the library it seems that its written specifically for 16Mhz processors

Is there a simple fix to get it to work?

I changed it to work on
PWM pins 5 and 6
digital phase toggle on pins 3 and 4

the problem is probably here:

#ifdef DRV8835MOTORSHIELD_USE_20KHZ_PWM
// timer 1 configuration
// prescaler: clockI/O / 1
// outputs enabled
// phase-correct PWM
// top of 400
//
// PWM frequency calculation
// 16MHz / 1 (prescaler) / 2 (phase-correct) / 400 (top) = 20kHz
TCCR1A = 0b10100000;
TCCR1B = 0b00010001;
ICR1 = 400;
#endif

Any ideas?

The library should work with the ATmega168 on the Pro Mini if you use pins 9 and 10 for PWM, although the PWM frequency will actually be 10 kHz if you’re using an 8 MHz board. The code is not set up to allow the pins to change since it is written for a shield that mounts on a full sized Arduino like the Uno or Leonardo. If you would like to get 20 kHz PWM, or if you need to use different PWM pins, I can help you modify the library to do that.

-Nathan

I did change these four lines to try to get it on the 4 usable and adjacent pins on the 3v pro mini:

const unsigned char DRV8835MotorShield::_M1DIR = 3;
const unsigned char DRV8835MotorShield::_M2DIR = 4;
const unsigned char DRV8835MotorShield::_M1PWM = 5;
const unsigned char DRV8835MotorShield::_M2PWM = 6;

When I try running the motors without the library,

I get buzzing motors from 0 to 100 or so,
Then I get a fast ramp up to a speed thats about 50% of what the motors should max out at
Then as the pwm value gets higher it looses speed… drops to a stall and then ramps up again… then back down and then at about 187 rises to 50% ish… never got it to 100% with values between 0 and 255 on the analogWrite (#,#);

this is why I thought it had to do with the timer setting being for 16MHZ processors

BTW at 255 its running motors at around 10% of the max speed…

I don’t see any obvious problems with using analogWrite() to do PWM with the DRV8835. Can you post some pictures of your setup and all of your connections? What kind of motors are you using? If you have the MODE pin connected, is it pulled LOW or HIGH? Are both motors behaving the same way?

It might be helpful to step back and verify that the pin works at full on and full off. If the MODE pin is pulled low or left disconnected, you should be able to run this code to turn both motors on for 6 seconds followed by a 6 second coast:

//Set up pins
void setup() {
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
}

//Turn pin D5 (IN1) and  D6(IN2) off for 6 seconds and then on for 6 seconds 
void loop() {
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);  
  delay(6000);              
  digitalWrite(5, HIGH);    
  digitalWrite(6, HIGH);    
  delay(6000);             
}

If that works, then the hardware is probably wired correctly. You can try this to run through a sweep of different speeds:

//Set up pins
void setup() {
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
}

//Turn pin D5 (IN1) and  D6(IN2) off for 6 seconds and slowly throttle to 100% duty cycle 6 seconds 
void loop() {
  analogWrite(5, 0);
  analogWrite(6, 0);  
  delay(6000);
  analogWrite(5, 31);
  analogWrite(6, 31);  
  delay(1000); 
  analogWrite(5, 63);
  analogWrite(6, 63);  
  delay(1000); 
  analogWrite(5, 127);
  analogWrite(6, 127);  
  delay(1000); 
  analogWrite(5, 159);
  analogWrite(6, 159);  
  delay(1000); 
  analogWrite(5, 191);
  analogWrite(6, 191);  
  delay(1000);
  analogWrite(5, 255);
  analogWrite(6, 255);  
  delay(1000);    
}