Motor Driver
Click images to expand
The PCA9635 chip was designed to control LED brightness using a fairly high pwm signal (97 kHz). Since this is well above normal human hearing range, this makes it very well suited for interfacing with the L298N motor driver without having any unwanted sound effects. The L298H can accept a PWM signal which will affect the high voltage side of the chip and effectively deliver an average voltage between 0 and 100% of said high voltage (Vs), that is directly proportional to the duty cycle of your PCA9635 duty cycle output. Note also that the pca9635 can be set to "digital mode" where the output is either high or low without a pwm signal whatsoever. This is also needed for the L298N since it has input pins designed to control the polarity of the high voltage side and those pins are digital.
Note that it is possible to use pin 18 on the Raspberry Pi header to output a hardware PWM signal which does work and can control the L298N (after logic level conversion), however, pin 18 can only control 1 train wheras the PCA9635 can control several. Also, pin 18 can be used for RGB LED's, so I would prefer to reserve pin 18 for that purpose.
Basic instructions:
Hardware:
L298N [click here]
PCA9635 LED/Motor driver [click here]
TSSOP28 Breakout [click here]
Header Pins [click here]
TXS0108e [click here]
Power Supply [click here]
PSU Connector [click here]
Review datasheets:
L298N datasheet [click here]
PCA9635 datasheet [click here]
TXS0108e datasheet [click here]
Power considerations:
I only run 12v as that is what the engine motors are rated for. I know some people like to overdrive it at 16 or even 19v, which the L298N supports, however, you would need to remove a jumper. Review these notes from the Amazon webpage:
To avoid damage the voltage stabilizing chip, please use an external 5V logic supply when using more than 12V driving voltage
Unconventional application of high-voltage drive: When the driving voltage is higher than 12V, less than or equal to 24V, for example, to drive a motor with rated voltage of 18V, the jumper cap with 5V output enabled on-board voltage must be pulled out and then outside the 5V output port Connect 5V voltage to L298N internal logic voltage supply
We believe they are referring to jumper con5, see photo [click here]
In order to use the L298N board with the PCA9635 IC, you will need to remove jumpers ENA and ENB as those pins are the PWM input override jumpers, see photo [click here]. The “back” pin is constant 5v, which is what you are disabling when removing the jumpers ENA & ENB, and therefore allowing the front pin to be controlled by the PC9635 PWM signal.
Use the schematic to wire together the electronic parts. [click here] We recommend downloading the image and then opening it with your favorite picture viewer.
txs0108e logic level converter:
OE pin: Low=disabled; High=enabled
Yes we know the 1k resistor looks weird. It is recommended in the datasheet to avoid unknown state behavior when turning the system on. Since we're attaching the OE pin to the RPi, it may not be necessary, but it would take some digging to find out how the RPi GPIO pins are configured and so it's easier just to add it. AKA, we don't know if the initial state of the RPi pins are open or drain. If they're open, then the resistor is necessary.
Software: [click here]
There's a utility program in the driver examples, but it does not control the OE pin on the txs0108e, so you'll need to set it manually before running the utility program.