DRV8830/Texas Instruments H-Bridge Voltage-Controlled Motor Driver library for Brushed DC Motor
Dependents: NucleoF401_motor_test_simple Frequency_Counter_w_GPS_1PPS Nucleo_ACM1602_I2C_DC_Angle Frequency_Cntr_1PPS_F746ZG
Diff: DRV8830.h
- Revision:
- 0:05db098cf4f8
- Child:
- 1:a9b58bc85be0
diff -r 000000000000 -r 05db098cf4f8 DRV8830.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DRV8830.h Sat Aug 23 11:18:06 2014 +0000 @@ -0,0 +1,114 @@ +/* + * mbed library program + * Texas Instruments / DRV8830 H-Bridge Voltage-Controlled Motor Driver + * http://www.ti.com/product/drv8830 + * + * Copyright (c) 2014 Kenji Arai / JH1PJL + * http://www.page.sannet.ne.jp/kenjia/index.html + * http://mbed.org/users/kenjiArai/ + * Created: August 6th, 2014 + * Revised: August 16th, 2014 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef MBED_DRV8830 +#define MBED_DRV8830 + +// DRV8830 LOW-VOLTAGE MOTOR DRIVER WITH SERIAL INTERFACE +// 7bit address = 0b01100000(0x60) -> 8bit = 0b11000000(0xc0) -> 0xc1(Read) or 0xc0(Write) +// ADDR_01 = (A1=0)+(A0=1), ADDR_1N = (A1=1)+(A0=No Connection) +// -> Please make sure your H/W configuration +#define DRV8830ADDR_00 0xc0 +#define DRV8830ADDR_0N 0xc2 +#define DRV8830ADDR_01 0xc4 +#define DRV8830ADDR_N0 0xc6 +#define DRV8830ADDR_NN 0xc8 +#define DRV8830ADDR_N1 0xca +#define DRV8830ADDR_10 0xcc +#define DRV8830ADDR_1N 0xce +#define DRV8830ADDR_11 0xd0 + +// fault status +#define DRV8830_F_ILIMIT 0x10 +#define DRV8830_F_OTS 0x08 +#define DRV8830_F_UVLO 0x04 +#define DRV8830_F_OCP 0x02 +#define DRV8830_F_FAULT 0x01 + +/** DRV8830 class + * + * This is a driver code for the DRV8830 H-Bridge Voltage-Controlled Motor Driver. + * http://www.ti.com/product/drv8830 + * + * @code + * #include "mbed.h" + * #include "DRV8830.h" + * + * // I2C Communication + * DRV8830 motor(PinName p_sda, PinName p_scl, addr); + * // If you connected I2C line not only this device but also other devices, + * // you need to declare following method. + * I2C i2c(PinName p_sda, PinName p_scl); + * DRV8830 motor(I2C& p_i2c, addr); + * + * int main() { + * uint8_t status; + * + * // Speed control + * motor.speed(0.5); // CW + * motor.speed(-0.5); // CCW + * motor.speed(0.0); // Stop(FREE) + * // Check error and reset + * status = motor.status(); + * if (status & DRV8830_F_FAULT){ + * motor.reset(); + * } + * } + * @endcode + */ + +class DRV8830 { +public: + /** Configure data pin + * @param data SDA and SCL pins + * @param DRV8830 address (H/W configuration of A1,A0) + */ + DRV8830(PinName p_sda, PinName p_scl, uint8_t addr); + + /** Configure data pin (with other devices on I2C line) + * @param I2C previous definition + * @param DRV8830 address (H/W configuration of A1,A0) + */ + DRV8830(I2C& p_i2c, uint8_t addr); + + /** Set motor speed + * @param speed (Range 0 to 1.0 or 0 to -1.0) + * @return none + */ + void speed(float speed); + + /** Read status + * @param none + * @return FAULT register content + */ + uint8_t status(); + + /** Reset DRV8830 chip + * @param none + * @return none + */ + void reset(); + +protected: + I2C i2c; + +private: + char DRV8830_addr; +}; + +#endif // MBED_DRV8830