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.
1
#include <Turta_MotorDriver.h>
Copied!
Then, create an instance of the Turta_MotorDriver class.
1
Turta_MotorDriver md
Copied!
Now you're ready to access the library by calling the md instance.

Initialization

To initialize the module, call the begin method.
1
begin()
Copied!
This method configures the GPIO pins to control motors.

Basic Members

Driver Motors

Drives the motors in desired speed and directions.
1
void driveMotors(int16_t leftSpeed, int16_t rightSpeed)
Copied!
  • 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.
1
void coastMotors()
Copied!
  • Parameters
    • None.
  • Returns
    • None.

Brake Motors

Brakes the motors.
1
void brakeMotors()
Copied!
  • 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. 1.
    Open the Motor Driver Demo sketch from the examples menu.
  2. 2.
    Select your Arduino MKR series board from the Tools > Board menu.
  3. 3.
    Select your device's COM port from Tools > Port menu.
  4. 4.
    Upload the code to your device.
Sample Code
Motor_Driver_Demo.ino
1
#include <Turta_MotorDriver.h>
2
3
// Create Motor Driver instance
4
Turta_MotorDriver md;
5
6
void setup() {
7
// Initialize Motor Driver
8
md.begin();
9
}
10
11
void loop() {
12
// Increase motor speed from coast to maximum forward
13
for (short i = 0; i < 255; i++) {
14
md.driveMotors(i, i);
15
delay(10);
16
}
17
18
// Set motor speed to maximum forward
19
md.driveMotors(255, 255);
20
delay(2000);
21
22
// Decrease motor speed from maximum forward to coast
23
for (short i = 255; i > 0; i--) {
24
md.driveMotors(i, i);
25
delay(10);
26
}
27
28
// Coast motors
29
md.driveMotors(0, 0);
30
delay(2000);
31
32
// Set motor speed to half reverse
33
md.driveMotors(-128, -128);
34
delay(2000);
35
36
// Set motor speed to maximum reverse
37
md.driveMotors(-255, -255);
38
delay(2000);
39
40
// Set motor speed to half reverse
41
md.driveMotors(-128, -128);
42
delay(2000);
43
44
// Short brake motors
45
md.brakeMotors();
46
delay(2000);
47
}
Copied!
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.
Last modified 2yr ago