Library for MAX14871 Shield, MAXREFDES89#

Dependencies:   MAX5387 MAX7300

Dependents:   MAXREFDES89_MAX14871_Shield_Demo MAXREFDES89_Test_Program Line_Following_Bot Line_Following_Bot_Pololu

MAXREFDES89# Component Page

Committer:
j3
Date:
Sun Jul 26 22:19:50 2015 +0000
Revision:
1:7e9b864ddacf
Parent:
0:b5189f4ce1cb
Child:
3:89bf07b855e5
updated period, duty cycle, and vref to floats

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 0:b5189f4ce1cb 1 /******************************************************************//**
j3 1:7e9b864ddacf 2 * @file max14871_shield.h
j3 0:b5189f4ce1cb 3 *
j3 0:b5189f4ce1cb 4 * @author Justin Jordan
j3 0:b5189f4ce1cb 5 *
j3 0:b5189f4ce1cb 6 * @version 0.0
j3 0:b5189f4ce1cb 7 *
j3 0:b5189f4ce1cb 8 * Started: 18JUL15
j3 0:b5189f4ce1cb 9 *
j3 0:b5189f4ce1cb 10 * Updated:
j3 0:b5189f4ce1cb 11 *
j3 0:b5189f4ce1cb 12 * @brief Header file for Max14871_Shield class
j3 0:b5189f4ce1cb 13 ***********************************************************************
j3 0:b5189f4ce1cb 14 * Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved.
j3 0:b5189f4ce1cb 15 *
j3 0:b5189f4ce1cb 16 * Permission is hereby granted, free of charge, to any person obtaining a
j3 0:b5189f4ce1cb 17 * copy of this software and associated documentation files (the "Software"),
j3 0:b5189f4ce1cb 18 * to deal in the Software without restriction, including without limitation
j3 0:b5189f4ce1cb 19 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
j3 0:b5189f4ce1cb 20 * and/or sell copies of the Software, and to permit persons to whom the
j3 0:b5189f4ce1cb 21 * Software is furnished to do so, subject to the following conditions:
j3 0:b5189f4ce1cb 22 *
j3 0:b5189f4ce1cb 23 * The above copyright notice and this permission notice shall be included
j3 0:b5189f4ce1cb 24 * in all copies or substantial portions of the Software.
j3 0:b5189f4ce1cb 25 *
j3 0:b5189f4ce1cb 26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
j3 0:b5189f4ce1cb 27 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
j3 0:b5189f4ce1cb 28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
j3 0:b5189f4ce1cb 29 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
j3 0:b5189f4ce1cb 30 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
j3 0:b5189f4ce1cb 31 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
j3 0:b5189f4ce1cb 32 * OTHER DEALINGS IN THE SOFTWARE.
j3 0:b5189f4ce1cb 33 *
j3 0:b5189f4ce1cb 34 * Except as contained in this notice, the name of Maxim Integrated
j3 0:b5189f4ce1cb 35 * Products, Inc. shall not be used except as stated in the Maxim Integrated
j3 0:b5189f4ce1cb 36 * Products, Inc. Branding Policy.
j3 0:b5189f4ce1cb 37 *
j3 0:b5189f4ce1cb 38 * The mere transfer of this software does not imply any licenses
j3 0:b5189f4ce1cb 39 * of trade secrets, proprietary technology, copyrights, patents,
j3 0:b5189f4ce1cb 40 * trademarks, maskwork rights, or any other form of intellectual
j3 0:b5189f4ce1cb 41 * property whatsoever. Maxim Integrated Products, Inc. retains all
j3 0:b5189f4ce1cb 42 * ownership rights.
j3 0:b5189f4ce1cb 43 **********************************************************************/
j3 0:b5189f4ce1cb 44
j3 0:b5189f4ce1cb 45
j3 0:b5189f4ce1cb 46 #ifndef MAX14871_SHIELD_H
j3 0:b5189f4ce1cb 47 #define MAX14871_SHIELD_H
j3 0:b5189f4ce1cb 48
j3 0:b5189f4ce1cb 49 #include "mbed.h"
j3 0:b5189f4ce1cb 50 #include "max7300.h"
j3 0:b5189f4ce1cb 51 #include "max5387.h"
j3 0:b5189f4ce1cb 52
j3 0:b5189f4ce1cb 53
j3 0:b5189f4ce1cb 54 class Max14871_Shield
j3 0:b5189f4ce1cb 55 {
j3 0:b5189f4ce1cb 56 public:
j3 0:b5189f4ce1cb 57
j3 0:b5189f4ce1cb 58 typedef enum
j3 0:b5189f4ce1cb 59 {
j3 0:b5189f4ce1cb 60 MD1 = 1,
j3 0:b5189f4ce1cb 61 MD2,
j3 0:b5189f4ce1cb 62 MD3,
j3 0:b5189f4ce1cb 63 MD4
j3 0:b5189f4ce1cb 64 }max14871_motor_driver_t;
j3 0:b5189f4ce1cb 65
j3 0:b5189f4ce1cb 66
j3 0:b5189f4ce1cb 67 typedef enum
j3 0:b5189f4ce1cb 68 {
j3 0:b5189f4ce1cb 69 COAST = 1,
j3 0:b5189f4ce1cb 70 BRAKE,
j3 0:b5189f4ce1cb 71 REVERSE,
j3 0:b5189f4ce1cb 72 FORWARD
j3 0:b5189f4ce1cb 73 }max14871_operating_mode_t;
j3 0:b5189f4ce1cb 74
j3 0:b5189f4ce1cb 75
j3 0:b5189f4ce1cb 76 typedef enum
j3 0:b5189f4ce1cb 77 {
j3 0:b5189f4ce1cb 78 RIPPLE_25_INTERNAL_REF = 1,
j3 0:b5189f4ce1cb 79 RIPPLE_25_EXTERNAL_REF,
j3 0:b5189f4ce1cb 80 TCOFF_FAST_INTERNAL_REF,
j3 0:b5189f4ce1cb 81 TCOFF_SLOW_INTERNAL_REF,
j3 0:b5189f4ce1cb 82 TCOFF_FAST_EXTERNAL_REF,
j3 0:b5189f4ce1cb 83 TCOFF_SLOW_EXTERNAL_REF
j3 0:b5189f4ce1cb 84 }max14871_current_regulation_mode_t;
j3 0:b5189f4ce1cb 85
j3 0:b5189f4ce1cb 86
j3 0:b5189f4ce1cb 87 /**********************************************************//**
j3 0:b5189f4ce1cb 88 * @brief Constructor for Max14871_Shield Class.
j3 0:b5189f4ce1cb 89 *
j3 0:b5189f4ce1cb 90 * @details Allows user to use existing I2C object
j3 0:b5189f4ce1cb 91 *
j3 0:b5189f4ce1cb 92 * On Entry:
j3 0:b5189f4ce1cb 93 * @param[in] i2c_bus - pointer to existing I2C object
j3 0:b5189f4ce1cb 94 * @param[in] default_config - true if board uses default
j3 0:b5189f4ce1cb 95 * pwm channels and I2C addressing
j3 0:b5189f4ce1cb 96 *
j3 0:b5189f4ce1cb 97 * On Exit:
j3 0:b5189f4ce1cb 98 * @return none
j3 0:b5189f4ce1cb 99 **************************************************************/
j3 0:b5189f4ce1cb 100 Max14871_Shield(I2C *i2c_bus, bool default_config);
j3 0:b5189f4ce1cb 101
j3 0:b5189f4ce1cb 102
j3 0:b5189f4ce1cb 103 /**********************************************************//**
j3 0:b5189f4ce1cb 104 * @brief Constructor for Max14871_Shield Class.
j3 0:b5189f4ce1cb 105 *
j3 0:b5189f4ce1cb 106 * @details Allows user to create a new I2C object if not
j3 0:b5189f4ce1cb 107 * already using one
j3 0:b5189f4ce1cb 108 *
j3 0:b5189f4ce1cb 109 * On Entry:
j3 0:b5189f4ce1cb 110 * @param[in] sda - sda pin of I2C bus
j3 0:b5189f4ce1cb 111 * @param[in] scl - scl pin of I2C bus
j3 0:b5189f4ce1cb 112 * @param[in] default_config - true if board uses default
j3 0:b5189f4ce1cb 113 * pwm channels and I2C addressing
j3 0:b5189f4ce1cb 114 *
j3 0:b5189f4ce1cb 115 * On Exit:
j3 0:b5189f4ce1cb 116 * @return none
j3 0:b5189f4ce1cb 117 **************************************************************/
j3 0:b5189f4ce1cb 118 Max14871_Shield(PinName sda, PinName scl, bool default_config);
j3 0:b5189f4ce1cb 119
j3 0:b5189f4ce1cb 120
j3 0:b5189f4ce1cb 121 /**********************************************************//**
j3 0:b5189f4ce1cb 122 * @brief Default destructor for Max14871_Shield Class.
j3 0:b5189f4ce1cb 123 *
j3 0:b5189f4ce1cb 124 * @details Destroys I2C object if owner
j3 0:b5189f4ce1cb 125 *
j3 0:b5189f4ce1cb 126 * On Entry:
j3 0:b5189f4ce1cb 127 *
j3 0:b5189f4ce1cb 128 * On Exit:
j3 0:b5189f4ce1cb 129 * @return none
j3 0:b5189f4ce1cb 130 **************************************************************/
j3 0:b5189f4ce1cb 131 ~Max14871_Shield();
j3 0:b5189f4ce1cb 132
j3 0:b5189f4ce1cb 133
j3 0:b5189f4ce1cb 134 /**********************************************************//**
j3 0:b5189f4ce1cb 135 * @brief Set the operating mode of the motor driver
j3 0:b5189f4ce1cb 136 *
j3 0:b5189f4ce1cb 137 * @details Configures the /EN and DIR pins of the motor driver
j3 0:b5189f4ce1cb 138 * via the MAX7300 GPIO Expander
j3 0:b5189f4ce1cb 139 *
j3 0:b5189f4ce1cb 140 * On Entry:
j3 0:b5189f4ce1cb 141 * @param[in] md - 1 of 4 motor drivers on the shield
j3 0:b5189f4ce1cb 142 * @param[in] mode - 1 of 4 operating modes of the motor driver
j3 0:b5189f4ce1cb 143 *
j3 0:b5189f4ce1cb 144 * On Exit:
j3 0:b5189f4ce1cb 145 * @return 0 on success, non-0 on failure
j3 0:b5189f4ce1cb 146 **************************************************************/
j3 0:b5189f4ce1cb 147 int16_t set_operating_mode(max14871_motor_driver_t md,
j3 0:b5189f4ce1cb 148 max14871_operating_mode_t mode);
j3 0:b5189f4ce1cb 149
j3 0:b5189f4ce1cb 150
j3 0:b5189f4ce1cb 151 /**********************************************************//**
j3 0:b5189f4ce1cb 152 * @brief
j3 0:b5189f4ce1cb 153 *
j3 0:b5189f4ce1cb 154 * @details
j3 0:b5189f4ce1cb 155 *
j3 0:b5189f4ce1cb 156 * On Entry:
j3 0:b5189f4ce1cb 157 * @param[in] md - 1 of 4 motor drivers on the shield
j3 0:b5189f4ce1cb 158 * @param[in] mode - 1 of 6 current regulation modes of the
j3 0:b5189f4ce1cb 159 * motor driver
j3 1:7e9b864ddacf 160 * @param[in] vref - sets maximum motor current, Max of 2.0V
j3 0:b5189f4ce1cb 161 *
j3 0:b5189f4ce1cb 162 * On Exit:
j3 0:b5189f4ce1cb 163 * @return 0 on success, non-0 on failure
j3 0:b5189f4ce1cb 164 **************************************************************/
j3 0:b5189f4ce1cb 165 int16_t set_current_regulation_mode(max14871_motor_driver_t md,
j3 0:b5189f4ce1cb 166 max14871_current_regulation_mode_t mode,
j3 1:7e9b864ddacf 167 float vref);
j3 0:b5189f4ce1cb 168
j3 0:b5189f4ce1cb 169
j3 0:b5189f4ce1cb 170 /**********************************************************//**
j3 0:b5189f4ce1cb 171 * @brief Sets period of pwm signal for selected motor driver
j3 0:b5189f4ce1cb 172 *
j3 0:b5189f4ce1cb 173 * @details period must be in micro-seconds
j3 0:b5189f4ce1cb 174 *
j3 0:b5189f4ce1cb 175 * On Entry:
j3 0:b5189f4ce1cb 176 * @param[in] md - 1 of 4 motor drivers on the shield
j3 1:7e9b864ddacf 177 * @param[in] period - PWM period specified in seconds
j3 0:b5189f4ce1cb 178 *
j3 0:b5189f4ce1cb 179 * On Exit:
j3 0:b5189f4ce1cb 180 * @return 0 on success, non-0 on failure
j3 0:b5189f4ce1cb 181 **************************************************************/
j3 1:7e9b864ddacf 182 int16_t set_pwm_period(max14871_motor_driver_t md, float period);
j3 0:b5189f4ce1cb 183
j3 0:b5189f4ce1cb 184
j3 0:b5189f4ce1cb 185 /**********************************************************//**
j3 0:b5189f4ce1cb 186 * @brief Sets duty cycle of pwm signal for selected motor driver
j3 0:b5189f4ce1cb 187 *
j3 0:b5189f4ce1cb 188 * @details duty cycle must be in micro-seconds
j3 0:b5189f4ce1cb 189 *
j3 0:b5189f4ce1cb 190 * On Entry:
j3 0:b5189f4ce1cb 191 * @param[in] md - 1 of 4 motor drivers on the shield
j3 1:7e9b864ddacf 192 * @param[in] duty_cycle - duty cycle of the pwm signal specified
j3 1:7e9b864ddacf 193 * as a percentage
j3 0:b5189f4ce1cb 194 *
j3 0:b5189f4ce1cb 195 * On Exit:
j3 0:b5189f4ce1cb 196 * @return 0 on success, non-0 on failure
j3 0:b5189f4ce1cb 197 **************************************************************/
j3 1:7e9b864ddacf 198 int16_t set_pwm_duty_cycle(max14871_motor_driver_t md, float duty_cycle);
j3 0:b5189f4ce1cb 199
j3 0:b5189f4ce1cb 200
j3 0:b5189f4ce1cb 201 private:
j3 0:b5189f4ce1cb 202
j3 0:b5189f4ce1cb 203 I2C *_p_i2c;
j3 0:b5189f4ce1cb 204 Max7300 *_p_io_expander;
j3 0:b5189f4ce1cb 205 Max5387 *_p_digi_pot1;
j3 0:b5189f4ce1cb 206 Max5387 *_p_digi_pot2;
j3 0:b5189f4ce1cb 207 PwmOut *_p_pwm1;
j3 0:b5189f4ce1cb 208 PwmOut *_p_pwm2;
j3 0:b5189f4ce1cb 209 PwmOut *_p_pwm3;
j3 0:b5189f4ce1cb 210 PwmOut *_p_pwm4;
j3 0:b5189f4ce1cb 211
j3 0:b5189f4ce1cb 212 bool _i2c_owner;
j3 0:b5189f4ce1cb 213
j3 0:b5189f4ce1cb 214 void init_board(void);
j3 0:b5189f4ce1cb 215 };
j3 0:b5189f4ce1cb 216
j3 0:b5189f4ce1cb 217 #endif/* MAX14871_SHIELD_H */