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:
Tue Aug 11 04:11:46 2015 +0000
Revision:
3:89bf07b855e5
Parent:
1:7e9b864ddacf
Child:
5:a206f6505109
added get fxs

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 3:89bf07b855e5 199
j3 3:89bf07b855e5 200
j3 3:89bf07b855e5 201 /**********************************************************//**
j3 3:89bf07b855e5 202 * @brief Get operating mode of selected motor driver
j3 3:89bf07b855e5 203 *
j3 3:89bf07b855e5 204 * @details
j3 3:89bf07b855e5 205 *
j3 3:89bf07b855e5 206 * On Entry:
j3 3:89bf07b855e5 207 * @param[in] md - 1 of 4 motor drivers on the shield
j3 3:89bf07b855e5 208 *
j3 3:89bf07b855e5 209 * On Exit:
j3 3:89bf07b855e5 210 * @return operating mode of selected motor driver
j3 3:89bf07b855e5 211 **************************************************************/
j3 3:89bf07b855e5 212 max14871_operating_mode_t get_operating_mode(max14871_motor_driver_t md);
j3 3:89bf07b855e5 213
j3 3:89bf07b855e5 214
j3 3:89bf07b855e5 215 /**********************************************************//**
j3 3:89bf07b855e5 216 * @brief Get current regulation mode of selected motor driver
j3 3:89bf07b855e5 217 *
j3 3:89bf07b855e5 218 * @details
j3 3:89bf07b855e5 219 *
j3 3:89bf07b855e5 220 * On Entry:
j3 3:89bf07b855e5 221 * @param[in] md - 1 of 4 motor drivers on the shield
j3 3:89bf07b855e5 222 *
j3 3:89bf07b855e5 223 * On Exit:
j3 3:89bf07b855e5 224 * @return current regulation mode of selected motor driver
j3 3:89bf07b855e5 225 **************************************************************/
j3 3:89bf07b855e5 226 max14871_current_regulation_mode_t get_current_regulation_mode(max14871_motor_driver_t md);
j3 3:89bf07b855e5 227
j3 3:89bf07b855e5 228
j3 3:89bf07b855e5 229 /**********************************************************//**
j3 3:89bf07b855e5 230 * @brief Get duty cycle of selected motor driver
j3 3:89bf07b855e5 231 *
j3 3:89bf07b855e5 232 * @details
j3 3:89bf07b855e5 233 *
j3 3:89bf07b855e5 234 * On Entry:
j3 3:89bf07b855e5 235 * @param[in] md - 1 of 4 motor drivers on the shield
j3 3:89bf07b855e5 236 *
j3 3:89bf07b855e5 237 * On Exit:
j3 3:89bf07b855e5 238 * @return duty cycle of selected motor driver
j3 3:89bf07b855e5 239 **************************************************************/
j3 3:89bf07b855e5 240 float get_pwm_duty_cycle(max14871_motor_driver_t md);
j3 3:89bf07b855e5 241
j3 3:89bf07b855e5 242
j3 3:89bf07b855e5 243 /**********************************************************//**
j3 3:89bf07b855e5 244 * @brief Get external voltage reference of selected motor driver
j3 3:89bf07b855e5 245 *
j3 3:89bf07b855e5 246 * @details
j3 3:89bf07b855e5 247 *
j3 3:89bf07b855e5 248 * On Entry:
j3 3:89bf07b855e5 249 * @param[in] md - 1 of 4 motor drivers on the shield
j3 3:89bf07b855e5 250 *
j3 3:89bf07b855e5 251 * On Exit:
j3 3:89bf07b855e5 252 * @return external voltage reference of selected motor driver
j3 3:89bf07b855e5 253 **************************************************************/
j3 3:89bf07b855e5 254 float get_external_voltage_ref(max14871_motor_driver_t md);
j3 0:b5189f4ce1cb 255
j3 0:b5189f4ce1cb 256
j3 0:b5189f4ce1cb 257 private:
j3 0:b5189f4ce1cb 258
j3 3:89bf07b855e5 259 struct motor_data_s
j3 3:89bf07b855e5 260 {
j3 3:89bf07b855e5 261 max14871_operating_mode_t op_mode;
j3 3:89bf07b855e5 262 max14871_current_regulation_mode_t i_reg_mode;
j3 3:89bf07b855e5 263 float duty_cycle;
j3 3:89bf07b855e5 264 float v_ref;
j3 3:89bf07b855e5 265 };
j3 3:89bf07b855e5 266
j3 3:89bf07b855e5 267 struct motor_data_s _motor_data_array[4];
j3 3:89bf07b855e5 268
j3 0:b5189f4ce1cb 269 I2C *_p_i2c;
j3 0:b5189f4ce1cb 270 Max7300 *_p_io_expander;
j3 0:b5189f4ce1cb 271 Max5387 *_p_digi_pot1;
j3 0:b5189f4ce1cb 272 Max5387 *_p_digi_pot2;
j3 0:b5189f4ce1cb 273 PwmOut *_p_pwm1;
j3 0:b5189f4ce1cb 274 PwmOut *_p_pwm2;
j3 0:b5189f4ce1cb 275 PwmOut *_p_pwm3;
j3 0:b5189f4ce1cb 276 PwmOut *_p_pwm4;
j3 0:b5189f4ce1cb 277
j3 0:b5189f4ce1cb 278 bool _i2c_owner;
j3 0:b5189f4ce1cb 279
j3 0:b5189f4ce1cb 280 void init_board(void);
j3 0:b5189f4ce1cb 281 };
j3 0:b5189f4ce1cb 282
j3 0:b5189f4ce1cb 283 #endif/* MAX14871_SHIELD_H */