Kenji Arai / DRV8830

Dependents:   NucleoF401_motor_test_simple Frequency_Counter_w_GPS_1PPS Nucleo_ACM1602_I2C_DC_Angle Frequency_Cntr_1PPS_F746ZG

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DRV8830.h Source File

DRV8830.h

00001 /*
00002  * mbed library program 
00003  *  Texas Instruments / DRV8830 H-Bridge Voltage-Controlled Motor Driver
00004  *      http://www.ti.com/product/drv8830
00005  *
00006  * Copyright (c) 2014,'17 Kenji Arai / JH1PJL
00007  *  http://www.page.sannet.ne.jp/kenjia/index.html
00008  *  http://mbed.org/users/kenjiArai/
00009  *      Created: August      6th, 2014
00010  *      Revised: August     23rd, 2017
00011  */
00012 
00013 #ifndef        MBED_DRV8830
00014 #define        MBED_DRV8830
00015 
00016 // DRV8830 LOW-VOLTAGE MOTOR DRIVER WITH SERIAL INTERFACE
00017 //  7bit address = 0b01100000(0x60) -> 8bit = 0b11000000(0xc0) -> 0xc1(Read) or 0xc0(Write)
00018 //  ADDR_01 = (A1=0)+(A0=1), ADDR_1N = (A1=1)+(A0=No Connection)
00019 //      -> Please make sure your H/W configuration
00020 #define DRV8830ADDR_00          0xc0
00021 #define DRV8830ADDR_0N          0xc2
00022 #define DRV8830ADDR_01          0xc4
00023 #define DRV8830ADDR_N0          0xc6
00024 #define DRV8830ADDR_NN          0xc8
00025 #define DRV8830ADDR_N1          0xca
00026 #define DRV8830ADDR_10          0xcc
00027 #define DRV8830ADDR_1N          0xce
00028 #define DRV8830ADDR_11          0xd0
00029 
00030 //  fault status
00031 #define DRV8830_F_ILIMIT        0x10
00032 #define DRV8830_F_OTS           0x08
00033 #define DRV8830_F_UVLO          0x04
00034 #define DRV8830_F_OCP           0x02
00035 #define DRV8830_F_FAULT         0x01
00036 
00037 /** DRV8830 class
00038  *
00039  *  This is a driver code for the DRV8830 H-Bridge Voltage-Controlled Motor Driver.
00040  *    http://www.ti.com/product/drv8830
00041  *
00042  * @code
00043  * #include "mbed.h"
00044  * #include "DRV8830.h"
00045  *
00046  * // I2C Communication
00047  * DRV8830 motor(PinName p_sda, PinName p_scl, addr);
00048  * // If you connected I2C line not only this device but also other devices,
00049  * //     you need to declare following method.
00050  * I2C     i2c(PinName p_sda, PinName p_scl);
00051  * DRV8830 motor(I2C& p_i2c, addr);
00052  * 
00053  * int main() {
00054  * uint8_t status;
00055  *    
00056  *     //  Speed control
00057  *     motor.speed(0.5);    // CW
00058  *     motor.speed(-0.5);   // CCW
00059  *     motor.speed(0.0);    // Stop(FREE)
00060  *     //  Check error and reset
00061  *     status = motor.status();
00062  *     if (status & DRV8830_F_FAULT){
00063  *        motor.reset();
00064  *     } 
00065  * }
00066  *  @endcode
00067  */
00068 
00069 class DRV8830 {
00070 public:
00071     /** Configure data pin
00072       * @param data SDA and SCL pins
00073       * @param DRV8830 address (H/W configuration of A1,A0)
00074       */
00075     DRV8830(PinName p_sda, PinName p_scl, uint8_t addr);
00076     
00077     /** Configure data pin (with other devices on I2C line)
00078       * @param I2C previous definition
00079       * @param DRV8830 address (H/W configuration of A1,A0)
00080       */
00081     DRV8830(I2C& p_i2c, uint8_t addr);
00082 
00083     /** Set motor speed
00084       * @param speed (Range 0 to 1.0 or 0 to -1.0)
00085       * @return none
00086       */
00087     void speed(float speed);
00088 
00089     /** Set voltage
00090       * @param voltage (0 to 5V)
00091       * @return none
00092       */
00093     void set_voltage(float volt);
00094    
00095     /** Read status
00096       * @param none
00097       * @return FAULT register content
00098       */
00099     uint8_t status();
00100 
00101     /** Reset DRV8830 chip
00102       * @param none
00103       * @return none
00104       */
00105     void reset();
00106 
00107 protected:
00108     I2C *_i2c_p;
00109     I2C &_i2c;
00110 
00111 private:
00112     char DRV8830_addr;
00113 };
00114 
00115 #endif  //  MBED_DRV8830
00116