What’s more satisfying than watching a robot wheel respond perfectly to your code—spinning left, pausing, then gliding right? In this protip, I use the PSOC™6 AI Kit as the main controller to drive a DC motor through a Multi half-bridge motor driver, creating a simple yet powerful demonstration of directional motor control.
The PSOC™ 6 AI Kit generates precise digital signals that control the motor’s direction by toggling transistors in the half-bridge. This isn’t just theory—you can actually see it happen in real time as the attached wheel reacts visibly to the logic: turn right, stop, turn left.
Let’s break it down together!
To control the direction of a DC motor, we use an H-bridge – a clever circuit made up of two half-bridges. Each half-bridge is composed of MOS transistors, which makes the switching more efficient and allows for integrated features like active freewheeling. Below is a simple schematic to show how that works.
Each half-bridge consists of:
- A high-side MOSFET
- A low-side MOSFET
By toggling these transistors in pairs, we can control the current direction through the motor:
- HS1 ON + LS2 PWM → Motor spins one direction
- HS2 ON + LS1 PWM → Motor spins the opposite direction
- All OFF → Motor stops
- Both high-side or both low-side ON → Short circuit! ⚠️
This setup is used in most motor drivers, including the one I used in this project. The Multi Half-Bridge (MHB) module in particular contains 12 half-bridges, giving you the flexibility to drive multiple motors or combine bridges for higher current output. The PSOC™ 6 AI Kit sends high/low signals to each input pin, turning the transistors ON or OFF to steer the motor. It’s a simple, efficient way to get full directional control using digital logic.
HardwareSchematics
First, make sure that you downloaded the PSOC™ 6 for Arduino.If not, no worries - you can check this protip:PSOC™ 6 for Arduino where it is all explained and then make sure to choose the board CY8CKIT-062S2-AI and the correct serial port.
Then install the Multi-Half-Bridge library by Infineon from the Arduino Library Manager.
Once installed, navigate to File > Examples > Multi-Half-Bridge and open the Basic Test example for your specific shield.
Now I started from this example but made a few modifications to better suit my setup and use case. In the next section, I’ll walk you through the updated code step by step and explain how everything works. Ready? Go!
#include <tle94112-ino.hpp>
#include <tle94112-motor-ino.hpp>
#include "SPI.h"
First, we import the required libraries for using the TLE94112 multi-half-bridge driver and the motor abstraction class. SPI.h
is also needed for the TLE94112 communication.
// Tle94112 Object on Shield 1
Tle94112Ino controller = Tle94112Ino(3);
This creates a controller
object for the TLE94112 chip and 3
refers to chip select pin 3, which connects the PSOC™/Arduino to the shield via SPI.
void setup()
{
pinMode(5, OUTPUT);
digitalWrite(5, HIGH);
Now we enable the motor driver through a GPIO pin 5 that we set to HIGH (ON).
Serial.begin(115200);
while (!Serial) {};
controller.begin();
We then start the serial monitor for debugging and status messages.The while (!Serial)
line waits until the serial connection is ready (useful for boards like the PSOC™ 6). and then we Initialize the TLE94112 driver through the controller.begin()
motor.initConnector(motor.HIGHSIDE, controller.TLE_NOPWM, controller.TLE_HB1, controller.TLE_HB2, controller.TLE_NOHB, controller.TLE_NOHB);
Now this sets up the high side of the motor driver using HB1 and HB2.
TLE_NOPWM
means no PWM is used here (the high side will be either ON or OFF).
motor.initConnector(motor.LOWSIDE, controller.TLE_PWM1, controller.TLE_HB3, controller.TLE_HB4, controller.TLE_NOHB, controller.TLE_NOHB);
This configures the low side with PWM1 and HB3 and HB4.
This is where PWM is applied for speed control. The low side is ideal for PWM because the high side supports freewheeling.
motor.begin();
we apply all configurations and starts the motor interface.
Serial.println("Init ready");
}
Our simple debug message to confirm that setup is complete.
void loop()
{
Serial.println("ramp transient");
Here we get a status printed to update the serial monitor
motor.rampSpeed(-255, 1000); // ramp down to min
delay(1000);
We then gradually changes motor speed to full reverse over 1000 ms.( -255
= full reverse.)
motor.rampSpeed(255, 1000); // ramp up to max
delay(1000);
This gradually changes speed to full forward.
motor.rampSpeed(-255, 1000); // ramp down to min
delay(1000);
motor.rampSpeed(0, 1000); // ramp up to 0
delay(1000);
A transitions to reverse again, then ramps back to stop.
Serial.println("stop and coast");
motor.stop(255); // stop and hold with max braking
delay(1000);
motor.coast(); // disable outputs, let motor spin freely
delay(1000);
}
stop(255)
applies a braking force (hold motor with max current).- coast() releases the motor completely—no holding, no braking.
Now you’ve got a working setup where the PSOC™ 6 and Multi Half-Bridge Driver team up to control a motor with code — and your wheel shows every move in real time.
If you're thinking about next steps: try adding a second motor, a sensor, or even experimenting with PWM frequency. And most importantly... have fun with it!
Comments
Please log in or sign up to comment.