Library for driving the IBT-2 H-bridge motor controller (with BTS 7960 or BTN 7971 half bridges).

See the Wiki tab for example code.

Committer:
rwunderl
Date:
Fri Jul 31 20:30:06 2015 +0000
Revision:
1:fe72c69ab361
Parent:
0:ea214158c2fb
Edited some documentation. No functional changes.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rwunderl 0:ea214158c2fb 1 /* mbed IBT-2 H-bridge motor controller
rwunderl 0:ea214158c2fb 2 * Copyright (c) 2015, rwunderl, http://mbed.org
rwunderl 0:ea214158c2fb 3 *
rwunderl 0:ea214158c2fb 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
rwunderl 0:ea214158c2fb 5 * of this software and associated documentation files (the "Software"), to deal
rwunderl 0:ea214158c2fb 6 * in the Software without restriction, including without limitation the rights
rwunderl 0:ea214158c2fb 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
rwunderl 0:ea214158c2fb 8 * copies of the Software, and to permit persons to whom the Software is
rwunderl 0:ea214158c2fb 9 * furnished to do so, subject to the following conditions:
rwunderl 0:ea214158c2fb 10 *
rwunderl 0:ea214158c2fb 11 * The above copyright notice and this permission notice shall be included in
rwunderl 0:ea214158c2fb 12 * all copies or substantial portions of the Software.
rwunderl 0:ea214158c2fb 13 *
rwunderl 0:ea214158c2fb 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
rwunderl 0:ea214158c2fb 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
rwunderl 0:ea214158c2fb 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
rwunderl 0:ea214158c2fb 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
rwunderl 0:ea214158c2fb 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
rwunderl 0:ea214158c2fb 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
rwunderl 0:ea214158c2fb 20 * THE SOFTWARE.
rwunderl 0:ea214158c2fb 21 */
rwunderl 0:ea214158c2fb 22
rwunderl 0:ea214158c2fb 23 #ifndef MBED_IBT2_H
rwunderl 0:ea214158c2fb 24 #define MBED_IBT2_H
rwunderl 0:ea214158c2fb 25
rwunderl 0:ea214158c2fb 26 #include "mbed.h"
rwunderl 0:ea214158c2fb 27
rwunderl 0:ea214158c2fb 28 /** Interface to the IBT-2 H-bridge motor controller
rwunderl 0:ea214158c2fb 29 *
rwunderl 0:ea214158c2fb 30 * Control a DC motor connected to the IBT-2 H-bridge using one of two modes:
rwunderl 1:fe72c69ab361 31 *
rwunderl 0:ea214158c2fb 32 * Mode 1:
rwunderl 0:ea214158c2fb 33 * 2 PwmOuts and 1 DigitalOut
rwunderl 0:ea214158c2fb 34 * - L_PWM controlled with a PwmOut
rwunderl 0:ea214158c2fb 35 * - R_PWM controlled with a PwmOut
rwunderl 0:ea214158c2fb 36 * - L_EN, R_EN connected to a DigitalOut (High is Enabled)
rwunderl 1:fe72c69ab361 37 *
rwunderl 1:fe72c69ab361 38 * Mode 2:
rwunderl 1:fe72c69ab361 39 * 1 PwmOut and 2 DigitalOuts
rwunderl 1:fe72c69ab361 40 * - L_PWM connected to a DigitalOut (High is Forward; keep R_PWM Low)
rwunderl 1:fe72c69ab361 41 * - R_PWM connected to a DigitalOut (High is Reverse; keep L_PWM Low)
rwunderl 1:fe72c69ab361 42 * - L_EN, R_EN controlled with a PwmOut
rwunderl 1:fe72c69ab361 43 *
rwunderl 0:ea214158c2fb 44 * For now, only Mode 1 is used.
rwunderl 0:ea214158c2fb 45 */
rwunderl 0:ea214158c2fb 46 class IBT2 {
rwunderl 0:ea214158c2fb 47 public:
rwunderl 0:ea214158c2fb 48 /** Create an IBT-2 control interface
rwunderl 0:ea214158c2fb 49 *
rwunderl 0:ea214158c2fb 50 * @param L_pwm A PwmOut pin, driving the L_PWM H-bridge line to control the forward speed.
rwunderl 0:ea214158c2fb 51 * @param R_pwm A PwmOut pin, driving the R_PWM H-bridge line to control the reverse speed.
rwunderl 0:ea214158c2fb 52 * @param en A DigitalOut pin, driving the L_EN and R_EN H-bridge enable lines.
rwunderl 0:ea214158c2fb 53 * @param freq The frequency of the H-bridge PWM lines in Hz.
rwunderl 0:ea214158c2fb 54 */
rwunderl 0:ea214158c2fb 55 IBT2(PinName L_pwm, PinName R_pwm, PinName en, float freq);
rwunderl 0:ea214158c2fb 56
rwunderl 0:ea214158c2fb 57 /** Set the speed and direction of the motor
rwunderl 0:ea214158c2fb 58 *
rwunderl 0:ea214158c2fb 59 * @param speed The speed of the motor as a normalized value between -1.0 and 1.0. Use a positive value for forward and a negative value for reverse.
rwunderl 0:ea214158c2fb 60 */
rwunderl 0:ea214158c2fb 61 void setSpeed(float speed);
rwunderl 0:ea214158c2fb 62
rwunderl 0:ea214158c2fb 63 /** Get the speed and direction of the motor
rwunderl 0:ea214158c2fb 64 *
rwunderl 1:fe72c69ab361 65 * @returns The speed of the motor as a normalized value between -1.0 and 1.0. A positive value is forward and a negative value is reverse.
rwunderl 0:ea214158c2fb 66 */
rwunderl 0:ea214158c2fb 67 float getSpeed(void);
rwunderl 0:ea214158c2fb 68
rwunderl 0:ea214158c2fb 69 protected:
rwunderl 0:ea214158c2fb 70 PwmOut _L_pwm;
rwunderl 0:ea214158c2fb 71 PwmOut _R_pwm;
rwunderl 0:ea214158c2fb 72 DigitalOut _en;
rwunderl 0:ea214158c2fb 73 float _period;
rwunderl 0:ea214158c2fb 74 float _speed;
rwunderl 0:ea214158c2fb 75 };
rwunderl 0:ea214158c2fb 76
rwunderl 0:ea214158c2fb 77 #endif /* MBED_IBT2_H */