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 Dec 22 04:24:07 2015 +0000
Revision:
5:a206f6505109
Parent:
3:89bf07b855e5
Child:
6:dc06cc75c1c8
Added set_pwm_channel member function

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 5:a206f6505109 171 * @brief Sets pwm channel for given motor driver
j3 5:a206f6505109 172 *
j3 5:a206f6505109 173 * @details Must use default, or alternate channel for specific
j3 5:a206f6505109 174 * motor driver. Function allows for mix of default and
j3 5:a206f6505109 175 * alternates for each motor driver vs all default or
j3 5:a206f6505109 176 * all alternate.
j3 5:a206f6505109 177 *
j3 5:a206f6505109 178 * On Entry:
j3 5:a206f6505109 179 * @param[in] md - 1 of 4 motor drivers on the shield
j3 5:a206f6505109 180 * @param[in] ch - PWM channel using Arduino naming convention
j3 5:a206f6505109 181 *
j3 5:a206f6505109 182 * On Exit:
j3 5:a206f6505109 183 * @return 0 on success, non-0 on failure
j3 5:a206f6505109 184 **************************************************************/
j3 5:a206f6505109 185 int16_t set_pwm_channel(max14871_motor_driver_t md, PinName ch);
j3 5:a206f6505109 186
j3 5:a206f6505109 187
j3 5:a206f6505109 188 /**********************************************************//**
j3 0:b5189f4ce1cb 189 * @brief Sets period of pwm signal for selected motor driver
j3 0:b5189f4ce1cb 190 *
j3 0:b5189f4ce1cb 191 * @details period must be in micro-seconds
j3 0:b5189f4ce1cb 192 *
j3 0:b5189f4ce1cb 193 * On Entry:
j3 0:b5189f4ce1cb 194 * @param[in] md - 1 of 4 motor drivers on the shield
j3 1:7e9b864ddacf 195 * @param[in] period - PWM period specified in seconds
j3 0:b5189f4ce1cb 196 *
j3 0:b5189f4ce1cb 197 * On Exit:
j3 0:b5189f4ce1cb 198 * @return 0 on success, non-0 on failure
j3 0:b5189f4ce1cb 199 **************************************************************/
j3 1:7e9b864ddacf 200 int16_t set_pwm_period(max14871_motor_driver_t md, float period);
j3 0:b5189f4ce1cb 201
j3 0:b5189f4ce1cb 202
j3 0:b5189f4ce1cb 203 /**********************************************************//**
j3 0:b5189f4ce1cb 204 * @brief Sets duty cycle of pwm signal for selected motor driver
j3 0:b5189f4ce1cb 205 *
j3 0:b5189f4ce1cb 206 * @details duty cycle must be in micro-seconds
j3 0:b5189f4ce1cb 207 *
j3 0:b5189f4ce1cb 208 * On Entry:
j3 0:b5189f4ce1cb 209 * @param[in] md - 1 of 4 motor drivers on the shield
j3 1:7e9b864ddacf 210 * @param[in] duty_cycle - duty cycle of the pwm signal specified
j3 1:7e9b864ddacf 211 * as a percentage
j3 0:b5189f4ce1cb 212 *
j3 0:b5189f4ce1cb 213 * On Exit:
j3 0:b5189f4ce1cb 214 * @return 0 on success, non-0 on failure
j3 0:b5189f4ce1cb 215 **************************************************************/
j3 1:7e9b864ddacf 216 int16_t set_pwm_duty_cycle(max14871_motor_driver_t md, float duty_cycle);
j3 3:89bf07b855e5 217
j3 3:89bf07b855e5 218
j3 3:89bf07b855e5 219 /**********************************************************//**
j3 3:89bf07b855e5 220 * @brief Get operating mode of selected motor driver
j3 3:89bf07b855e5 221 *
j3 3:89bf07b855e5 222 * @details
j3 3:89bf07b855e5 223 *
j3 3:89bf07b855e5 224 * On Entry:
j3 3:89bf07b855e5 225 * @param[in] md - 1 of 4 motor drivers on the shield
j3 3:89bf07b855e5 226 *
j3 3:89bf07b855e5 227 * On Exit:
j3 3:89bf07b855e5 228 * @return operating mode of selected motor driver
j3 3:89bf07b855e5 229 **************************************************************/
j3 3:89bf07b855e5 230 max14871_operating_mode_t get_operating_mode(max14871_motor_driver_t md);
j3 3:89bf07b855e5 231
j3 3:89bf07b855e5 232
j3 3:89bf07b855e5 233 /**********************************************************//**
j3 3:89bf07b855e5 234 * @brief Get current regulation mode of selected motor driver
j3 3:89bf07b855e5 235 *
j3 3:89bf07b855e5 236 * @details
j3 3:89bf07b855e5 237 *
j3 3:89bf07b855e5 238 * On Entry:
j3 3:89bf07b855e5 239 * @param[in] md - 1 of 4 motor drivers on the shield
j3 3:89bf07b855e5 240 *
j3 3:89bf07b855e5 241 * On Exit:
j3 3:89bf07b855e5 242 * @return current regulation mode of selected motor driver
j3 3:89bf07b855e5 243 **************************************************************/
j3 3:89bf07b855e5 244 max14871_current_regulation_mode_t get_current_regulation_mode(max14871_motor_driver_t md);
j3 3:89bf07b855e5 245
j3 3:89bf07b855e5 246
j3 3:89bf07b855e5 247 /**********************************************************//**
j3 3:89bf07b855e5 248 * @brief Get duty cycle of selected motor driver
j3 3:89bf07b855e5 249 *
j3 3:89bf07b855e5 250 * @details
j3 3:89bf07b855e5 251 *
j3 3:89bf07b855e5 252 * On Entry:
j3 3:89bf07b855e5 253 * @param[in] md - 1 of 4 motor drivers on the shield
j3 3:89bf07b855e5 254 *
j3 3:89bf07b855e5 255 * On Exit:
j3 3:89bf07b855e5 256 * @return duty cycle of selected motor driver
j3 3:89bf07b855e5 257 **************************************************************/
j3 3:89bf07b855e5 258 float get_pwm_duty_cycle(max14871_motor_driver_t md);
j3 3:89bf07b855e5 259
j3 3:89bf07b855e5 260
j3 3:89bf07b855e5 261 /**********************************************************//**
j3 5:a206f6505109 262 * @brief Get pwm period of selected motor driver
j3 5:a206f6505109 263 *
j3 5:a206f6505109 264 * @details
j3 5:a206f6505109 265 *
j3 5:a206f6505109 266 * On Entry:
j3 5:a206f6505109 267 * @param[in] md - 1 of 4 motor drivers on the shield
j3 5:a206f6505109 268 *
j3 5:a206f6505109 269 * On Exit:
j3 5:a206f6505109 270 * @return pwm period of selected motor driver
j3 5:a206f6505109 271 **************************************************************/
j3 5:a206f6505109 272 float get_pwm_period(max14871_motor_driver_t md);
j3 5:a206f6505109 273
j3 5:a206f6505109 274
j3 5:a206f6505109 275 /**********************************************************//**
j3 3:89bf07b855e5 276 * @brief Get external voltage reference of selected motor driver
j3 3:89bf07b855e5 277 *
j3 3:89bf07b855e5 278 * @details
j3 3:89bf07b855e5 279 *
j3 3:89bf07b855e5 280 * On Entry:
j3 3:89bf07b855e5 281 * @param[in] md - 1 of 4 motor drivers on the shield
j3 3:89bf07b855e5 282 *
j3 3:89bf07b855e5 283 * On Exit:
j3 3:89bf07b855e5 284 * @return external voltage reference of selected motor driver
j3 3:89bf07b855e5 285 **************************************************************/
j3 3:89bf07b855e5 286 float get_external_voltage_ref(max14871_motor_driver_t md);
j3 0:b5189f4ce1cb 287
j3 0:b5189f4ce1cb 288
j3 0:b5189f4ce1cb 289 private:
j3 0:b5189f4ce1cb 290
j3 3:89bf07b855e5 291 struct motor_data_s
j3 3:89bf07b855e5 292 {
j3 3:89bf07b855e5 293 max14871_operating_mode_t op_mode;
j3 3:89bf07b855e5 294 max14871_current_regulation_mode_t i_reg_mode;
j3 3:89bf07b855e5 295 float duty_cycle;
j3 5:a206f6505109 296 float period;
j3 3:89bf07b855e5 297 float v_ref;
j3 3:89bf07b855e5 298 };
j3 3:89bf07b855e5 299
j3 3:89bf07b855e5 300 struct motor_data_s _motor_data_array[4];
j3 3:89bf07b855e5 301
j3 0:b5189f4ce1cb 302 I2C *_p_i2c;
j3 0:b5189f4ce1cb 303 Max7300 *_p_io_expander;
j3 0:b5189f4ce1cb 304 Max5387 *_p_digi_pot1;
j3 0:b5189f4ce1cb 305 Max5387 *_p_digi_pot2;
j3 0:b5189f4ce1cb 306 PwmOut *_p_pwm1;
j3 0:b5189f4ce1cb 307 PwmOut *_p_pwm2;
j3 0:b5189f4ce1cb 308 PwmOut *_p_pwm3;
j3 0:b5189f4ce1cb 309 PwmOut *_p_pwm4;
j3 0:b5189f4ce1cb 310
j3 0:b5189f4ce1cb 311 bool _i2c_owner;
j3 0:b5189f4ce1cb 312
j3 0:b5189f4ce1cb 313 void init_board(void);
j3 0:b5189f4ce1cb 314 };
j3 0:b5189f4ce1cb 315
j3 0:b5189f4ce1cb 316 #endif/* MAX14871_SHIELD_H */