Skip to content

Commit 18ac483

Browse files
authored
Merge pull request #5 from Infineon/feature/direct-register-access
Feature/direct register access
2 parents fe420a6 + b362c00 commit 18ac483

File tree

8 files changed

+198
-16
lines changed

8 files changed

+198
-16
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*!
2+
* \name directRegisterControl
3+
* \author Infineon Technologies AG
4+
* \copyright 2025 Infineon Technologies AG
5+
* \brief This example demonstrates how to control two motors via direct register setting
6+
* \details
7+
* If motors are connected to the TLE94112 on certain half bridges, than they can be controlled via direct register
8+
* setting which reduces greatly the overhead and allows fast motor controlling.
9+
* therefore the half bridges HB1 to HB4, HB5 to HB8 and HB9 to HB12 must be used together, either for controlling
10+
* two motors on one tuple (0.9 A), or one motor on one tuple (1.8 A).
11+
*
12+
* SPDX-License-Identifier: MIT
13+
*
14+
*/
15+
16+
#include <tle94112-ino.hpp>
17+
18+
//! Tle94112 Object
19+
Tle94112Ino controller = Tle94112Ino();
20+
21+
//! Tle94112 registers for motor 1 and 2
22+
uint8_t motor[2][2] = {
23+
{REG_ACT_1, REG_PWM_DC_1},
24+
{REG_ACT_3, REG_PWM_DC_3}
25+
};
26+
27+
//! Tle94112 register for motor direction
28+
volatile uint8_t oldDirection [] = { LL_HH, HH_LL };
29+
30+
/**
31+
* @brief Changes the motor direction and speed
32+
* The motor direction is set by the change of the High/Low switching of the motor half bridges in one register.
33+
* This needs some time to change the direction, so its avoided if not needed.
34+
* Setting the speed is done by setting the PWM register.
35+
*
36+
* @param motorNum uint8_t motor number (0 or 1)
37+
* @param dir uint8_t direction (HH_LL or LL_HH for forward/backward of one motor on four half bridges)
38+
* @param speed uint8_t speed (0-255)
39+
* @param errorCheck bool if true, the error register is cleared after setting the speed
40+
*/
41+
void motorSet(uint8_t motorNum, uint8_t dir, uint8_t speed, bool errorCheck = false)
42+
{
43+
if (dir != oldDirection[motorNum]) {
44+
controller.directWriteReg(motor[motorNum][0], dir);
45+
oldDirection[motorNum] = dir;
46+
}
47+
controller.directWriteReg(motor[motorNum][1], speed);
48+
if (errorCheck) {
49+
controller.clearErrors();
50+
}
51+
}
52+
53+
54+
//! connect motor between halfbridge 1 and halfbridge 2
55+
void setup()
56+
{
57+
58+
Serial.begin(9600);
59+
while (!Serial) {
60+
; // wait for serial port to connect. Needed for native USB port only
61+
}
62+
Serial.println("TLE94112 Motor Speed Control Example");
63+
delay(1000);
64+
65+
// Enable MotorController Tle94112
66+
// Note: Required to be done before starting to configure the motor
67+
controller.begin();
68+
69+
// four half bridges and two PWM channels are used to control two motors
70+
controller.configHB(controller.TLE_HB1, controller.TLE_HIGH, controller.TLE_PWM1);
71+
controller.configHB(controller.TLE_HB2, controller.TLE_HIGH, controller.TLE_PWM1);
72+
controller.configHB(controller.TLE_HB3, controller.TLE_LOW, controller.TLE_NOPWM);
73+
controller.configHB(controller.TLE_HB4, controller.TLE_LOW, controller.TLE_NOPWM);
74+
75+
controller.configHB(controller.TLE_HB9, controller.TLE_HIGH, controller.TLE_PWM3);
76+
controller.configHB(controller.TLE_HB10, controller.TLE_HIGH, controller.TLE_PWM3);
77+
controller.configHB(controller.TLE_HB11, controller.TLE_LOW, controller.TLE_NOPWM);
78+
controller.configHB(controller.TLE_HB12, controller.TLE_LOW, controller.TLE_NOPWM);
79+
80+
// all stop
81+
controller.configPWM(controller.TLE_PWM1, controller.TLE_FREQ200HZ, 0);
82+
controller.configPWM(controller.TLE_PWM3, controller.TLE_FREQ200HZ, 0);
83+
controller.clearErrors();
84+
85+
delay(1000);
86+
87+
}
88+
89+
90+
void loop() {
91+
controller.clearErrors();
92+
93+
Serial.println("forward / backward");
94+
motorSet(0, HH_LL, 100);
95+
motorSet(1, LL_HH, 100);
96+
delay(1000);
97+
98+
Serial.println(" speed up / down");
99+
motorSet(0, HH_LL, 255);
100+
motorSet(1, LL_HH, 50);
101+
delay(1000);
102+
103+
Serial.print("backward / forward ");
104+
motorSet(0, LL_HH, 255);
105+
motorSet(1, HH_LL, 255);
106+
delay(1000);
107+
108+
}

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"url":"https://www.infineon.com/cms/en/product/power/motor-control-ics/brushed-dc-motor-driver-ics/multi-half-bridge-ics/",
1313
"maintainer": true
1414
},
15-
"version":"4.1.1",
15+
"version":"4.2.0",
1616
"license":"MIT",
1717
"frameworks":"arduino",
1818
"platforms":[

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=multi-half-bridge
2-
version=4.1.1
2+
version=4.2.0
33
author=Infineon Technologies
44
maintainer=Infineon Technologies <www.infineon.com>
55
sentence=Library of Infineon Multi Half-Bridge IC controllers family

src/tle94112-ino.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,28 @@ Tle94112Ino::Tle94112Ino(void):Tle94112()
2525
}
2626

2727
/**
28-
* @brief constructor with individual pin assignment
28+
* @brief constructor with individual pin assignment for CS pin
2929
*
30-
* @param csPin pin number of the CS pin
30+
* @param csPin pin number of the CS (chip select) pin
3131
*/
3232
Tle94112Ino::Tle94112Ino(uint8_t csPin):Tle94112()
3333
{
3434
Tle94112::en = new GPIOIno( TLE94112_PIN_EN, OUTPUT, GPIOIno::POSITIVE );
3535
Tle94112::cs = new GPIOIno( csPin, OUTPUT, GPIOIno::POSITIVE );
3636
Tle94112::timer = new TimerIno();
3737
Tle94112::sBus = new SPICIno();
38+
}
39+
40+
/**
41+
* @brief constructor with individual pin assignment for CS and EN pin.
42+
*
43+
* @param csPin pin number of the CS (chip select) pin
44+
* @param enPin pin number of the EN (enable) pin
45+
*/
46+
Tle94112Ino::Tle94112Ino(uint8_t csPin, uint8_t enPin):Tle94112()
47+
{
48+
Tle94112::en = new GPIOIno( enPin, OUTPUT, GPIOIno::POSITIVE );
49+
Tle94112::cs = new GPIOIno( csPin, OUTPUT, GPIOIno::POSITIVE );
50+
Tle94112::timer = new TimerIno();
51+
Tle94112::sBus = new SPICIno();
3852
}

src/tle94112-ino.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Tle94112Ino: virtual public Tle94112
2626
public:
2727
Tle94112Ino(void);
2828
Tle94112Ino(uint8_t csPin);
29+
Tle94112Ino(uint8_t csPin, uint8_t enPin);
2930
};
3031
/** @} */
3132

src/tle94112-types.hpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,40 @@ namespace tle94112
3030
READ_ERROR = -3, /**< Read error */
3131
WRITE_ERROR = -4, /**< Write error */
3232
};
33+
34+
#define REG_ACT_1 0x03
35+
#define REG_ACT_2 0x43
36+
#define REG_ACT_3 0x23
37+
38+
#define REG_MODE_1 0x63
39+
#define REG_MODE_2 0x13
40+
#define REG_MODE_3 0x53
41+
42+
#define REG_PWM_CH_FREQ 0x33
43+
44+
#define REG_PWM_DC_1 0x73
45+
#define REG_PWM_DC_2 0x0B
46+
#define REG_PWM_DC_3 0x4B
47+
48+
#define REG_SYS_DIAG 0x1B
49+
#define REG_ERR1 0x5B
50+
#define REG_ERR2 0x3B
51+
#define REG_ERR3 0x7B
52+
#define REG_ERR4 0x07
53+
#define REG_ERR5 0x47
54+
#define REG_ERR6 0x27
55+
56+
#define REG_FW_OL 0x2B
57+
#define REG_FW_CTRL 0x6B
58+
59+
#define HL_HL 0b10011001
60+
#define HL_LH 0b10010110
61+
#define LH_HL 0b01101001
62+
#define LH_LH 0b01100110
63+
64+
#define HH_LL 0b10100101
65+
#define LL_HH 0b01011010
66+
3367
/** @} */
3468

3569
/** @} */

src/tle94112.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,21 @@ void Tle94112::init(void)
301301
/*! \brief time in milliseconds to wait for chipselect signal raised */
302302
#define TLE94112_CS_RISETIME 2
303303

304+
void Tle94112::directWriteReg(uint8_t reg, uint8_t data)
305+
{
306+
TLE94112_LOG_MSG(__FUNCTION__);
307+
308+
uint8_t address = reg | TLE94112_CMD_WRITE;
309+
uint8_t byte0;
310+
uint8_t byte1;
311+
312+
cs->disable();
313+
sBus->transfer(address, byte0);
314+
sBus->transfer(data, byte1);
315+
cs->enable();
316+
timer->delayMilli(TLE94112_CS_RISETIME);
317+
}
318+
304319
void Tle94112::writeReg(uint8_t reg, uint8_t mask, uint8_t shift, uint8_t data)
305320
{
306321
uint8_t address = mCtrlRegAddresses[reg];

src/tle94112.hpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,28 @@ class Tle94112
227227
//! \brief clears all clearable error flags
228228
void clearErrors();
229229

230+
/*! \brief writes data bits directly to a register of the TLE94112
231+
*
232+
* \param reg address of the register to be written to.
233+
* \param data the data byte that has to be written.
234+
*
235+
* \see mCtrlRegAddresses
236+
* \see mCtrlRegData
237+
*/
238+
void directWriteReg(uint8_t reg, uint8_t data);
239+
240+
/*! \brief reads one byte from a status register of the TLE94112
241+
*
242+
* \param reg status register number(mapping array index / StatusRegisters constant) of the register
243+
*
244+
* \return data byte that has been read
245+
*
246+
* \see StatusRegisters
247+
* \see TLE94112_NUM_STATUS_REGS
248+
* \see mStatusRegAddresses
249+
*/
250+
uint8_t readStatusReg(uint8_t reg);
251+
230252
SPIC *sBus; //<! \brief SPI cover class as representation of the SPI bus
231253
GPIOC *cs; //<! \brief shield enable GPIO to switch chipselect on/off
232254
GPIOC *en; //<! \brief shield enable GPIO to switch shield on/off
@@ -363,18 +385,6 @@ class Tle94112
363385
*/
364386
void writeReg(uint8_t reg, uint8_t mask, uint8_t shift, uint8_t data);
365387

366-
/*! \brief reads one byte from a status register of the TLE94112
367-
*
368-
* \param reg status register number(mapping array index / StatusRegisters constant) of the register
369-
*
370-
* \return data byte that has been read
371-
*
372-
* \see StatusRegisters
373-
* \see TLE94112_NUM_STATUS_REGS
374-
* \see mStatusRegAddresses
375-
*/
376-
uint8_t readStatusReg(uint8_t reg);
377-
378388
/*! \brief reads some bits from a status register of the TLE94112
379389
*
380390
* \param reg status register number(mapping array index / StatusRegisters constant) of the register

0 commit comments

Comments
 (0)