Motor Driver

This documentation includes installation guidelines and sample code for your hardware.

Overall Info

The TC78H630FNG is H-bridge driver IC for DC motors.

Driver Connections

  • Left Motor Driver

    • nStand By: D1

    • Forward PWM: D3

    • Reverse PWM: D2

  • Right Motor Driver

    • nStand By: D0

    • Forward PWM: D5

    • Reverse PWM: D4

  • Power

    • Logic: VCC (+3.3V) and GND.

    • Motor: Motor In and GND.

Specifications

TC78H630FNG's technical specifications are as follows:

  • Input Voltage: 15V Max.

  • Output Current: 1.6A Max.

  • Control Logic Frequency: 500kHz Max.

Arduino Library

Turta_MotorDriver library is responsible for controlling the motor drivers.

To use the library on Arduino IDE, add the following #include statement to the top of your sketch.

#include <Turta_MotorDriver.h>

Then, create an instance of the Turta_MotorDriver class.

Turta_MotorDriver md

Now you're ready to access the library by calling the md instance.

Initialization

To initialize the module, call the begin method.

begin()

This method configures the GPIO pins to control motors.

Basic Members

Driver Motors

Drives the motors in desired speed and directions.

void driveMotors(int16_t leftSpeed, int16_t rightSpeed)
  • Parameters

    • int16_t leftSpeed: Left motor speed. -255 to 255. 0 is coast.

    • int16_t rightSpeed: Right motor speed. -255 to 255. 0 is coast.

  • Returns

    • None.

Coast Motors

Coasts (stops) the motors without braking.

void coastMotors()
  • Parameters

    • None.

  • Returns

    • None.

Brake Motors

Brakes the motors.

void brakeMotors()
  • Parameters

    • None.

  • Returns

    • None.

Examples

You can open the example from Arduino IDE > File > Examples > Examples from Custom Libraries > Turta MKR Motor Shield. There is one example of this sensor.

Motor Driver Demo

This application demonstrates motor control capabilities of the drivers.

To run the example:

  1. Open the Motor Driver Demo sketch from the examples menu.

  2. Select your Arduino MKR series board from the Tools > Board menu.

  3. Select your device's COM port from Tools > Port menu.

  4. Upload the code to your device.

Sample Code

Motor_Driver_Demo.ino
#include <Turta_MotorDriver.h>
// Create Motor Driver instance
Turta_MotorDriver md;
void setup() {
// Initialize Motor Driver
md.begin();
}
void loop() {
// Increase motor speed from coast to maximum forward
for (short i = 0; i < 255; i++) {
md.driveMotors(i, i);
delay(10);
}
// Set motor speed to maximum forward
md.driveMotors(255, 255);
delay(2000);
// Decrease motor speed from maximum forward to coast
for (short i = 255; i > 0; i--) {
md.driveMotors(i, i);
delay(10);
}
// Coast motors
md.driveMotors(0, 0);
delay(2000);
// Set motor speed to half reverse
md.driveMotors(-128, -128);
delay(2000);
// Set motor speed to maximum reverse
md.driveMotors(-255, -255);
delay(2000);
// Set motor speed to half reverse
md.driveMotors(-128, -128);
delay(2000);
// Short brake motors
md.brakeMotors();
delay(2000);
}

Result

After the application is uploaded to the device, it demonstrates different motor speed and directions.

The application runs forever until you clear it from memory.