Functional test program for MAXREFDES89# that ramps each motor driver output up/down and in each direction sequentially. Uses default configuration, i.e. pwm signals are on D4, D5, D9 and D10 along with default I2C addresses for supporting I.C.s.

Dependencies:   MAX14871_Shield mbed

Committer:
j3
Date:
Sat Jan 23 02:23:43 2016 +0000
Revision:
2:be568cc42d4b
Parent:
1:c9cf8a2fc829
Updated shield library, Sam's main loop for testing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 0:81e41ea3f51a 1 /**********************************************************************
j3 0:81e41ea3f51a 2 * Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved.
j3 0:81e41ea3f51a 3 *
j3 0:81e41ea3f51a 4 * Permission is hereby granted, free of charge, to any person obtaining a
j3 0:81e41ea3f51a 5 * copy of this software and associated documentation files (the "Software"),
j3 0:81e41ea3f51a 6 * to deal in the Software without restriction, including without limitation
j3 0:81e41ea3f51a 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
j3 0:81e41ea3f51a 8 * and/or sell copies of the Software, and to permit persons to whom the
j3 0:81e41ea3f51a 9 * Software is furnished to do so, subject to the following conditions:
j3 0:81e41ea3f51a 10 *
j3 0:81e41ea3f51a 11 * The above copyright notice and this permission notice shall be included
j3 0:81e41ea3f51a 12 * in all copies or substantial portions of the Software.
j3 0:81e41ea3f51a 13 *
j3 0:81e41ea3f51a 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
j3 0:81e41ea3f51a 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
j3 0:81e41ea3f51a 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
j3 0:81e41ea3f51a 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
j3 0:81e41ea3f51a 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
j3 0:81e41ea3f51a 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
j3 0:81e41ea3f51a 20 * OTHER DEALINGS IN THE SOFTWARE.
j3 0:81e41ea3f51a 21 *
j3 0:81e41ea3f51a 22 * Except as contained in this notice, the name of Maxim Integrated
j3 0:81e41ea3f51a 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
j3 0:81e41ea3f51a 24 * Products, Inc. Branding Policy.
j3 0:81e41ea3f51a 25 *
j3 0:81e41ea3f51a 26 * The mere transfer of this software does not imply any licenses
j3 0:81e41ea3f51a 27 * of trade secrets, proprietary technology, copyrights, patents,
j3 0:81e41ea3f51a 28 * trademarks, maskwork rights, or any other form of intellectual
j3 0:81e41ea3f51a 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
j3 0:81e41ea3f51a 30 * ownership rights.
j3 0:81e41ea3f51a 31 **********************************************************************/
j3 0:81e41ea3f51a 32
j3 0:81e41ea3f51a 33
j3 0:81e41ea3f51a 34 #include "mbed.h"
j3 0:81e41ea3f51a 35 #include "max14871_shield.h"
j3 0:81e41ea3f51a 36
j3 2:be568cc42d4b 37 template <typename T>
j3 2:be568cc42d4b 38 static inline void REPORT (T set, T get)
j3 2:be568cc42d4b 39 {
j3 2:be568cc42d4b 40 const char *resp = (set == get) ? "Pass" : "Fail";
j3 2:be568cc42d4b 41 printf("%08d: %s\n", __LINE__, resp);
j3 2:be568cc42d4b 42 }
j3 2:be568cc42d4b 43
j3 2:be568cc42d4b 44 float float_status = 0.0f;
j3 2:be568cc42d4b 45 Max14871_Shield::max14871_current_regulation_mode_t reg_mode_status = Max14871_Shield::TCOFF_SLOW_EXTERNAL_REF;
j3 2:be568cc42d4b 46 Max14871_Shield::max14871_operating_mode_t op_mode_status = Max14871_Shield::FORWARD;
j3 0:81e41ea3f51a 47
j3 0:81e41ea3f51a 48 int main(void)
j3 0:81e41ea3f51a 49 {
j3 2:be568cc42d4b 50
j3 0:81e41ea3f51a 51 uint8_t idx = 0;
j3 0:81e41ea3f51a 52 const uint8_t DELAY = 50;
j3 0:81e41ea3f51a 53 const float VREF = 2.0f;
j3 0:81e41ea3f51a 54 const float PWM_PERIOD = 0.000025f; //40KHz
j3 0:81e41ea3f51a 55 float pwm_duty_cycle = 0.0f;
j3 2:be568cc42d4b 56
j3 2:be568cc42d4b 57 puts("Starting Test");
j3 0:81e41ea3f51a 58 Max14871_Shield shld(D14, D15, true);
j3 2:be568cc42d4b 59
j3 2:be568cc42d4b 60 Max14871_Shield::max14871_motor_driver_t MD_ARRAY[] = {Max14871_Shield::MD1, Max14871_Shield::MD2,
j3 2:be568cc42d4b 61 Max14871_Shield::MD3, Max14871_Shield::MD4
j3 2:be568cc42d4b 62 };
j3 2:be568cc42d4b 63
j3 0:81e41ea3f51a 64 //configure motor drivers
j3 2:be568cc42d4b 65 for(idx = 0; idx < 4; idx++) {
j3 0:81e41ea3f51a 66 shld.set_pwm_duty_cycle(MD_ARRAY[idx], pwm_duty_cycle);
j3 2:be568cc42d4b 67 float_status = shld.get_pwm_duty_cycle(MD_ARRAY[idx]);
j3 2:be568cc42d4b 68 REPORT(pwm_duty_cycle, float_status);
j3 2:be568cc42d4b 69
j3 0:81e41ea3f51a 70 shld.set_pwm_period(MD_ARRAY[idx], PWM_PERIOD);
j3 2:be568cc42d4b 71 // no get pwm_period method
j3 2:be568cc42d4b 72 float_status = shld.get_pwm_period(MD_ARRAY[idx]);
j3 2:be568cc42d4b 73 REPORT(PWM_PERIOD, float_status);
j3 2:be568cc42d4b 74
j3 0:81e41ea3f51a 75 shld.set_current_regulation_mode(MD_ARRAY[idx], Max14871_Shield::RIPPLE_25_EXTERNAL_REF, VREF);
j3 2:be568cc42d4b 76 reg_mode_status = shld.get_current_regulation_mode(MD_ARRAY[idx]);
j3 2:be568cc42d4b 77 REPORT(Max14871_Shield::RIPPLE_25_EXTERNAL_REF, reg_mode_status);
j3 2:be568cc42d4b 78
j3 0:81e41ea3f51a 79 shld.set_operating_mode(MD_ARRAY[idx], Max14871_Shield::BRAKE);
j3 2:be568cc42d4b 80 op_mode_status = shld.get_operating_mode(MD_ARRAY[idx]);
j3 2:be568cc42d4b 81 REPORT(Max14871_Shield::BRAKE, op_mode_status);
j3 0:81e41ea3f51a 82 }
j3 2:be568cc42d4b 83
j3 2:be568cc42d4b 84 for(idx = 0; idx < 4; idx++) {
j3 2:be568cc42d4b 85 shld.set_operating_mode(MD_ARRAY[idx], Max14871_Shield::FORWARD);
j3 2:be568cc42d4b 86 op_mode_status = shld.get_operating_mode(MD_ARRAY[idx]);
j3 2:be568cc42d4b 87 REPORT(Max14871_Shield::FORWARD, op_mode_status);
j3 2:be568cc42d4b 88
j3 2:be568cc42d4b 89 //Ramp up
j3 2:be568cc42d4b 90 printf("Ramping up Forward, MD = %d\n", MD_ARRAY[idx]);
j3 2:be568cc42d4b 91 for(pwm_duty_cycle = 0.0f; pwm_duty_cycle < 1.0f; pwm_duty_cycle += 0.1f) {
j3 2:be568cc42d4b 92 printf("Duty Cycle = %0.2f\n", pwm_duty_cycle);
j3 2:be568cc42d4b 93 shld.set_pwm_duty_cycle(MD_ARRAY[idx], pwm_duty_cycle);
j3 2:be568cc42d4b 94 float_status = shld.get_pwm_duty_cycle(MD_ARRAY[idx]);
j3 2:be568cc42d4b 95 REPORT(pwm_duty_cycle, float_status);
j3 2:be568cc42d4b 96 wait_ms(DELAY);
j3 2:be568cc42d4b 97 }
j3 2:be568cc42d4b 98
j3 2:be568cc42d4b 99 //100% duty cycle
j3 2:be568cc42d4b 100 printf("Duty Cycle = %0.2f\n", pwm_duty_cycle);
j3 2:be568cc42d4b 101 shld.set_pwm_duty_cycle(MD_ARRAY[idx], pwm_duty_cycle);
j3 2:be568cc42d4b 102 float_status = shld.get_pwm_duty_cycle(MD_ARRAY[idx]);
j3 2:be568cc42d4b 103 REPORT(pwm_duty_cycle, float_status);
j3 2:be568cc42d4b 104 wait_ms(DELAY);
j3 2:be568cc42d4b 105
j3 2:be568cc42d4b 106 //Ramp down
j3 2:be568cc42d4b 107 printf("Ramping down Forward, MD = %d\n", MD_ARRAY[idx]);
j3 2:be568cc42d4b 108 for(pwm_duty_cycle = 1.0f; pwm_duty_cycle > 0.0f; pwm_duty_cycle -= 0.1f) {
j3 2:be568cc42d4b 109 printf("Duty Cycle = %0.2f\n", pwm_duty_cycle);
j3 2:be568cc42d4b 110 shld.set_pwm_duty_cycle(MD_ARRAY[idx], pwm_duty_cycle);
j3 2:be568cc42d4b 111 float_status = shld.get_pwm_duty_cycle(MD_ARRAY[idx]);
j3 2:be568cc42d4b 112 REPORT(pwm_duty_cycle, float_status);
j3 2:be568cc42d4b 113 wait_ms(DELAY);
j3 2:be568cc42d4b 114 }
j3 2:be568cc42d4b 115
j3 2:be568cc42d4b 116 //0% duty cycle
j3 2:be568cc42d4b 117 printf("Duty Cycle = %0.2f\n", pwm_duty_cycle);
j3 2:be568cc42d4b 118 shld.set_pwm_duty_cycle(MD_ARRAY[idx], pwm_duty_cycle);
j3 2:be568cc42d4b 119 float_status = shld.get_pwm_duty_cycle(MD_ARRAY[idx]);
j3 2:be568cc42d4b 120 REPORT(pwm_duty_cycle, float_status);
j3 2:be568cc42d4b 121 wait_ms(DELAY);
j3 2:be568cc42d4b 122
j3 2:be568cc42d4b 123 shld.set_operating_mode(MD_ARRAY[idx], Max14871_Shield::REVERSE);
j3 2:be568cc42d4b 124 op_mode_status = shld.get_operating_mode(MD_ARRAY[idx]);
j3 2:be568cc42d4b 125 REPORT(Max14871_Shield::REVERSE, op_mode_status);
j3 2:be568cc42d4b 126
j3 2:be568cc42d4b 127 //Ramp up
j3 2:be568cc42d4b 128 printf("Ramping up Reverse, MD = %d\n", MD_ARRAY[idx]);
j3 2:be568cc42d4b 129 for(pwm_duty_cycle = 0.0f; pwm_duty_cycle < 1.0f; pwm_duty_cycle += 0.1f) {
j3 2:be568cc42d4b 130 printf("Duty Cycle = %0.2f\n", pwm_duty_cycle);
j3 2:be568cc42d4b 131 shld.set_pwm_duty_cycle(MD_ARRAY[idx], pwm_duty_cycle);
j3 2:be568cc42d4b 132 float_status = shld.get_pwm_duty_cycle(MD_ARRAY[idx]);
j3 2:be568cc42d4b 133 REPORT(pwm_duty_cycle, float_status);
j3 2:be568cc42d4b 134 wait_ms(DELAY);
j3 2:be568cc42d4b 135 }
j3 2:be568cc42d4b 136
j3 2:be568cc42d4b 137 //100% duty cycle
j3 2:be568cc42d4b 138 printf("Duty Cycle = %0.2f\n", pwm_duty_cycle);
j3 2:be568cc42d4b 139 shld.set_pwm_duty_cycle(MD_ARRAY[idx], pwm_duty_cycle);
j3 2:be568cc42d4b 140 float_status = shld.get_pwm_duty_cycle(MD_ARRAY[idx]);
j3 2:be568cc42d4b 141 REPORT(pwm_duty_cycle, float_status);
j3 2:be568cc42d4b 142 wait_ms(DELAY);
j3 2:be568cc42d4b 143
j3 2:be568cc42d4b 144 //Ramp down
j3 2:be568cc42d4b 145 printf("Ramping down Reverse, MD = %d\n", MD_ARRAY[idx]);
j3 2:be568cc42d4b 146 for(pwm_duty_cycle = 1.0f; pwm_duty_cycle > 0.0f; pwm_duty_cycle -= 0.1f) {
j3 2:be568cc42d4b 147 printf("Duty Cycle = %0.2f\n", pwm_duty_cycle);
j3 2:be568cc42d4b 148 shld.set_pwm_duty_cycle(MD_ARRAY[idx], pwm_duty_cycle);
j3 2:be568cc42d4b 149 float_status = shld.get_pwm_duty_cycle(MD_ARRAY[idx]);
j3 2:be568cc42d4b 150 REPORT(pwm_duty_cycle, float_status);
j3 2:be568cc42d4b 151 wait_ms(DELAY);
j3 2:be568cc42d4b 152 }
j3 2:be568cc42d4b 153
j3 2:be568cc42d4b 154 //0% duty cycle
j3 2:be568cc42d4b 155 printf("Duty Cycle = %0.2f\n", pwm_duty_cycle);
j3 2:be568cc42d4b 156 shld.set_pwm_duty_cycle(MD_ARRAY[idx], pwm_duty_cycle);
j3 2:be568cc42d4b 157 float_status = shld.get_pwm_duty_cycle(MD_ARRAY[idx]);
j3 2:be568cc42d4b 158 REPORT(pwm_duty_cycle, float_status);
j3 2:be568cc42d4b 159 wait_ms(DELAY);
j3 2:be568cc42d4b 160
j3 2:be568cc42d4b 161 shld.set_operating_mode(MD_ARRAY[idx], Max14871_Shield::COAST);
j3 2:be568cc42d4b 162 op_mode_status = shld.get_operating_mode(MD_ARRAY[idx]);
j3 2:be568cc42d4b 163 REPORT(Max14871_Shield::COAST, op_mode_status);
j3 0:81e41ea3f51a 164 }
j3 2:be568cc42d4b 165
j3 0:81e41ea3f51a 166 return 0;
j3 0:81e41ea3f51a 167 }