4
4
* \copyright 2021 Infineon Technologies AG
5
5
* \brief This example demonstrates how to control the speed of motor by using the PWM units of the TLE94112 shield
6
6
* \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.
9
8
* The TLE94112 has three separate PWM units which can be attached to any combination
10
9
* of halfbridges. So try out to change the TLE_PWM1 to TLE_PWM2 or TLE_PWM3 to see this.
11
10
* You can change the motor direction by changing the HIGH/LOW status of the halfbridges
19
18
// ! Tle94112 Object
20
19
Tle94112Ino controller = Tle94112Ino();
21
20
22
- // ! Select pins for speed and direction settings
23
- #define pinDir 5
24
- #define pinSpeed A0
25
-
26
21
// ! connect motor between halfbridge 1 and halfbridge 2
27
22
void setup ()
28
23
{
29
24
// Enable MotorController Tle94112
30
25
// Note: Required to be done before starting to configure the motor
31
26
controller.begin ();
32
-
33
- pinMode (pinDir, INPUT);
34
- pinMode (pinSpeed, INPUT);
35
27
}
36
28
37
29
38
30
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++)
42
39
{
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 );
45
42
}
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++)
47
51
{
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 );
50
54
}
51
55
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