PWM for motor driver

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
christian.prosser
Posts: 5
Joined: Thu Nov 06, 2014 10:33 pm

PWM for motor driver

Post by christian.prosser » Tue Feb 24, 2015 11:55 pm

Hi All,

I'm trying to write a module for the SparkFun Motor Driver TB6612FNG
I'm struggling to understand how to use the PWM features of the TimerChannel and would appreciate any help I can get.
I'm not sure what to set the freq and pulse_width to, the datasheet mentions a max 100 kHz frequency on the PWM pins but I'm not sure how use that fact.
Once the channel is configured, is the timer.pulse_width_percent the correct way to vary the motor speed?

I've read the following pages but I'm still confused
http://micropython.org/doc/module/pyb/Timer
http://docs.micropython.org/en/latest/l ... #pyb-timer
http://wiki.micropython.org/platforms/b ... r-Examples

Thanks for your help,
Chris

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: PWM for motor driver

Post by dhylands » Wed Feb 25, 2015 2:06 am

What frequency you use depends a bit on the motor as well as the PWM controller.

Personally, I try to use a frequency above 20 kHZ so that the motor whine is out of the audible range.

Looking at the datasheet, you'll need to pull STBY high, and then use the table on page 4 of the datasheet to set direction.

You'll use the PWM to toggle between CCW/short brake and CW/short brake. So use IN1/IN2 to control the direction/braking and the PWM to control the speed.

Setting channel.pulse_width_percent to zero should correspond to zero speed, and setting pulse_width_percent to 75 should correspond to 75% speed.

You should try to use 2 channels on the same timer, one channel for each motor. That way the PWM cycles will be synchronized. I'd also recommend using one of the center aligned modes. This will effectively divide the frequency in half.

Post Reply