Skip to content

Commit fe420a6

Browse files
authored
Merge pull request #4 from Infineon/update-speedControl-example
examples/speedControl: Replace poti by ramp.
2 parents 4e2caf6 + 78bd3c3 commit fe420a6

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

examples/speedControl/speedControl.ino

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
* \copyright 2021 Infineon Technologies AG
55
* \brief This example demonstrates how to control the speed of motor by using the PWM units of the TLE94112 shield
66
* \details
7-
* Attaching a potentiometer on an analog input pin, which will than control the
8-
* setting of the TLE94112 internal PWM unit and therefore the speed of the motor.
7+
* Ramping the speed of the motor up and down by using PWM signals.
98
* The TLE94112 has three separate PWM units which can be attached to any combination
109
* of halfbridges. So try out to change the TLE_PWM1 to TLE_PWM2 or TLE_PWM3 to see this.
1110
* You can change the motor direction by changing the HIGH/LOW status of the halfbridges
@@ -19,39 +18,39 @@
1918
//! Tle94112 Object
2019
Tle94112Ino controller = Tle94112Ino();
2120

22-
//! Select pins for speed and direction settings
23-
#define pinDir 5
24-
#define pinSpeed A0
25-
2621
//! connect motor between halfbridge 1 and halfbridge 2
2722
void setup()
2823
{
2924
// Enable MotorController Tle94112
3025
// Note: Required to be done before starting to configure the motor
3126
controller.begin();
32-
33-
pinMode(pinDir, INPUT);
34-
pinMode(pinSpeed, INPUT);
3527
}
3628

3729

3830
void loop() {
39-
// get desired direction from digital pin
40-
uint8_t dir = digitalRead(pinDir);
41-
if(dir == HIGH)
31+
32+
/* Configure the motor to use PWM with a duty cycle of 0% and forward direction. */
33+
controller.configPWM(controller.TLE_PWM1, controller.TLE_FREQ80HZ, 0);
34+
controller.configHB(controller.TLE_HB1, controller.TLE_HIGH, controller.TLE_PWM1);
35+
controller.configHB(controller.TLE_HB2, controller.TLE_LOW, controller.TLE_NOPWM);
36+
37+
/* Ramp up duty cycle from 0% to 100%. */
38+
for (uint8_t speed = 0; speed < 255; speed++)
4239
{
43-
controller.configHB(controller.TLE_HB1, controller.TLE_HIGH, controller.TLE_PWM1);
44-
controller.configHB(controller.TLE_HB2, controller.TLE_LOW, controller.TLE_NOPWM);
40+
controller.configPWM(controller.TLE_PWM1, controller.TLE_FREQ80HZ, speed);
41+
delay(10);
4542
}
46-
else
43+
44+
/* Configure the motor to use PWM with a duty cycle of 0% and backward direction. */
45+
controller.configPWM(controller.TLE_PWM1, controller.TLE_FREQ80HZ, 0);
46+
controller.configHB(controller.TLE_HB1, controller.TLE_LOW, controller.TLE_NOPWM);
47+
controller.configHB(controller.TLE_HB2, controller.TLE_HIGH, controller.TLE_PWM1);
48+
49+
/* Ramp up duty cycle from 0% to 100%. */
50+
for (uint8_t speed = 0; speed < 255; speed++)
4751
{
48-
controller.configHB(controller.TLE_HB1, controller.TLE_LOW, controller.TLE_NOPWM);
49-
controller.configHB(controller.TLE_HB2, controller.TLE_HIGH, controller.TLE_PWM1);
52+
controller.configPWM(controller.TLE_PWM1, controller.TLE_FREQ80HZ, 255-speed);
53+
delay(10);
5054
}
5155

52-
// get desired motor speed from analog input
53-
uint8_t dc = analogRead(pinSpeed) >> 2;
54-
55-
// update motor speed
56-
controller.configPWM(controller.TLE_PWM1, controller.TLE_FREQ80HZ, dc);
57-
}
56+
}

0 commit comments

Comments
 (0)