A simple language and parser to control the TLE94112EL Arduino Shield.

Part 2

In the first part we introduced the software and architecture of the TLE94112EL Arduino shield platform. In this second article we see how the software works, and how users can customize the software. The software repository is available on GitHub []. Thanks to Farnell Element14 [] for sponsoring the Infineon board.

This video shows the usage and testing of the hardware platform used to run the software controlled by a serial terminal over a smartphone


MotorControl class

This is the hardware control class and the core of the application, inheriting the TLE94112 Arduino library, with its related motorcontrol.h header file. Details on how to use the Arduino library provided by Infineon, as well as the installation instructions, can be found on GitHub [].

void MotorControl::begin(void) {

// enable tle94112




void MotorControl::end(void) {




When the class is instantiated by the sketch the begin() method creates its own instance of the low-level hardware library. This avoids separately instantiating the external library classes by the main application. The Infineon TLE94112 library controls the shield IC, as well as the registers status, and the SPI communication with the micro controller. The sketch only needs to access the MotorControl class APIs for full hardware control.



* All the state flags and value settings for a generic motor


struct motorStatus {

uint8_t channelPWM;     ///< PWM channel for this motor

boolean isEnabled;      ///< Motor enabled status

boolean isRunning;      ///< Motor running status (should be enabled)

boolean freeWheeling;   ///< Free wheeling active or passive

int motorDirection;     ///< Current motor direction



* PWM duty cycle settings. All motors using the same

* PWM channel will be affected by the same settings


struct pwmStatus {

boolean useRamp;        ///< Use acceleration/deceleration cycle when starting

uint8_t minDC;          ///< Min duty cycle value

uint8_t maxDC;          ///< Max duty cycle value

boolean manDC;          ///< Manual duty cycle flag


The motorcontrol.h header file defines two global structures, pwmStatus and motorstatus containing the updated values and flags available to the application. These are used by the sketch loop() and parser() function, depending on the user interaction.

There are two kinds of methods; reset(), resetHB(), resetPWM(), to control the shield. These methods are public, but are mostly used by the other MotorControl class APIs.

The second API group provides higher level methods to setup and execute the user commands:


  • setPWM(uint8_t pwmCh) Set the desired PWM channel for current motor or for all.
  • setMotorDirection(int dir) Set the desired direction for the selected motor (or all)
  • setPWMRamp(boolean acc) Enable or disable the acceleration/deceleration sequence for the desired PWM channel
  • motorPWMStart(void) Start PWM channels (if configured)
  • motorPWMStop(void) Stop PWM channels (if configured)
  • motorPWMAccelerate(int channel) Run PWM channels with an acceleration cycle
  • motorPWMDecelerate(int channel) Halt PWM channels with a deceleration cycle
  • motorPWMAnalogDC(void) Change the current duty cicle value through acceleration/deceleration for the PWM channels that has set the manual duty cycle
  • motorPWMRun(int channel) Run PWM channel immediately setting the max duty cycle
  • setMotorFreeWheeling(boolean fw) Enable or disable the freewheeling flag
  • setPWMManualDC(boolean dc) Set the state flag for duty cycle mode. If set to manual the target value (max) is read from the analog input (pot) else it is set following the internal parameters values.
  • setPWMMinDC(uint8_t dc) Assign a user defined value as min duty cycle. This method applies to any of the three available PWM channels
  • setPWMMaxDC(uint8_t dc) Assign a user defined value as Max duty cycle. This method applies to any of the three available PWM channels
  • startMotors() Start all enabled motors
  • stopMotors() Stop all enabled motors
  • motorConfigHB(void) Configure the half bridges of all the motors
  • motorConfigHB(int motor) Configure the half bridges of the specified motor
  • motorConfigHBCW(int motor) Configure the half bridges of the specified motor, clockwise direction
  • motorConfigHBCCW(int motor) Configure the half bridges of the specified motor, counter clockwise direction
  • motorStopHB(void) Stop all running motors
  • motorStopHB(int motor) Stop the specified motor
  • showInfo(void) Send current motors configuration and PWM settings on two tables to the serial terminal
  • tleCheckDiagnostic(void) Check if an error occurred
  • tleDiagnostic(void) Check the error condition and detect the kind of error (if any) then reset it
  • tleDiagnostic(int motor) Check the error condition and detect the kind of error (if any) then reset it
  • tleDiagnostic(int motor, String message) Check the error conditions and detect the kind of error (if any) then reset it

The platform configuration status tables shown on the serial terminal. Errors strings and tables are defined in the motor.h header file


In the third and last part we will discuss using the parser command and syntax to control the shield.



No Comments

Join the conversation!

Error! Please fill all fields.
Looking for the latest from TI?