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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /**********************************************************************
00002 * Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved.
00003 *
00004 * Permission is hereby granted, free of charge, to any person obtaining a
00005 * copy of this software and associated documentation files (the "Software"),
00006 * to deal in the Software without restriction, including without limitation
00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008 * and/or sell copies of the Software, and to permit persons to whom the
00009 * Software is furnished to do so, subject to the following conditions:
00010 *
00011 * The above copyright notice and this permission notice shall be included
00012 * in all copies or substantial portions of the Software.
00013 *
00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020 * OTHER DEALINGS IN THE SOFTWARE.
00021 *
00022 * Except as contained in this notice, the name of Maxim Integrated
00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated
00024 * Products, Inc. Branding Policy.
00025 *
00026 * The mere transfer of this software does not imply any licenses
00027 * of trade secrets, proprietary technology, copyrights, patents,
00028 * trademarks, maskwork rights, or any other form of intellectual
00029 * property whatsoever. Maxim Integrated Products, Inc. retains all
00030 * ownership rights.
00031 **********************************************************************/
00032 
00033 
00034 #include "mbed.h"
00035 #include "max14871_shield.h"
00036 
00037 template <typename T>
00038 static inline void REPORT (T set, T get)
00039 {
00040     const char *resp = (set == get) ? "Pass" : "Fail";
00041     printf("%08d: %s\n", __LINE__, resp);
00042 }
00043 
00044 float float_status = 0.0f;
00045 Max14871_Shield::max14871_current_regulation_mode_t reg_mode_status = Max14871_Shield::TCOFF_SLOW_EXTERNAL_REF;
00046 Max14871_Shield::max14871_operating_mode_t op_mode_status = Max14871_Shield::FORWARD;
00047 
00048 int main(void)
00049 {
00050 
00051     uint8_t idx = 0;
00052     const uint8_t DELAY = 50;
00053     const float VREF = 2.0f;
00054     const float PWM_PERIOD = 0.000025f; //40KHz
00055     float pwm_duty_cycle = 0.0f;
00056 
00057     puts("Starting Test");
00058     Max14871_Shield shld(D14, D15, true);
00059 
00060     Max14871_Shield::max14871_motor_driver_t MD_ARRAY[] = {Max14871_Shield::MD1, Max14871_Shield::MD2,
00061             Max14871_Shield::MD3, Max14871_Shield::MD4
00062                                                           };
00063 
00064     //configure motor drivers
00065     for(idx = 0; idx < 4; idx++) {
00066         shld.set_pwm_duty_cycle(MD_ARRAY[idx], pwm_duty_cycle);
00067         float_status = shld.get_pwm_duty_cycle(MD_ARRAY[idx]);
00068         REPORT(pwm_duty_cycle, float_status);
00069 
00070         shld.set_pwm_period(MD_ARRAY[idx], PWM_PERIOD);
00071         // no get pwm_period method
00072         float_status = shld.get_pwm_period(MD_ARRAY[idx]);
00073         REPORT(PWM_PERIOD, float_status);
00074 
00075         shld.set_current_regulation_mode(MD_ARRAY[idx], Max14871_Shield::RIPPLE_25_EXTERNAL_REF, VREF);
00076         reg_mode_status = shld.get_current_regulation_mode(MD_ARRAY[idx]);
00077         REPORT(Max14871_Shield::RIPPLE_25_EXTERNAL_REF, reg_mode_status);
00078 
00079         shld.set_operating_mode(MD_ARRAY[idx], Max14871_Shield::BRAKE);
00080         op_mode_status = shld.get_operating_mode(MD_ARRAY[idx]);
00081         REPORT(Max14871_Shield::BRAKE, op_mode_status);
00082     }
00083 
00084     for(idx = 0; idx < 4; idx++) {
00085         shld.set_operating_mode(MD_ARRAY[idx], Max14871_Shield::FORWARD);
00086         op_mode_status = shld.get_operating_mode(MD_ARRAY[idx]);
00087         REPORT(Max14871_Shield::FORWARD, op_mode_status);
00088 
00089         //Ramp up
00090         printf("Ramping up Forward, MD = %d\n", MD_ARRAY[idx]);
00091         for(pwm_duty_cycle = 0.0f; pwm_duty_cycle < 1.0f; pwm_duty_cycle += 0.1f) {
00092             printf("Duty Cycle = %0.2f\n", pwm_duty_cycle);
00093             shld.set_pwm_duty_cycle(MD_ARRAY[idx], pwm_duty_cycle);
00094             float_status = shld.get_pwm_duty_cycle(MD_ARRAY[idx]);
00095             REPORT(pwm_duty_cycle, float_status);
00096             wait_ms(DELAY);
00097         }
00098 
00099         //100% duty cycle
00100         printf("Duty Cycle = %0.2f\n", pwm_duty_cycle);
00101         shld.set_pwm_duty_cycle(MD_ARRAY[idx], pwm_duty_cycle);
00102         float_status = shld.get_pwm_duty_cycle(MD_ARRAY[idx]);
00103         REPORT(pwm_duty_cycle, float_status);
00104         wait_ms(DELAY);
00105 
00106         //Ramp down
00107         printf("Ramping down Forward, MD = %d\n", MD_ARRAY[idx]);
00108         for(pwm_duty_cycle = 1.0f; pwm_duty_cycle > 0.0f; pwm_duty_cycle -= 0.1f) {
00109             printf("Duty Cycle = %0.2f\n", pwm_duty_cycle);
00110             shld.set_pwm_duty_cycle(MD_ARRAY[idx], pwm_duty_cycle);
00111             float_status = shld.get_pwm_duty_cycle(MD_ARRAY[idx]);
00112             REPORT(pwm_duty_cycle, float_status);
00113             wait_ms(DELAY);
00114         }
00115 
00116         //0% duty cycle
00117         printf("Duty Cycle = %0.2f\n", pwm_duty_cycle);
00118         shld.set_pwm_duty_cycle(MD_ARRAY[idx], pwm_duty_cycle);
00119         float_status = shld.get_pwm_duty_cycle(MD_ARRAY[idx]);
00120         REPORT(pwm_duty_cycle, float_status);
00121         wait_ms(DELAY);
00122 
00123         shld.set_operating_mode(MD_ARRAY[idx], Max14871_Shield::REVERSE);
00124         op_mode_status = shld.get_operating_mode(MD_ARRAY[idx]);
00125         REPORT(Max14871_Shield::REVERSE, op_mode_status);
00126 
00127         //Ramp up
00128         printf("Ramping up Reverse, MD = %d\n", MD_ARRAY[idx]);
00129         for(pwm_duty_cycle = 0.0f; pwm_duty_cycle < 1.0f; pwm_duty_cycle += 0.1f) {
00130             printf("Duty Cycle = %0.2f\n", pwm_duty_cycle);
00131             shld.set_pwm_duty_cycle(MD_ARRAY[idx], pwm_duty_cycle);
00132             float_status = shld.get_pwm_duty_cycle(MD_ARRAY[idx]);
00133             REPORT(pwm_duty_cycle, float_status);
00134             wait_ms(DELAY);
00135         }
00136 
00137         //100% duty cycle
00138         printf("Duty Cycle = %0.2f\n", pwm_duty_cycle);
00139         shld.set_pwm_duty_cycle(MD_ARRAY[idx], pwm_duty_cycle);
00140         float_status = shld.get_pwm_duty_cycle(MD_ARRAY[idx]);
00141         REPORT(pwm_duty_cycle, float_status);
00142         wait_ms(DELAY);
00143 
00144         //Ramp down
00145         printf("Ramping down Reverse, MD = %d\n", MD_ARRAY[idx]);
00146         for(pwm_duty_cycle = 1.0f; pwm_duty_cycle > 0.0f; pwm_duty_cycle -= 0.1f) {
00147             printf("Duty Cycle = %0.2f\n", pwm_duty_cycle);
00148             shld.set_pwm_duty_cycle(MD_ARRAY[idx], pwm_duty_cycle);
00149             float_status = shld.get_pwm_duty_cycle(MD_ARRAY[idx]);
00150             REPORT(pwm_duty_cycle, float_status);
00151             wait_ms(DELAY);
00152         }
00153 
00154         //0% duty cycle
00155         printf("Duty Cycle = %0.2f\n", pwm_duty_cycle);
00156         shld.set_pwm_duty_cycle(MD_ARRAY[idx], pwm_duty_cycle);
00157         float_status = shld.get_pwm_duty_cycle(MD_ARRAY[idx]);
00158         REPORT(pwm_duty_cycle, float_status);
00159         wait_ms(DELAY);
00160 
00161         shld.set_operating_mode(MD_ARRAY[idx], Max14871_Shield::COAST);
00162         op_mode_status = shld.get_operating_mode(MD_ARRAY[idx]);
00163         REPORT(Max14871_Shield::COAST, op_mode_status);
00164     }
00165 
00166     return 0;
00167 }