Multi Half-Bridge  4.0.0
Library of Infineon's Multi Half-Bridge IC controllers family
TLE94112 Motor Control API
Collaboration diagram for TLE94112 Motor Control API:

Data Structures

class  Tle94112Motor
 represents a motor connected to a TLE94112 More...
 

Macros

#define TLE94112_MAX_SPEED   255
 The maximum absolute speed value which can be set. More...
 
#define TLE94112MOTOR_MAX_CONNECTORS   4
 maximum number of Tle94112 outputs per motor connector More...
 

Detailed Description


Data Structure Documentation

◆ Tle94112Motor

class Tle94112Motor

represents a motor connected to a TLE94112

This class provides a simple API for connecting and controlling motors. Each motor is assigned to a Tle94112 which acts as output driver. Calls to Tle94112Motor instances are mapped to calls to Tle94112. Therefore, this class does not bring new features, it does only provide further abstraction.

See also
Tle94112
Collaboration diagram for Tle94112Motor:

Public Types

enum  ePolarity { LOWSIDE = 0 , HIGHSIDE }
 Enum to select polarity of a motor connector. More...
 

Public Member Functions

 Tle94112Motor (Tle94112 &driver)
 Construct a new Tle94112Motor object. More...
 
 ~Tle94112Motor ()
 Destroy the Tle94112Motor object. More...
 
void begin (void)
 finishes configuration and enables motor controls More...
 
void end (void)
 disables motor controls and switches back to configuration mode More...
 
void initConnector (Tle94112Motor::ePolarity pol, Tle94112::PWMChannel channel, Tle94112::HalfBridge out1, Tle94112::HalfBridge out2, Tle94112::HalfBridge out3, Tle94112::HalfBridge out4)
 configures most important settings for one motor connector More...
 
void initConnector (Tle94112Motor::ePolarity, Tle94112::PWMChannel channel, Tle94112::PWMFreq freq, Tle94112::HalfBridge out1, Tle94112::HalfBridge out2, Tle94112::HalfBridge out3, Tle94112::HalfBridge out4)
 configures most important settings for one motor connector More...
 
void connect (Tle94112Motor::ePolarity pol, Tle94112::HalfBridge connector)
 connects a single halfbridge output to a motor connector More...
 
void disconnect (Tle94112::HalfBridge connector)
 disconnects a single halfbridge output from a motor connector More...
 
void setPwm (Tle94112Motor::ePolarity pol, Tle94112::PWMChannel channel)
 Sets the PWM channel to be used for a motor connector. More...
 
void setPwm (Tle94112Motor::ePolarity pol, Tle94112::PWMChannel channel, Tle94112::PWMFreq freq)
 Sets the PWM channel and frequency for a motor connector. More...
 
void setPwmFreq (Tle94112Motor::ePolarity pol, Tle94112::PWMFreq freq)
 Sets the PWM frequency for driving a motor connector. More...
 
void setActiveFreeWheeling (Tle94112Motor::ePolarity pol, uint8_t active_fw)
 Enables or disables active freewheeling. More...
 
void stop (uint8_t force=255)
 actively breaks the motor to stop it More...
 
void coast ()
 releases the motor without driving or active breaking More...
 
void start (int16_t speed)
 starts the motor with a certain speed in a certain direction More...
 
void setSpeed (int16_t speed)
 equivalent to start() More...
 
int16_t getSpeed (void)
 Returns the motor's current speed setting. More...
 
void rampSpeed (int16_t speed, uint16_t slope)
 function to gradually change the motors speed More...
 

Protected Types

enum  eMode { COAST , FORWARD , BACKWARD , STOP }
 enum for motor operation modes More...
 
typedef struct Tle94112Motor::Connector_tConnector_p
 

Protected Member Functions

uint32_t _measureSetSpeedDuration (int16_t speed, int16_t start_speed)
 private function needed by rampSpeed More...
 
void _performSpeedStepping (int16_t start_speed, int16_t ramp_delta_speed, int16_t num_steps, uint16_t steptime)
 private function needed by rampSpeed More...
 

Protected Attributes

Connector_t mConnectors [2]
 array of motor connectors More...
 
Tle94112mDriver
 Tle94112 instance acting as output driver. More...
 
eMode mMode
 current operation mode More...
 
uint8_t mEnabled
 flag indicating if motor controls are enabled More...
 
uint8_t mSpeed
 value of the current motor speed More...
 

Member Typedef Documentation

◆ Connector_p

Member Enumeration Documentation

◆ ePolarity

Enum to select polarity of a motor connector.

Enumerator
LOWSIDE 
HIGHSIDE 

◆ eMode

enum Tle94112Motor::eMode
protected

enum for motor operation modes

Enumerator
COAST 
FORWARD 
BACKWARD 
STOP 

Constructor & Destructor Documentation

◆ Tle94112Motor()

Tle94112Motor::Tle94112Motor ( Tle94112 driver)

Construct a new Tle94112Motor object.

After constructing, the motor must be configured. You can use functions initConnector(), connect(), disconnect(), setPwm(), setPwmFreq() and setActiveFreeWheeling() for configuration. Call begin() to finish configuration and enable motor controls.

Parameters
driverTle94112 instance acting as a driver

◆ ~Tle94112Motor()

Tle94112Motor::~Tle94112Motor ( )

Destroy the Tle94112Motor object.

Here is the call graph for this function:

Member Function Documentation

◆ begin()

void Tle94112Motor::begin ( void  )

finishes configuration and enables motor controls

For controlling the motor, you can use the functions start(), stop(), coast(), setSpeed(), getSpeed() and rampSpeed() Call end() to get back to configuration mode. After calling end() and changing configuration, you can get back to controlling mode by calling begin()

See also
end
Here is the call graph for this function:

◆ end()

void Tle94112Motor::end ( void  )

disables motor controls and switches back to configuration mode

If necessary, you can call end() and change the configuration settings at any point of time. This might be useful when sharing PWM channels between several motors. Configuration changes to motors are not allowed while controls are active! Call begin() again when the configuration changes are done to enable motor controls again.

See also
begin
Here is the call graph for this function:

◆ initConnector() [1/2]

void Tle94112Motor::initConnector ( Tle94112Motor::ePolarity  pol,
Tle94112::PWMChannel  channel,
Tle94112::HalfBridge  out1,
Tle94112::HalfBridge  out2,
Tle94112::HalfBridge  out3,
Tle94112::HalfBridge  out4 
)

configures most important settings for one motor connector

Call this function twice to setup motor configuration for both the

  • and - connector of the motor. If there is no setup for one polarity, the library assumes that the motor is constantly connected to + or -.
Parameters
polPolarity of the motor connector to be configured
channelPWM channel assigned to this connector
out1halfbridge output 1 of 4 assigned to this connector
out2halfbridge output 2 of 4 assigned to this connector
out3halfbridge output 3 of 4 assigned to this connector
out4halfbridge output 4 of 4 assigned to this connector

◆ initConnector() [2/2]

void Tle94112Motor::initConnector ( Tle94112Motor::ePolarity  pol,
Tle94112::PWMChannel  channel,
Tle94112::PWMFreq  freq,
Tle94112::HalfBridge  out1,
Tle94112::HalfBridge  out2,
Tle94112::HalfBridge  out3,
Tle94112::HalfBridge  out4 
)

configures most important settings for one motor connector

Call this function twice to setup motor configuration for both the

  • and - connector of the motor. If there is no setup for one polarity, the library assumes that the motor is constantly connected to + or -.
Parameters
polPolarity of the motor connector to be configured
channelPWM channel assigned to this connector
freqoptional PWM frequency setting
out1halfbridge output 1 of 4 assigned to this connector
out2halfbridge output 2 of 4 assigned to this connector
out3halfbridge output 3 of 4 assigned to this connector
out4halfbridge output 4 of 4 assigned to this connector

◆ connect()

void Tle94112Motor::connect ( Tle94112Motor::ePolarity  pol,
Tle94112::HalfBridge  connector 
)

connects a single halfbridge output to a motor connector

Parameters
polPolarity of the motor connector to be configured
connectorhalfbridge output to be assigned to this motor

◆ disconnect()

void Tle94112Motor::disconnect ( Tle94112::HalfBridge  connector)

disconnects a single halfbridge output from a motor connector

Parameters
connectorhalfbridge output to be removed from this motor

◆ setPwm() [1/2]

void Tle94112Motor::setPwm ( Tle94112Motor::ePolarity  pol,
Tle94112::PWMChannel  channel 
)

Sets the PWM channel to be used for a motor connector.

Parameters
polPolarity of the motor connector to be configured
channelPWM channel to be used

◆ setPwm() [2/2]

void Tle94112Motor::setPwm ( Tle94112Motor::ePolarity  pol,
Tle94112::PWMChannel  channel,
Tle94112::PWMFreq  freq 
)

Sets the PWM channel and frequency for a motor connector.

Parameters
polPolarity of the motor connector to be configured
channelPWM channel to be used
freqPWM frequency selection

◆ setPwmFreq()

void Tle94112Motor::setPwmFreq ( Tle94112Motor::ePolarity  pol,
Tle94112::PWMFreq  freq 
)

Sets the PWM frequency for driving a motor connector.

Parameters
polPolarity of the motor connector to be configured
freqPWM frequency selection

◆ setActiveFreeWheeling()

void Tle94112Motor::setActiveFreeWheeling ( Tle94112Motor::ePolarity  pol,
uint8_t  active_fw 
)

Enables or disables active freewheeling.

Default is false i.e. passive freewheeling. Depending on your application circuit, active freewheeling may lead to electrical problems. Do not change this setting unless you know what you are doing.

Parameters
polPolarity of the motor connector to be configured
active_fwtrue/false to enable/disable active freewheeling

◆ stop()

void Tle94112Motor::stop ( uint8_t  force = 255)

actively breaks the motor to stop it

Parameters
forcehigher force lets the motor stop quicker, maximum is 255
Here is the call graph for this function:

◆ coast()

void Tle94112Motor::coast ( )

releases the motor without driving or active breaking

Here is the call graph for this function:

◆ start()

void Tle94112Motor::start ( int16_t  speed)

starts the motor with a certain speed in a certain direction

The behaviour of this function depends on the way the motor is connected to the Tle94112. Motors which have just one connector assigned to the Tle94112 cannot run in reverse direction and break instead if a negative speed value is passed. Motors without PWM assigned cannot run at a certain speed. They can just coast, run and break. Speed values greater or smaller than 0 are treated like -255 or 255, respectively.

Parameters
speedan integer in a range from -255 to 255 to set motor speed and direction
Here is the call graph for this function:

◆ setSpeed()

void Tle94112Motor::setSpeed ( int16_t  speed)

equivalent to start()

This function is fully equivalent to start(), but it is intended to be used if the motor is already running. (Distinguishing between these two functions helps improving the readability of your code) The behaviour of this function depends on the way the motor is connected to the Tle94112. Motors which have just one connector assigned to the Tle94112 cannot run in reverse direction and break instead if a negative speed value is passed. Motors without PWM assigned cannot run at a certain speed. They can just coast, run and break. Speed values greater or smaller than 0 are treated like -255 or 255, respectively.

Parameters
speedan integer in a range from -255 to 255 to set motor speed and direction
See also
start
Here is the call graph for this function:

◆ getSpeed()

int16_t Tle94112Motor::getSpeed ( void  )

Returns the motor's current speed setting.

Returns
int16_t the motor's current speed setting

◆ rampSpeed()

void Tle94112Motor::rampSpeed ( int16_t  speed,
uint16_t  slope 
)

function to gradually change the motors speed

Parameters
speedtarget speed
slopetime for a full ramp from speed=0 to speed=255
Here is the call graph for this function:

◆ _measureSetSpeedDuration()

uint32_t Tle94112Motor::_measureSetSpeedDuration ( int16_t  speed,
int16_t  start_speed 
)
protected

private function needed by rampSpeed

Parameters
speedinteger in a range from -255 to 255 to set motor speed and direction. Here the target speed.
start_speedinteger a range from -255 to 255 to set motor speed and direction. Here the source speed
Here is the call graph for this function:

◆ _performSpeedStepping()

void Tle94112Motor::_performSpeedStepping ( int16_t  start_speed,
int16_t  ramp_delta_speed,
int16_t  num_steps,
uint16_t  steptime 
)
protected

private function needed by rampSpeed

Parameters
start_speedinteger a range from -255 to 255 to set motor speed and direction. Here the source speed
ramp_delta_speedslope value how fast the speed change should raise or fall
num_stepsnumber of steps to raise or fall the speed
steptimetime to be needed for each step

none blocking delay

Here is the call graph for this function:

Field Documentation

◆ mConnectors

Connector_t Tle94112Motor::mConnectors[2]
protected
Initial value:
=
{
{
.halfbridges = {Tle94112::TLE_NOHB,
.channel = Tle94112::TLE_NOPWM,
.active_fw = false
},
{
.halfbridges = {Tle94112::TLE_NOHB,
.channel = Tle94112::TLE_NOPWM,
.active_fw = false
}
}
@ TLE_FREQ80HZ
Definition: tle94112.hpp:97
@ TLE_NOPWM
Definition: tle94112.hpp:79
@ TLE_NOHB
Definition: tle94112.hpp:72

array of motor connectors

◆ mDriver

Tle94112* Tle94112Motor::mDriver
protected

Tle94112 instance acting as output driver.

◆ mMode

eMode Tle94112Motor::mMode
protected

current operation mode

◆ mEnabled

uint8_t Tle94112Motor::mEnabled
protected

flag indicating if motor controls are enabled

◆ mSpeed

uint8_t Tle94112Motor::mSpeed
protected

value of the current motor speed

Macro Definition Documentation

◆ TLE94112_MAX_SPEED

#define TLE94112_MAX_SPEED   255

The maximum absolute speed value which can be set.

See also
Tle94112

◆ TLE94112MOTOR_MAX_CONNECTORS

#define TLE94112MOTOR_MAX_CONNECTORS   4

maximum number of Tle94112 outputs per motor connector

When this is changed, also the function signature and implementation of Tle94112Motor::initConnector has to be changed.

See also
Tle94112Motor::initConnector