diff --git a/.travis.yml b/.travis.yml index 4ee8a0e7..3da1dce8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ sudo: required branches: - master + only: - tle94112 env: diff --git a/examples/Control2Motors/Control2Motors.ino b/examples/Control2Motors/Control2Motors.ino index 3ec162d7..6d7c2281 100644 --- a/examples/Control2Motors/Control2Motors.ino +++ b/examples/Control2Motors/Control2Motors.ino @@ -1,4 +1,30 @@ -#include +/*! + * \name Control2Motors + * \author Infineon Technologies AG + * \copyright 2019 Infineon Technologies AG + * \version 1.4.1 + * \brief + * This example demonstrates how to control two motors, their speed and direction + * with the TLE94112 shield + * \detail + * By attaching a Tle94112 controller object to two Tle94112Motor objects, we can generate + * an easy to handle motor object for each motor. We can easily attach this motor object + * two any of the halfbridges and to any of the PWM units. This is done in the setup part. + * Keep in mind that you have to initialize the Tle94112 controller and each motor object, + * which is done in the setup function. + * After that we can take the motor start, stop and setSpeed function to easily control + * each motor. + * + * \attention Motors have depending on there size a very big latency until a motor has + * fully started or is stoped to 0. Specially the time between a start and stop and vice versa + * is much higher than higher than the processing speed of any microcontroller. This + * is solved in this example with the delay command, but there are better solutions than that. + * This delays are needed because a direct switch between start and stop will lead to high currents + * and the TLE94112 will signal an overcurrent. + * + */ + +#include #include // Tle94112 Object @@ -78,4 +104,4 @@ void loop() motor1.stop(255); delay(5000); -} \ No newline at end of file +} diff --git a/examples/rampSpeedTest/rampSpeedTest.ino b/examples/rampSpeedTest/rampSpeedTest.ino index b85c2362..a29f1858 100644 --- a/examples/rampSpeedTest/rampSpeedTest.ino +++ b/examples/rampSpeedTest/rampSpeedTest.ino @@ -1,8 +1,25 @@ -#include +/*! + * \name rampSpeedTest + * \author Infineon Technologies AG + * \copyright 2019 Infineon Technologies AG + * \version 1.4.1 + * \brief + * This example measure the rampspeed of an attached motor with the TLE94112 shield + * \detail + * By attaching a motor to the TLE94112 and running a testcase scenario, we can measure the + * optimal values for the rampSpeed function. This function allows us to smoothly start, stop, + * raise or break the motor. + * + * \attention A free running motor ramps very different that the same motor with load attached. + * So you have to measure different scenarios. + * + */ + +#include #include -// Tle94112 Object on Shiled 1 +// Tle94112 Object on Shield 1 Tle94112 controller1 = Tle94112(); // Tle94112Motor Objects on controller1 @@ -15,6 +32,7 @@ typedef struct { uint16_t slope; } RampMeasurement_t, *RampMeasurement_p; +// lets define an array with different #define NUM_TESTS 6 RampMeasurement_t testcases[NUM_TESTS] = { { 0, 255, 5000 }, @@ -78,4 +96,4 @@ void loop() { { measureRampTime(i); } -} \ No newline at end of file +} diff --git a/examples/rampTest/rampTest.ino b/examples/rampTest/rampTest.ino index bce223f0..47310e81 100644 --- a/examples/rampTest/rampTest.ino +++ b/examples/rampTest/rampTest.ino @@ -1,111 +1,122 @@ -#include -#include -/* - ============================================================================ - Name : Lego Robot III - Author : Dr. Olaf Filies, Marcus Gordon Filies - Version : 0.9 - Description : ramping the motor speed of a high current motor - ============================================================================ - */ - -// Tle94112 Object on Shiled 1 -Tle94112 controller1 = Tle94112(); - -// Tle94112Motor Objects on controller1 -Tle94112Motor motor1(controller1); - - -void setup() { - Serial.begin(115200); // Switch on comunication - Serial.println("Init ready"); - - // Enable MotorController on all Shields and Motors - // Note: Required to be done before starting to configure the motor - // controller1 is set to default CS1 pin - controller1.begin(); - - //-Motor1-high current motor between out1/out2 = HB1/HB2 and out3/out4 = HB3/HB4------------------- - - // Connect motor1 to HB1/HB2 highside and HB3/HB4 lowside - // IMPORTANT connect PWM to Lowside as higside is active Free wheeling - motor1.initConnector(motor1.HIGHSIDE, controller1.TLE_NOPWM, controller1.TLE_HB1, controller1.TLE_HB2, controller1.TLE_NOHB, controller1.TLE_NOHB); - motor1.initConnector(motor1.LOWSIDE, controller1.TLE_PWM1, controller1.TLE_HB3, controller1.TLE_HB4, controller1.TLE_NOHB, controller1.TLE_NOHB); - - // start motor1 - motor1.begin(); -} - -void loop() { - - motor1.coast(); - delay(1000); - -// max forward/backward - Serial.println("max forward/backward"); - motor1.start(255); - delay(1000); - motor1.coast(); - delay(1000); - motor1.start(-255); - delay(1000); - motor1.coast(); - delay(1000); - -// ramp rippel forward/backward - Serial.println("ramp rippel forward/backward"); - motor1.start(255); - delay(1000); - motor1.rampSpeed(0,5000); - delay(1000); - motor1.start(-255); - delay(1000); - motor1.rampSpeed(0,5000); - delay(1000); - -// ramp up/down forward - Serial.println("ramp up/down forward"); - motor1.start(50); // start above 0 to allow motor to start - motor1.rampSpeed(255,5000); - delay(1000); - motor1.rampSpeed(100,5000); - delay(1000); - motor1.rampSpeed(255,5000); - delay(1000); - motor1.rampSpeed(0,5000); - -// ramp up/down backward - Serial.println("ramp up/down backward"); - motor1.start(50); - motor1.rampSpeed(-255,5000); - delay(1000); - motor1.rampSpeed(-100,5000); - delay(1000); - motor1.rampSpeed(-255,5000); - delay(1000); - motor1.rampSpeed(0,5000); - -// ramp transient - Serial.println("ramp transient"); - motor1.rampSpeed(-255,1000); - delay(1000); - motor1.rampSpeed(255,1000); - delay(1000); - motor1.rampSpeed(-255,1000); - delay(1000); - motor1.rampSpeed(0,1000); - delay(1000); - -// stop and coast - Serial.println("stop and coast"); - motor1.stop(255); - delay(1000); - motor1.coast(); - delay(1000); - - -} - - - - +/*! + * \name rampTest + * \author Infineon Technologies AG + * \copyright 2019 Infineon Technologies AG + * \version 1.4.1 + * \brief + * This example to run a motor with the rampSpeed function + * \detail + * This example also demonstrats how to attach a bigger motor on 4 halfbridges with a total + * current of 1.8 A. Originally designed to test Lego (R) Powerfunktions or Mindstorm motors, + * this sketch can be used to simply run a motor smoothly with different speeds + * in different directions. + * + */ + +#include +#include +/* + ============================================================================ + Name : Lego Robot III + Author : Dr. Olaf Filies, Marcus Gordon Filies + Version : 0.9 + Description : ramping the motor speed of a high current motor + ============================================================================ + */ + +// Tle94112 Object on Shield 1 +Tle94112 controller1 = Tle94112(); + +// Tle94112Motor Objects on controller1 +Tle94112Motor motor1(controller1); + + +void setup() { + Serial.begin(115200); // Switch on communications + Serial.println("Init ready"); + + // Enable MotorController on all Shields and Motors + // Note: Required to be done before starting to configure the motor + // controller1 is set to default CS1 pin + controller1.begin(); + + //-Motor1-high current motor between out1/out2 = HB1/HB2 and out3/out4 = HB3/HB4------------------- + + // Connect motor1 to HB1/HB2 highside and HB3/HB4 lowside + // IMPORTANT connect PWM to Lowside as higside is active Free wheeling + motor1.initConnector(motor1.HIGHSIDE, controller1.TLE_NOPWM, controller1.TLE_HB1, controller1.TLE_HB2, controller1.TLE_NOHB, controller1.TLE_NOHB); + motor1.initConnector(motor1.LOWSIDE, controller1.TLE_PWM1, controller1.TLE_HB3, controller1.TLE_HB4, controller1.TLE_NOHB, controller1.TLE_NOHB); + + // start motor1 + motor1.begin(); +} + +void loop() { + + motor1.coast(); + delay(1000); + +// max forward/backward + Serial.println("max forward/backward"); + motor1.start(255); + delay(1000); + motor1.coast(); + delay(1000); + motor1.start(-255); + delay(1000); + motor1.coast(); + delay(1000); + +// ramp ripple forward/backward + Serial.println("ramp ripple forward/backward"); + motor1.start(255); + delay(1000); + motor1.rampSpeed(0,5000); + delay(1000); + motor1.start(-255); + delay(1000); + motor1.rampSpeed(0,5000); + delay(1000); + +// ramp up/down forward + Serial.println("ramp up/down forward"); + motor1.start(50); // start above 0 to allow motor to start + motor1.rampSpeed(255,5000); + delay(1000); + motor1.rampSpeed(100,5000); + delay(1000); + motor1.rampSpeed(255,5000); + delay(1000); + motor1.rampSpeed(0,5000); + +// ramp up/down backward + Serial.println("ramp up/down backward"); + motor1.start(50); + motor1.rampSpeed(-255,5000); + delay(1000); + motor1.rampSpeed(-100,5000); + delay(1000); + motor1.rampSpeed(-255,5000); + delay(1000); + motor1.rampSpeed(0,5000); + +// ramp transient + Serial.println("ramp transient"); + motor1.rampSpeed(-255,1000); + delay(1000); + motor1.rampSpeed(255,1000); + delay(1000); + motor1.rampSpeed(-255,1000); + delay(1000); + motor1.rampSpeed(0,1000); + delay(1000); + +// stop and coast + Serial.println("stop and coast"); + motor1.stop(255); + delay(1000); + motor1.coast(); + delay(1000); + + +} diff --git a/examples/speedControl/speedControl.ino b/examples/speedControl/speedControl.ino index e2f2edcf..082d06b0 100644 --- a/examples/speedControl/speedControl.ino +++ b/examples/speedControl/speedControl.ino @@ -1,41 +1,58 @@ -#include - -// Tle94112 Object -Tle94112 controller = Tle94112(); - -#define pinDir 5 -#define pinSpeed A0 -//connect motor between halfbridge 1 and halfbridge 2 - - -void setup() -{ - // Enable MotorController Tle94112 - // Note: Required to be done before starting to configure the motor - controller.begin(); - - pinMode(pinDir, INPUT); - pinMode(pinSpeed, INPUT); -} - - -void loop() { - // get desired direction from digital pin - uint8_t dir = digitalRead(pinDir); - if(dir == HIGH) - { - controller.configHB(controller.TLE_HB1, controller.TLE_HIGH, controller.TLE_PWM1); - controller.configHB(controller.TLE_HB2, controller.TLE_LOW, controller.TLE_NOPWM); - } - else - { - controller.configHB(controller.TLE_HB1, controller.TLE_LOW, controller.TLE_NOPWM); - controller.configHB(controller.TLE_HB2, controller.TLE_HIGH, controller.TLE_PWM1); - } - - // get desired motor speed from analog input - uint8_t dc = analogRead(pinSpeed) >> 2; - - // update motor speed - controller.configPWM(controller.TLE_PWM1, controller.TLE_FREQ80HZ, dc); -} \ No newline at end of file +/*! + * \name speedControl + * \author Infineon Technologies AG + * \copyright 2019 Infineon Technologies AG + * \version 1.4.1 + * \brief + * This example demonstrates how to control the speed of motor by using the PWM units + * of the TLE94112 shield + * \detail + * Attaching a potentiometer on an analog input pin, which will than controll the + * setting of the TLE94112 internal PWM unit and therefore the speed of the motor. + * The TLE94112 has three seperat PWM units which can be attached to any combination + * of halfbridges. So try out to change the TLE_PWM1 to TLE_PWM2 or TLE_PWM3 to see this. + * You can change the motor direction by changing the HIGH/LOW status of the halfbridges + * + */ + +#include + +//! Tle94112 Object +Tle94112 controller = Tle94112(); + +//! Select pins for speed and direction setings +#define pinDir 5 +#define pinSpeed A0 + +//! connect motor between halfbridge 1 and halfbridge 2 +void setup() +{ + // Enable MotorController Tle94112 + // Note: Required to be done before starting to configure the motor + controller.begin(); + + pinMode(pinDir, INPUT); + pinMode(pinSpeed, INPUT); +} + + +void loop() { + // get desired direction from digital pin + uint8_t dir = digitalRead(pinDir); + if(dir == HIGH) + { + controller.configHB(controller.TLE_HB1, controller.TLE_HIGH, controller.TLE_PWM1); + controller.configHB(controller.TLE_HB2, controller.TLE_LOW, controller.TLE_NOPWM); + } + else + { + controller.configHB(controller.TLE_HB1, controller.TLE_LOW, controller.TLE_NOPWM); + controller.configHB(controller.TLE_HB2, controller.TLE_HIGH, controller.TLE_PWM1); + } + + // get desired motor speed from analog input + uint8_t dc = analogRead(pinSpeed) >> 2; + + // update motor speed + controller.configPWM(controller.TLE_PWM1, controller.TLE_FREQ80HZ, dc); +} diff --git a/src/TLE94112.cpp b/src/TLE94112.cpp index 1bc75007..6479683a 100644 --- a/src/TLE94112.cpp +++ b/src/TLE94112.cpp @@ -1,19 +1,25 @@ -/* - * Arduino library to control Infineon's DC Motor Control Shield with TLE94112 - * - * The shield contains twelve independent halfbridges, - * so it can drive up to 6 independent (+5 cascaded) bidirectional DC motor(s). - * Each halfbridge provides a high-Voltage (nominal 5.5-18 V) tristate output, - * which is also capable of PWM with 3 different frequencies. +/*! + * \file Tle94112.cpp + * \name Tle94112.cpp - Arduino library to control Infineon's DC Motor Control Shield with Tle94112 + * \author Infineon Technologies AG + * \copyright 2019 Infineon Technologies AG + * \version 1.4.1 + * \brief This file has to be included in projects that use Infineon's DC Motor Control Shield with TLE94112 + * \details + * The Infineon TLE94112EL DC motor controller shield is able to handle 6 motors with a max. current of 0.9 A + * independently and additional 5 motors cascaded. The twelve half-bridges can be arranged also together, + * so that 3 motors with 1.8 A current or one motor with 3.6 A can be used. Each half bridge can + * provide a high-Voltage (nominal 5.5-18 V) tristate output and max. input voltage of 40V. It is also + * capable of PWM with 3 different frequencies for controlling the speed of each motor. + * Have a look at the datasheet for more information. + * + * This library include the basic functions to access the half-bridges. * * Have a look at the datasheet for more information. */ - -/*! \file TLE94112.cpp - * \brief This file defines functions and predefined instances from TLE94112.h - */ -#include "Tle94112.h" + +#include "TLE94112.h" #include "./util/tle94112_conf.h" //SPI address commands diff --git a/src/TLE94112.h b/src/TLE94112.h index 6ec7663a..81fd0697 100644 --- a/src/TLE94112.h +++ b/src/TLE94112.h @@ -1,15 +1,19 @@ /*! - * \file Tle94112.h - * \brief This file has to be included in projects that use Infineon's DC Motor Control Shield with TLE94112 - * - * Arduino library to control Infineon's DC Motor Control Shield with Tle94112 - * - * The shield contains twelve independent halfbridges, - * so it can drive up to 6 independent (+5 cascaded) bidirectional DC motor(s). - * Each halfbridge provides a high-Voltage (nominal 5.5-18 V) tristate output, - * which is also capable of PWM with 3 different frequencies. - * - * Have a look at the datasheet for more information. + * \file Tle94112.h + * \name Tle94112.h - Arduino library to control Infineon's DC Motor Control Shield with Tle94112 + * \author Infineon Technologies AG + * \copyright 2019 Infineon Technologies AG + * \version 1.4.1 + * \brief This file has to be included in projects that use Infineon's DC Motor Control Shield with TLE94112 + * \details + * The Infineon TLE94112EL DC motor controller shield is able to handle 6 motors with a max. current of 0.9 A + * independently and additional 5 motors cascaded. The twelve half-bridges can be arranged also together, + * so that 3 motors with 1.8 A current or one motor with 3.6 A can be used. Each half bridge can + * provide a high-Voltage (nominal 5.5-18 V) tristate output and max. input voltage of 40V. It is also + * capable of PWM with 3 different frequencies for controlling the speed of each motor. + * Have a look at the datasheet for more information. + * + * This library include the basic functions to access the half-bridges. * * * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the diff --git a/src/Tle94112Motor.cpp b/src/Tle94112Motor.cpp index c0ae1005..ceff2671 100644 --- a/src/Tle94112Motor.cpp +++ b/src/Tle94112Motor.cpp @@ -1,3 +1,43 @@ +/*! + * \file Tle94112Motor.cpp + * \name Tle94112Motor.cpp - optionally include library + * \author Infineon Technologies AG + * \copyright 2019 Infineon Technologies AG + * \version 1.4.1 + * \brief This file can optionally be included in projects that use Infineon's + * DC Motor Control Shield with TLE94112 + * It provides a higher abstraction for controlling motors with the TLE94112 + * acting as an output driver + * \details + * The Infineon TLE94112EL DC motor controller shield is able to handle 6 motors with a max. current of 0.9 A + * independently and additional 5 motors cascaded. The twelve half-bridges can be arranged also together, + * so that 3 motors with 1.8 A current or one motor with 3.6 A can be used. Each half bridge can + * provide a high-Voltage (nominal 5.5-18 V) tristate output and max. input voltage of 40V. It is also + * capable of PWM with 3 different frequencies for controlling the speed of each motor. + * Have a look at the datasheet for more information. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following + * disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + #include "Tle94112Motor.h" #define TLE94112_MAX_SPEED 255 @@ -64,8 +104,7 @@ void Tle94112Motor::initConnector(Tle94112Motor::ePolarity pol, } } -void Tle94112Motor::connect(Tle94112Motor::ePolarity pol, - Tle94112::HalfBridge connector) +void Tle94112Motor::connect(Tle94112Motor::ePolarity pol, Tle94112::HalfBridge connector) { if(mEnabled == FALSE) { @@ -97,8 +136,7 @@ void Tle94112Motor::disconnect(Tle94112::HalfBridge connector) } } -void Tle94112Motor::setPwm(Tle94112Motor::ePolarity pol, - Tle94112::PWMChannel channel) +void Tle94112Motor::setPwm(Tle94112Motor::ePolarity pol, Tle94112::PWMChannel channel) { if(mEnabled == FALSE) { @@ -116,8 +154,7 @@ void Tle94112Motor::setPwm(Tle94112Motor::ePolarity pol, } } -void Tle94112Motor::setPwmFreq(Tle94112Motor::ePolarity pol, - Tle94112::PWMFreq freq) +void Tle94112Motor::setPwmFreq(Tle94112Motor::ePolarity pol, Tle94112::PWMFreq freq) { if(mEnabled == FALSE) { @@ -235,24 +272,24 @@ void Tle94112Motor::setSpeed(int16_t speed) mSpeed = static_cast(speed); for(uint8_t idx = 0u; idx < TLE94112MOTOR_MAX_CONNECTORS; idx++) { - mDriver->configHB(mConnectors[HIGHSIDE].halfbridges[idx], - Tle94112::TLE_HIGH, - mConnectors[HIGHSIDE].channel, - mConnectors[HIGHSIDE].active_fw); - mDriver->configHB(mConnectors[LOWSIDE].halfbridges[idx], - Tle94112::TLE_LOW, - mConnectors[LOWSIDE].channel, - mConnectors[LOWSIDE].active_fw); + mDriver->configHB( + mConnectors[HIGHSIDE].halfbridges[idx], + Tle94112::TLE_HIGH, + mConnectors[HIGHSIDE].channel, + mConnectors[HIGHSIDE].active_fw); + mDriver->configHB( + mConnectors[LOWSIDE].halfbridges[idx], + Tle94112::TLE_LOW, + mConnectors[LOWSIDE].channel, + mConnectors[LOWSIDE].active_fw); } } } else // speed < 0 { mSpeed = static_cast(-speed); - mDriver->configPWM(mConnectors[HIGHSIDE].channel, - mConnectors[HIGHSIDE].freq, mSpeed); - mDriver->configPWM(mConnectors[LOWSIDE].channel, - mConnectors[LOWSIDE].freq, mSpeed); + mDriver->configPWM(mConnectors[HIGHSIDE].channel, mConnectors[HIGHSIDE].freq, mSpeed); + mDriver->configPWM(mConnectors[LOWSIDE].channel, mConnectors[LOWSIDE].freq, mSpeed); if(mMode != BACKWARD) { //change configuration to running backward @@ -293,7 +330,8 @@ int16_t Tle94112Motor::getSpeed(void) uint32_t Tle94112Motor::measureSetSpeedDuration(int16_t speed, int16_t start_speed) { - if(start_speed == 0) { + if(start_speed == 0) + { // changing direction is additional effort // don't let this have an effect on the setSpeed duration measurement start_speed = SIGNUM(speed); @@ -309,7 +347,8 @@ void Tle94112Motor::performSpeedStepping(int16_t start_speed, int16_t ramp_delta_speed, int16_t num_steps, uint16_t steptime) { uint32_t Timer = millis(); //!> none blocking delay - if(num_steps > 0) { + if(num_steps > 0) + { // normal ramp loop for(uint16_t i=1u; i<=num_steps; i++) { @@ -326,10 +365,12 @@ void Tle94112Motor::performSpeedStepping(int16_t start_speed, setSpeed(start_speed+ramp_delta_speed); } } + void Tle94112Motor::rampSpeed(int16_t speed, uint16_t slope) { int16_t start_speed = getSpeed(); - if (mEnabled == TRUE && speed != start_speed) { + if (mEnabled == TRUE && speed != start_speed) + { uint32_t duration = measureSetSpeedDuration(speed, start_speed); //mDriver->clearErrors(); // calc full ramp deltas @@ -339,7 +380,8 @@ void Tle94112Motor::rampSpeed(int16_t speed, uint16_t slope) int16_t num_steps = ramp_delta_time / duration - 1; uint16_t steptime = 0; // correction of step deltas for very flat ramps - if (abs(ramp_delta_speed) < num_steps) { + if (abs(ramp_delta_speed) < num_steps) + { num_steps = abs(ramp_delta_speed); steptime = ramp_delta_time / abs(ramp_delta_speed) - duration; } diff --git a/src/Tle94112Motor.h b/src/Tle94112Motor.h index 2c759456..633b6ea1 100644 --- a/src/Tle94112Motor.h +++ b/src/Tle94112Motor.h @@ -1,16 +1,47 @@ -/** - * @file Tle94112Motor.h - * @brief This file can optionally be included in projects that use Infineon's - * DC Motor Control Shield with TLE94112 +/*! + * \file Tle94112Motor.h + * \name Tle94112Motor.h - optionally include library + * \author Infineon Technologies AG + * \copyright 2019 Infineon Technologies AG + * \version 1.4.1 + * \brief This file can optionally be included in projects that use Infineon's + * DC Motor Control Shield with TLE94112 + * It provides a higher abstraction for controlling motors with the TLE94112 + * acting as an output driver + * \details + * The Infineon TLE94112EL DC motor controller shield is able to handle 6 motors with a max. current of 0.9 A + * independently and additional 5 motors cascaded. The twelve half-bridges can be arranged also together, + * so that 3 motors with 1.8 A current or one motor with 3.6 A can be used. Each half bridge can + * provide a high-Voltage (nominal 5.5-18 V) tristate output and max. input voltage of 40V. It is also + * capable of PWM with 3 different frequencies for controlling the speed of each motor. + * Have a look at the datasheet for more information. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following + * disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * It provides a higher abstraction for controlling motors with the TLE94112 - * acting as an output driver */ #ifndef TLE94112MOTOR_H #define TLE94112MOTOR_H -#include "Tle94112.h" +#include "TLE94112.h" /** @@ -94,7 +125,7 @@ class Tle94112Motor * @brief 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 poarity, + * + and - connector of the motor. If there is no setup for one polarity, * the library assumes that the motor is constantly connected to + or -. * * @param pol Polarity of the motor connector to be configured @@ -115,7 +146,7 @@ class Tle94112Motor * @brief 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 poarity, + * + and - connector of the motor. If there is no setup for one polarity, * the library assumes that the motor is constantly connected to + or -. * * @param pol Polarity of the motor connector to be configured @@ -211,8 +242,7 @@ class Tle94112Motor * coast, run and break. Speed values greater or smaller than 0 are treated * like -255 or 255, respectively. * - * @param speed An integer in a range from -255 to 255 to set motor speed - * and direction + * @param speed An integer in a range from -255 to 255 to set motor speed and direction */ void start(int16_t speed); @@ -230,8 +260,7 @@ class Tle94112Motor * coast, run and break. Speed values greater or smaller than 0 are treated * like -255 or 255, respectively. * - * @param speed An integer in a range from -255 to 255 to set motor speed - * and direction + * @param speed An integer in a range from -255 to 255 to set motor speed and direction * @see start */ void setSpeed(int16_t speed); @@ -264,7 +293,8 @@ class Tle94112Motor }; //! @brief struct representing one motor connector - typedef struct { + typedef struct + { Tle94112::HalfBridge halfbridges[TLE94112MOTOR_MAX_CONNECTORS]; Tle94112::PWMChannel channel; Tle94112::PWMFreq freq; @@ -272,7 +302,8 @@ class Tle94112Motor } Connector_t, *Connector_p; //! @brief array of motor connectors - Connector_t mConnectors[2] = { + Connector_t mConnectors[2] = + { { .halfbridges = {Tle94112::TLE_NOHB, Tle94112::TLE_NOHB, @@ -305,10 +336,27 @@ class Tle94112Motor //! @brief value of the current motor speed uint8_t mSpeed; - //! @brief private function needed by rampSpeed + //! + + /* + * @brief private function needed by rampSpeed + * + * @param speed An integer in a range from -255 to 255 to set motor speed + * and direction. Here the target speed. + * @param start_speed An integer a range from -255 to 255 to set motor speed + * and direction. Here the source speed + */ uint32_t measureSetSpeedDuration(int16_t speed, int16_t start_speed); - //! @brief private function needed by rampSpeed + /* @brief private function needed by rampSpeed + * + * @param start_speed An integer a range from -255 to 255 to set motor speed + * and direction. Here the source speed + * @param ramp_delta_speed a slope value how fast the speed change + * should raise or fall + * @param num_steps The number of steps to raise or fall the speed + * @param steptime The time to be needed for each step + */ void performSpeedStepping(int16_t start_speed, int16_t ramp_delta_speed, int16_t num_steps, uint16_t steptime); }; diff --git a/src/util/tle94112_conf.cpp b/src/util/tle94112_conf.cpp index 8b2ae007..f68903ed 100644 --- a/src/util/tle94112_conf.cpp +++ b/src/util/tle94112_conf.cpp @@ -1,25 +1,44 @@ -/* - * Arduino library to control Infineon's DC Motor Control Shield with TLE94112 +/*! + * \file TLE94112_conf.cpp + * \name TLE94112_conf.cpp - automatically included library + * \author Infineon Technologies AG + * \copyright 2019 Infineon Technologies AG + * \version 1.4.1 + * \brief This file can optionally be included in projects that use Infineon's + * DC Motor Control Shield with TLE94112 + * It provides a higher abstraction for controlling motors with the TLE94112 + * acting as an output driver + * + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: * - * The shield contains twelve independent halfbridges, - * so it can drive up to 6 indipendent (+5 cascaded) bidirectional DC motor(s). - * Each halfbridge provides a high-Voltage (nominal 5.5-18 V) tristate output, - * which is also capable of PWM with 3 different frequencies. + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following + * disclaimer. * - * Have a look at the datasheet for more information. - */ - -/*! \file TLE94112_conf.cpp - * \brief This file contains the initialization of a TLE94112 with all its magic numbers + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * */ -#include "tle94112_conf.h" -#include "Tle94112.h" +#include "tle94112_conf.h" +#include "TLE94112.h" void Tle94112::init(void) { - //initial control register configuration + //!< initial control register configuration mCtrlRegAddresses[static_cast(Tle94112::HB_ACT_1_CTRL)] = 0x03; mCtrlRegData[HB_ACT_1_CTRL] = 0; mCtrlRegAddresses[HB_ACT_2_CTRL] = 0x43; @@ -45,7 +64,7 @@ void Tle94112::init(void) mCtrlRegAddresses[FW_CTRL] = 0x6B; mCtrlRegData[FW_CTRL] = 0; - //status register configuration + //!< status register configuration mStatusRegAddresses[SYS_DIAG1] = 0x1B; mStatusRegAddresses[OP_ERROR_1_STAT] = 0x5B; mStatusRegAddresses[OP_ERROR_2_STAT] = 0x3B; @@ -54,7 +73,7 @@ void Tle94112::init(void) mStatusRegAddresses[OP_ERROR_5_STAT] = 0x47; mStatusRegAddresses[OP_ERROR_6_STAT] = 0x27; - //bit masking for all halfbridges + //!< bit masking for all halfbridges mHalfBridges[TLE_NOHB] = { HB_ACT_1_CTRL, 0x00, 0, HB_MODE_1_CTRL, 0x00, 0, FW_OL_CTRL, 0x00, 0, OP_ERROR_1_STAT, 0x00, 0, OP_ERROR_4_STAT, 0x00, 0 }; mHalfBridges[TLE_HB1] = { HB_ACT_1_CTRL, 0x03, 0, HB_MODE_1_CTRL, 0x03, 0, FW_OL_CTRL, 0x04, 2, OP_ERROR_1_STAT, 0x03, 0, OP_ERROR_4_STAT, 0x03, 0 }; mHalfBridges[TLE_HB2] = { HB_ACT_1_CTRL, 0x0C, 2, HB_MODE_1_CTRL, 0x0C, 2, FW_OL_CTRL, 0x08, 3, OP_ERROR_1_STAT, 0x0C, 2, OP_ERROR_4_STAT, 0x0C, 2 }; @@ -69,10 +88,10 @@ void Tle94112::init(void) mHalfBridges[TLE_HB11] = { HB_ACT_3_CTRL, 0x30, 4, HB_MODE_3_CTRL, 0x30, 4, FW_CTRL, 0x10, 4, OP_ERROR_3_STAT, 0x30, 4, OP_ERROR_6_STAT, 0x30, 4 }; mHalfBridges[TLE_HB12] = { HB_ACT_3_CTRL, 0xC0, 6, HB_MODE_3_CTRL, 0xC0, 6, FW_CTRL, 0x20, 5, OP_ERROR_3_STAT, 0xC0, 6, OP_ERROR_6_STAT, 0xC0, 6 }; - //bit masking for all pwm channels + //!< bit masking for all pwm channels mPwmChannels[TLE_NOPWM] = { PWM_CH_FREQ_CTRL, 0x00, 0, 0, 0x00, 0}; //dummy channel for NOPWM mPwmChannels[TLE_PWM1] = { PWM_CH_FREQ_CTRL, 0x03, 0, PWM1_DC_CTRL, 0xFF, 0}; mPwmChannels[TLE_PWM2] = { PWM_CH_FREQ_CTRL, 0x0C, 2, PWM2_DC_CTRL, 0xFF, 0}; mPwmChannels[TLE_PWM3] = { PWM_CH_FREQ_CTRL, 0x30, 4, PWM3_DC_CTRL, 0xFF, 0}; -} \ No newline at end of file +} diff --git a/src/util/tle94112_conf.h b/src/util/tle94112_conf.h index 466e2a78..130230bd 100644 --- a/src/util/tle94112_conf.h +++ b/src/util/tle94112_conf.h @@ -1,19 +1,37 @@ -/* - * Arduino library to control Infineon's DC Motor Control Shield with TLE94112 +/*! + * \file TLE94112_conf.h + * \name TLE94112_conf.h - automatically included library + * \author Infineon Technologies AG + * \copyright 2019 Infineon Technologies AG + * \version 1.4.1 + * \brief This file can optionally be included in projects that use Infineon's + * DC Motor Control Shield with TLE94112 + * It provides a higher abstraction for controlling motors with the TLE94112 + * acting as an output driver + * + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: * - * The shield contains twelve independent halfbridges, - * so it can drive up to 6 indipendent (+5 cascaded) bidirectional DC motor(s). - * Each halfbridge provides a high-Voltage (nominal 5.5-18 V) tristate output, - * which is also capable of PWM with 3 different frequencies. + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following + * disclaimer. * - * Have a look at the datasheet for more information. - */ - -/*! \file TLE94112_conf.h - * \brief This file is automatically included + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * */ - #ifndef TLE94112_CONF_H #define TLE94112_CONF_H @@ -50,5 +68,4 @@ typedef struct uint8_t dcShift; } PWMchannel_t; - #endif \ No newline at end of file