DC motor control with TM4C123. Each board controls 2 motors independently and can talk to other boards
Switch branches/tags
Nothing to show
Clone or download
Latest commit 06c7246 May 28, 2018
Failed to load latest commit information.
Examples Added example code May 27, 2018
TIVA code doc update May 28, 2018
.gitignore doc update May 28, 2018
LICENSE Initial commit May 5, 2018
README.md doc update May 28, 2018



DC motor control with TM4C123. Each board controls 2 motors independently and can talk to other boards

Use Cases

  • A base module for a differential drive robot.
  • SCARA-like robot (combine two modules).


  • TM4C123 MCU
  • TB6612FNG motor controller
  • 2 channel encoder interface
  • 2 channel 1A continuous, 1.3A max
  • CAN Bus interface
  • UART interface
  • PID control library

PID control library

The PID control library incorporates the use of an autotuning mechanism using the Nelder-Mead method whereby it searches through R3 space using a simplex model to reduce the scoring function, which in this case is the time it takes to settle.

There are some drawbacks using the Nelder-Mead method because the quality of the search depends on the initial values.

Modifiable Values

The modifiable values for the PID control library are:

  • gen_algo.c->testArray ~ This array stores 4 initial points (P,I,D) to search
  • gen_algo.h->TEST_PERIOD ~ This value is the length of time in cycles to measure the PID response
  • motor.h->MAX_PWM ~ the maximum PWM counts. The range of PWM is from 0 to this value
  • motor.h->TIME_TO_COUNT ~ the time to count the velocity. The encoder interface will wait this length of time to determine the velocity

Useful Function Descriptions


  • absolute_to_relative: takes a value from an absolute sensor (orientation/counts) and converts it to a relative value.
  • pid_controller: takes a sensed value and attempts to match it with a given desired value. Includes testing and autotuning algorithms.
  • pid_autotune: auto-tunes the PID values.


  • setSpeed: sets the speed of the motor based on the pwm counts given.
  • getMotorXCounts: gets the counts from the encoder interface, note that absolute_to_relative function is already applied here
  • getMotorXVelocity: gets the velocity in counts/time from the QEI interface
  • zeroMotorX: zeros the motors and the relative counts


  • initAll: calls all the configuration options


  • uartRead: given a char pointer and length to read, reads from UART
  • uartWrite: writes from a char pointer

Known Problems

  • CAN bus interface not fully implemented yet