Multiple Dual VNH5019 Motor Driver Shields

Hello,

I’m interested in using three Pololu Dual VNH5019 Motor Driver Shield for Arduino (https://www.pololu.com/catalog/product/2502) to run 6 motors. I do not plan on stacking them as actual shields. My arduino is a duemilanove ATMega328.

I have already purchased one shield and have been successful in running two motors, controlling their speed based upon feedback from a proximity sensor I am using. I do not need individual direction control for each motor from the arduino, as they will all always be moving forward. I also will not be using any of the feedback from the driver.

My general plan is to add to the existing library (http://github.com/pololu/Dual-VNH5019-Motor-Shield) for this shield to add commands for motors 3 through 6. I’ll provide direction control to each of the motors from the default pins for motor 1 on the arduino, pins 2 and 4.

As a first proof of concept for myself, I’ve attempted to modify the library to remap the speed control for motor 1 from pin 9 to pin 10. (The library warns specifically against this, I guess I’m just a fool rebel.)

I believe there are only two portions of the library I need to change, one in the header and one in the main body file. Is this correct?

Here’s the first bit, from the header:

private:
    unsigned char _INA1;
    unsigned char _INB1;
    static const unsigned char _PWM1 = 9; // NEED TO CHANGE THIS LINE TO 10

The second part is what I think is giving me trouble. From the comments I learned that the default pins are on timer1. From my reading I’ve learned that the arduino has 3 timers, with different clock speeds. But I can’t figure out how to modify the following few lines to be able to use pin 10 for speed control of motor 1. How do I do this?

  #if defined(__AVR_ATmega168__)|| defined(__AVR_ATmega328P__)
  // 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

Help would be greatly, greatly appreciated, and rewarded with a beer if you come to Boston!

EDIT: I just realized that pin 10 also uses timer1, but the same question still applies, as I want to use all of the arduino PWM outputs.

P.S. Thank you to Pololu for the awesome user guide, it persuaded me to purchase the driver from you even though I suspect that equally capable drivers could be had for less.

Hello.

The library handles PWM generation in a somewhat complicated way in order to produce a 20 kHz PWM frequency from timer 1. The benefit of this is that it is ultrasonic, so you cannot hear the PWM-induced motor whine at this frequency. Unfortunately, the Arduino’s two other timers are not practically capable of this: timer 0 is used for the system clock, so you can only use it to generate PWMs with a frequency of 1 kHz, and timer 2, as an 8-bit timer, can only get 100 speeds in each direction at 20 kHz.

I can help you with the code if you really want to get a 20 kHz PWM from timer 2, but I suggest you just take the easy route and use Arduino’s built in analogWrite() function to get your PWMs on the desired pins.

- Ben

Edit:

I’m very happy to hear that you like the user’s guide! If you mean that these drivers might be overkill for your project and you might have been able to get lower-power ones for less, that is certainly possible. However, I’m not aware of anything else as capable as the VNH5019 available for less. Did you have any other specific drivers you were considering?