Tuesday 24 April 2018

Controlling DC motors with the TB6612FNG

I bought this H-bridge module containing the TB6612FNG chip (datasheet)

It is an interesting chip.

Points to note:

Tie the standby pin high

Otherwise you're going nowhere. It was not clear that there is no internal pull-up in the standby pin - it will float low, which turns everything off. 

PWM is not what it seems

There are three input signals per channel (x2 channels). These are labelled IN1, IN2 and PWM. All is not as it seems.
 I initially assumed that if the PWM pin is low, it would drive the output high-impedence (open-circuit) to allow a motor to run freely. This is not the case.

The free-running setting is actually PWM=high, IN1, IN2 = low.

This means, that when we drive it with a pulse-width modulation duty cycle, we don't want to be pulsing the PWM pin (which is counter-inutitve).

To drive in either direction, set PWM=high, and one of the inputs high, the other low.
To drive with <100 high="" in1="" in2="" leaving="" low.="" one="" or="" other="" p="" power="" pulse="" the="">
To activate the brake, set PWM=low, and the value of the other signals doesn't seem to matter.
To leave it free-running, set PWM=high and the other inputs low.

 We could pulse the PWM signal, but that would be activating the brake during the off duty-cycle.

 Raspberry Pi - some GPIO outputs are high on boot

A surprise to me was that on the Pi, some of the GPIO pins (not many) are high on boot. It is a (somewhat) documented behaviour. I didn't know about that, so I've managed to wire up the robot so that one of the motors runs on boot. This is undesirable as it means the robot tries to drive away while we connect the battery.

(NB: GPIO 7 is high on boot)

It's possible, however, to make it go low very early during the boot process. It seems that this is approximately 1 second after power-on on my Zero W.

It may be that there is a weak pull-up enabled at boot, and I could fix it by installing a resistor to provide a stronger "pull down", and still allow the pin to be high when I want it high.

No comments: