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:
Mon Aug 15 19:22:31 2016 +0000
Revision:
7:c0bee1397f3e
Parent:
6:dc06cc75c1c8
Added default value of true for default_config in constructor;; Changing operating mode to coast no longer clears duty cycle to 0

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 * Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved.
j3 0:b5189f4ce1cb 4 *
j3 0:b5189f4ce1cb 5 * Permission is hereby granted, free of charge, to any person obtaining a
j3 0:b5189f4ce1cb 6 * copy of this software and associated documentation files (the "Software"),
j3 0:b5189f4ce1cb 7 * to deal in the Software without restriction, including without limitation
j3 0:b5189f4ce1cb 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
j3 0:b5189f4ce1cb 9 * and/or sell copies of the Software, and to permit persons to whom the
j3 0:b5189f4ce1cb 10 * Software is furnished to do so, subject to the following conditions:
j3 0:b5189f4ce1cb 11 *
j3 0:b5189f4ce1cb 12 * The above copyright notice and this permission notice shall be included
j3 0:b5189f4ce1cb 13 * in all copies or substantial portions of the Software.
j3 0:b5189f4ce1cb 14 *
j3 0:b5189f4ce1cb 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
j3 0:b5189f4ce1cb 16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
j3 0:b5189f4ce1cb 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
j3 0:b5189f4ce1cb 18 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
j3 0:b5189f4ce1cb 19 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
j3 0:b5189f4ce1cb 20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
j3 0:b5189f4ce1cb 21 * OTHER DEALINGS IN THE SOFTWARE.
j3 0:b5189f4ce1cb 22 *
j3 0:b5189f4ce1cb 23 * Except as contained in this notice, the name of Maxim Integrated
j3 0:b5189f4ce1cb 24 * Products, Inc. shall not be used except as stated in the Maxim Integrated
j3 0:b5189f4ce1cb 25 * Products, Inc. Branding Policy.
j3 0:b5189f4ce1cb 26 *
j3 0:b5189f4ce1cb 27 * The mere transfer of this software does not imply any licenses
j3 0:b5189f4ce1cb 28 * of trade secrets, proprietary technology, copyrights, patents,
j3 0:b5189f4ce1cb 29 * trademarks, maskwork rights, or any other form of intellectual
j3 0:b5189f4ce1cb 30 * property whatsoever. Maxim Integrated Products, Inc. retains all
j3 0:b5189f4ce1cb 31 * ownership rights.
j3 0:b5189f4ce1cb 32 **********************************************************************/
j3 0:b5189f4ce1cb 33
j3 0:b5189f4ce1cb 34
j3 0:b5189f4ce1cb 35 #ifndef MAX14871_SHIELD_H
j3 0:b5189f4ce1cb 36 #define MAX14871_SHIELD_H
j3 0:b5189f4ce1cb 37
j3 0:b5189f4ce1cb 38 #include "mbed.h"
j3 0:b5189f4ce1cb 39 #include "max7300.h"
j3 0:b5189f4ce1cb 40 #include "max5387.h"
j3 0:b5189f4ce1cb 41
j3 0:b5189f4ce1cb 42
j3 6:dc06cc75c1c8 43 /**
j3 6:dc06cc75c1c8 44 * @brief MAX14871 Full-Bridge DC Motor Driver MBED Shield Library
j3 6:dc06cc75c1c8 45 *
j3 6:dc06cc75c1c8 46 * @details The MAXREFDES89# provides an ideal interface for anyone
j3 6:dc06cc75c1c8 47 * developing with brushed DC motors. The design is an
j3 6:dc06cc75c1c8 48 * mbed®-compatible, Arduino® form factor shield for the rapid
j3 6:dc06cc75c1c8 49 * development of brushed DC motor applications. The shield contains
j3 6:dc06cc75c1c8 50 * four MAX14871 full-bridge DC motor drivers for driving up to 4
j3 6:dc06cc75c1c8 51 * motors. A MAX17501 DC-DC converter allows the system to operate
j3 6:dc06cc75c1c8 52 * from a single 7 to 36VDC power supply. Four MAX4704 4:1
j3 6:dc06cc75c1c8 53 * multiplexers permit setting the current regulation mode of the
j3 6:dc06cc75c1c8 54 * MAX14871, while two MAX5387 digital potentiometers provide the
j3 6:dc06cc75c1c8 55 * ability to set the motor current limit. A MAX7300 GPIO expander
j3 6:dc06cc75c1c8 56 * supports interfacing each motor driver circuit to the
j3 6:dc06cc75c1c8 57 * mbed-enabled microcontroller platform.
j3 6:dc06cc75c1c8 58 *
j3 6:dc06cc75c1c8 59 * @code
j3 6:dc06cc75c1c8 60 * @endcode
j3 6:dc06cc75c1c8 61 */
j3 0:b5189f4ce1cb 62 class Max14871_Shield
j3 0:b5189f4ce1cb 63 {
j3 0:b5189f4ce1cb 64 public:
j3 0:b5189f4ce1cb 65
j3 6:dc06cc75c1c8 66 /**
j3 6:dc06cc75c1c8 67 * @brief Motor driver channels
j3 6:dc06cc75c1c8 68 * @details Simple enumeration of channels available on the shield
j3 6:dc06cc75c1c8 69 */
j3 0:b5189f4ce1cb 70 typedef enum
j3 0:b5189f4ce1cb 71 {
j3 0:b5189f4ce1cb 72 MD1 = 1,
j3 0:b5189f4ce1cb 73 MD2,
j3 0:b5189f4ce1cb 74 MD3,
j3 0:b5189f4ce1cb 75 MD4
j3 0:b5189f4ce1cb 76 }max14871_motor_driver_t;
j3 0:b5189f4ce1cb 77
j3 0:b5189f4ce1cb 78
j3 6:dc06cc75c1c8 79 /**
j3 6:dc06cc75c1c8 80 * @brief Operating modes
j3 6:dc06cc75c1c8 81 * @details Motor operating modes offered on each channel
j3 6:dc06cc75c1c8 82 */
j3 0:b5189f4ce1cb 83 typedef enum
j3 0:b5189f4ce1cb 84 {
j3 0:b5189f4ce1cb 85 COAST = 1,
j3 0:b5189f4ce1cb 86 BRAKE,
j3 0:b5189f4ce1cb 87 REVERSE,
j3 0:b5189f4ce1cb 88 FORWARD
j3 0:b5189f4ce1cb 89 }max14871_operating_mode_t;
j3 0:b5189f4ce1cb 90
j3 0:b5189f4ce1cb 91
j3 6:dc06cc75c1c8 92 /**
j3 6:dc06cc75c1c8 93 * @brief Current regulation modes
j3 6:dc06cc75c1c8 94 * @details Three different current regulation modes offered with
j3 6:dc06cc75c1c8 95 * either an internal or external reference for setting the regulation limit.
j3 6:dc06cc75c1c8 96 * This is not the fault current which is fixed, see datasheet.
j3 6:dc06cc75c1c8 97 */
j3 0:b5189f4ce1cb 98 typedef enum
j3 0:b5189f4ce1cb 99 {
j3 0:b5189f4ce1cb 100 RIPPLE_25_INTERNAL_REF = 1,
j3 0:b5189f4ce1cb 101 RIPPLE_25_EXTERNAL_REF,
j3 0:b5189f4ce1cb 102 TCOFF_FAST_INTERNAL_REF,
j3 0:b5189f4ce1cb 103 TCOFF_SLOW_INTERNAL_REF,
j3 0:b5189f4ce1cb 104 TCOFF_FAST_EXTERNAL_REF,
j3 0:b5189f4ce1cb 105 TCOFF_SLOW_EXTERNAL_REF
j3 0:b5189f4ce1cb 106 }max14871_current_regulation_mode_t;
j3 0:b5189f4ce1cb 107
j3 0:b5189f4ce1cb 108
j3 0:b5189f4ce1cb 109 /**********************************************************//**
j3 0:b5189f4ce1cb 110 * @brief Constructor for Max14871_Shield Class.
j3 0:b5189f4ce1cb 111 *
j3 0:b5189f4ce1cb 112 * @details Allows user to use existing I2C object
j3 0:b5189f4ce1cb 113 *
j3 0:b5189f4ce1cb 114 * On Entry:
j3 0:b5189f4ce1cb 115 * @param[in] i2c_bus - pointer to existing I2C object
j3 0:b5189f4ce1cb 116 * @param[in] default_config - true if board uses default
j3 0:b5189f4ce1cb 117 * pwm channels and I2C addressing
j3 0:b5189f4ce1cb 118 *
j3 0:b5189f4ce1cb 119 * On Exit:
j3 6:dc06cc75c1c8 120 *
j3 6:dc06cc75c1c8 121 * @return None
j3 0:b5189f4ce1cb 122 **************************************************************/
j3 7:c0bee1397f3e 123 Max14871_Shield(I2C *i2c_bus, bool default_config = true);
j3 0:b5189f4ce1cb 124
j3 0:b5189f4ce1cb 125
j3 0:b5189f4ce1cb 126 /**********************************************************//**
j3 0:b5189f4ce1cb 127 * @brief Constructor for Max14871_Shield Class.
j3 0:b5189f4ce1cb 128 *
j3 0:b5189f4ce1cb 129 * @details Allows user to create a new I2C object if not
j3 0:b5189f4ce1cb 130 * already using one
j3 0:b5189f4ce1cb 131 *
j3 0:b5189f4ce1cb 132 * On Entry:
j3 0:b5189f4ce1cb 133 * @param[in] sda - sda pin of I2C bus
j3 0:b5189f4ce1cb 134 * @param[in] scl - scl pin of I2C bus
j3 0:b5189f4ce1cb 135 * @param[in] default_config - true if board uses default
j3 0:b5189f4ce1cb 136 * pwm channels and I2C addressing
j3 0:b5189f4ce1cb 137 *
j3 0:b5189f4ce1cb 138 * On Exit:
j3 6:dc06cc75c1c8 139 *
j3 6:dc06cc75c1c8 140 * @return None
j3 0:b5189f4ce1cb 141 **************************************************************/
j3 7:c0bee1397f3e 142 Max14871_Shield(PinName sda, PinName scl, bool default_config = true);
j3 0:b5189f4ce1cb 143
j3 0:b5189f4ce1cb 144
j3 0:b5189f4ce1cb 145 /**********************************************************//**
j3 0:b5189f4ce1cb 146 * @brief Default destructor for Max14871_Shield Class.
j3 0:b5189f4ce1cb 147 *
j3 0:b5189f4ce1cb 148 * @details Destroys I2C object if owner
j3 0:b5189f4ce1cb 149 *
j3 0:b5189f4ce1cb 150 * On Entry:
j3 0:b5189f4ce1cb 151 *
j3 0:b5189f4ce1cb 152 * On Exit:
j3 6:dc06cc75c1c8 153 *
j3 6:dc06cc75c1c8 154 * @return None
j3 0:b5189f4ce1cb 155 **************************************************************/
j3 0:b5189f4ce1cb 156 ~Max14871_Shield();
j3 0:b5189f4ce1cb 157
j3 0:b5189f4ce1cb 158
j3 0:b5189f4ce1cb 159 /**********************************************************//**
j3 0:b5189f4ce1cb 160 * @brief Set the operating mode of the motor driver
j3 0:b5189f4ce1cb 161 *
j3 0:b5189f4ce1cb 162 * @details Configures the /EN and DIR pins of the motor driver
j3 0:b5189f4ce1cb 163 * via the MAX7300 GPIO Expander
j3 0:b5189f4ce1cb 164 *
j3 0:b5189f4ce1cb 165 * On Entry:
j3 0:b5189f4ce1cb 166 * @param[in] md - 1 of 4 motor drivers on the shield
j3 0:b5189f4ce1cb 167 * @param[in] mode - 1 of 4 operating modes of the motor driver
j3 0:b5189f4ce1cb 168 *
j3 0:b5189f4ce1cb 169 * On Exit:
j3 6:dc06cc75c1c8 170 *
j3 6:dc06cc75c1c8 171 * @return 0 on success, non-0 on failure
j3 0:b5189f4ce1cb 172 **************************************************************/
j3 0:b5189f4ce1cb 173 int16_t set_operating_mode(max14871_motor_driver_t md,
j3 0:b5189f4ce1cb 174 max14871_operating_mode_t mode);
j3 0:b5189f4ce1cb 175
j3 0:b5189f4ce1cb 176
j3 0:b5189f4ce1cb 177 /**********************************************************//**
j3 0:b5189f4ce1cb 178 * @brief
j3 0:b5189f4ce1cb 179 *
j3 0:b5189f4ce1cb 180 * @details
j3 0:b5189f4ce1cb 181 *
j3 0:b5189f4ce1cb 182 * On Entry:
j3 0:b5189f4ce1cb 183 * @param[in] md - 1 of 4 motor drivers on the shield
j3 0:b5189f4ce1cb 184 * @param[in] mode - 1 of 6 current regulation modes of the
j3 0:b5189f4ce1cb 185 * motor driver
j3 1:7e9b864ddacf 186 * @param[in] vref - sets maximum motor current, Max of 2.0V
j3 0:b5189f4ce1cb 187 *
j3 0:b5189f4ce1cb 188 * On Exit:
j3 6:dc06cc75c1c8 189 *
j3 6:dc06cc75c1c8 190 * @return 0 on success, non-0 on failure
j3 0:b5189f4ce1cb 191 **************************************************************/
j3 0:b5189f4ce1cb 192 int16_t set_current_regulation_mode(max14871_motor_driver_t md,
j3 0:b5189f4ce1cb 193 max14871_current_regulation_mode_t mode,
j3 7:c0bee1397f3e 194 float vref = 1.0);
j3 0:b5189f4ce1cb 195
j3 0:b5189f4ce1cb 196
j3 0:b5189f4ce1cb 197 /**********************************************************//**
j3 5:a206f6505109 198 * @brief Sets pwm channel for given motor driver
j3 5:a206f6505109 199 *
j3 5:a206f6505109 200 * @details Must use default, or alternate channel for specific
j3 5:a206f6505109 201 * motor driver. Function allows for mix of default and
j3 5:a206f6505109 202 * alternates for each motor driver vs all default or
j3 5:a206f6505109 203 * all alternate.
j3 5:a206f6505109 204 *
j3 5:a206f6505109 205 * On Entry:
j3 5:a206f6505109 206 * @param[in] md - 1 of 4 motor drivers on the shield
j3 5:a206f6505109 207 * @param[in] ch - PWM channel using Arduino naming convention
j3 5:a206f6505109 208 *
j3 5:a206f6505109 209 * On Exit:
j3 6:dc06cc75c1c8 210 *
j3 6:dc06cc75c1c8 211 * @return 0 on success, non-0 on failure
j3 5:a206f6505109 212 **************************************************************/
j3 5:a206f6505109 213 int16_t set_pwm_channel(max14871_motor_driver_t md, PinName ch);
j3 5:a206f6505109 214
j3 5:a206f6505109 215
j3 5:a206f6505109 216 /**********************************************************//**
j3 0:b5189f4ce1cb 217 * @brief Sets period of pwm signal for selected motor driver
j3 0:b5189f4ce1cb 218 *
j3 0:b5189f4ce1cb 219 * @details period must be in micro-seconds
j3 0:b5189f4ce1cb 220 *
j3 0:b5189f4ce1cb 221 * On Entry:
j3 0:b5189f4ce1cb 222 * @param[in] md - 1 of 4 motor drivers on the shield
j3 1:7e9b864ddacf 223 * @param[in] period - PWM period specified in seconds
j3 0:b5189f4ce1cb 224 *
j3 0:b5189f4ce1cb 225 * On Exit:
j3 6:dc06cc75c1c8 226 *
j3 6:dc06cc75c1c8 227 * @return 0 on success, non-0 on failure
j3 0:b5189f4ce1cb 228 **************************************************************/
j3 1:7e9b864ddacf 229 int16_t set_pwm_period(max14871_motor_driver_t md, float period);
j3 0:b5189f4ce1cb 230
j3 0:b5189f4ce1cb 231
j3 0:b5189f4ce1cb 232 /**********************************************************//**
j3 0:b5189f4ce1cb 233 * @brief Sets duty cycle of pwm signal for selected motor driver
j3 0:b5189f4ce1cb 234 *
j3 0:b5189f4ce1cb 235 * @details duty cycle must be in micro-seconds
j3 0:b5189f4ce1cb 236 *
j3 0:b5189f4ce1cb 237 * On Entry:
j3 0:b5189f4ce1cb 238 * @param[in] md - 1 of 4 motor drivers on the shield
j3 1:7e9b864ddacf 239 * @param[in] duty_cycle - duty cycle of the pwm signal specified
j3 1:7e9b864ddacf 240 * as a percentage
j3 0:b5189f4ce1cb 241 *
j3 0:b5189f4ce1cb 242 * On Exit:
j3 6:dc06cc75c1c8 243 *
j3 6:dc06cc75c1c8 244 * @return 0 on success, non-0 on failure
j3 0:b5189f4ce1cb 245 **************************************************************/
j3 1:7e9b864ddacf 246 int16_t set_pwm_duty_cycle(max14871_motor_driver_t md, float duty_cycle);
j3 3:89bf07b855e5 247
j3 3:89bf07b855e5 248
j3 3:89bf07b855e5 249 /**********************************************************//**
j3 3:89bf07b855e5 250 * @brief Get operating mode of selected motor driver
j3 3:89bf07b855e5 251 *
j3 3:89bf07b855e5 252 * @details
j3 3:89bf07b855e5 253 *
j3 3:89bf07b855e5 254 * On Entry:
j3 3:89bf07b855e5 255 * @param[in] md - 1 of 4 motor drivers on the shield
j3 3:89bf07b855e5 256 *
j3 3:89bf07b855e5 257 * On Exit:
j3 6:dc06cc75c1c8 258 *
j3 6:dc06cc75c1c8 259 * @return Operating mode of selected motor driver
j3 3:89bf07b855e5 260 **************************************************************/
j3 3:89bf07b855e5 261 max14871_operating_mode_t get_operating_mode(max14871_motor_driver_t md);
j3 3:89bf07b855e5 262
j3 3:89bf07b855e5 263
j3 3:89bf07b855e5 264 /**********************************************************//**
j3 3:89bf07b855e5 265 * @brief Get current regulation mode of selected motor driver
j3 3:89bf07b855e5 266 *
j3 3:89bf07b855e5 267 * @details
j3 3:89bf07b855e5 268 *
j3 3:89bf07b855e5 269 * On Entry:
j3 3:89bf07b855e5 270 * @param[in] md - 1 of 4 motor drivers on the shield
j3 3:89bf07b855e5 271 *
j3 3:89bf07b855e5 272 * On Exit:
j3 6:dc06cc75c1c8 273 *
j3 6:dc06cc75c1c8 274 * @return Current regulation mode of selected motor driver
j3 3:89bf07b855e5 275 **************************************************************/
j3 3:89bf07b855e5 276 max14871_current_regulation_mode_t get_current_regulation_mode(max14871_motor_driver_t md);
j3 3:89bf07b855e5 277
j3 3:89bf07b855e5 278
j3 3:89bf07b855e5 279 /**********************************************************//**
j3 3:89bf07b855e5 280 * @brief Get duty cycle of selected motor driver
j3 3:89bf07b855e5 281 *
j3 3:89bf07b855e5 282 * @details
j3 3:89bf07b855e5 283 *
j3 3:89bf07b855e5 284 * On Entry:
j3 3:89bf07b855e5 285 * @param[in] md - 1 of 4 motor drivers on the shield
j3 3:89bf07b855e5 286 *
j3 3:89bf07b855e5 287 * On Exit:
j3 6:dc06cc75c1c8 288 *
j3 6:dc06cc75c1c8 289 * @return Duty cycle of selected motor driver
j3 3:89bf07b855e5 290 **************************************************************/
j3 3:89bf07b855e5 291 float get_pwm_duty_cycle(max14871_motor_driver_t md);
j3 3:89bf07b855e5 292
j3 3:89bf07b855e5 293
j3 3:89bf07b855e5 294 /**********************************************************//**
j3 5:a206f6505109 295 * @brief Get pwm period of selected motor driver
j3 5:a206f6505109 296 *
j3 5:a206f6505109 297 * @details
j3 5:a206f6505109 298 *
j3 5:a206f6505109 299 * On Entry:
j3 5:a206f6505109 300 * @param[in] md - 1 of 4 motor drivers on the shield
j3 5:a206f6505109 301 *
j3 5:a206f6505109 302 * On Exit:
j3 6:dc06cc75c1c8 303 *
j3 6:dc06cc75c1c8 304 * @return pwm period of selected motor driver
j3 5:a206f6505109 305 **************************************************************/
j3 5:a206f6505109 306 float get_pwm_period(max14871_motor_driver_t md);
j3 5:a206f6505109 307
j3 5:a206f6505109 308
j3 5:a206f6505109 309 /**********************************************************//**
j3 3:89bf07b855e5 310 * @brief Get external voltage reference of selected motor driver
j3 3:89bf07b855e5 311 *
j3 3:89bf07b855e5 312 * @details
j3 3:89bf07b855e5 313 *
j3 3:89bf07b855e5 314 * On Entry:
j3 3:89bf07b855e5 315 * @param[in] md - 1 of 4 motor drivers on the shield
j3 3:89bf07b855e5 316 *
j3 3:89bf07b855e5 317 * On Exit:
j3 6:dc06cc75c1c8 318 *
j3 6:dc06cc75c1c8 319 * @return External voltage reference of selected motor driver
j3 3:89bf07b855e5 320 **************************************************************/
j3 3:89bf07b855e5 321 float get_external_voltage_ref(max14871_motor_driver_t md);
j3 0:b5189f4ce1cb 322
j3 0:b5189f4ce1cb 323
j3 0:b5189f4ce1cb 324 private:
j3 0:b5189f4ce1cb 325
j3 3:89bf07b855e5 326 struct motor_data_s
j3 3:89bf07b855e5 327 {
j3 3:89bf07b855e5 328 max14871_operating_mode_t op_mode;
j3 3:89bf07b855e5 329 max14871_current_regulation_mode_t i_reg_mode;
j3 3:89bf07b855e5 330 float duty_cycle;
j3 5:a206f6505109 331 float period;
j3 3:89bf07b855e5 332 float v_ref;
j3 3:89bf07b855e5 333 };
j3 3:89bf07b855e5 334
j3 3:89bf07b855e5 335 struct motor_data_s _motor_data_array[4];
j3 3:89bf07b855e5 336
j3 0:b5189f4ce1cb 337 I2C *_p_i2c;
j3 0:b5189f4ce1cb 338 Max7300 *_p_io_expander;
j3 0:b5189f4ce1cb 339 Max5387 *_p_digi_pot1;
j3 0:b5189f4ce1cb 340 Max5387 *_p_digi_pot2;
j3 0:b5189f4ce1cb 341 PwmOut *_p_pwm1;
j3 0:b5189f4ce1cb 342 PwmOut *_p_pwm2;
j3 0:b5189f4ce1cb 343 PwmOut *_p_pwm3;
j3 0:b5189f4ce1cb 344 PwmOut *_p_pwm4;
j3 0:b5189f4ce1cb 345
j3 0:b5189f4ce1cb 346 bool _i2c_owner;
j3 0:b5189f4ce1cb 347
j3 0:b5189f4ce1cb 348 void init_board(void);
j3 0:b5189f4ce1cb 349 };
j3 0:b5189f4ce1cb 350
j3 0:b5189f4ce1cb 351 #endif/* MAX14871_SHIELD_H */