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

Files at this revision

API Documentation at this revision

Comitter:
j3
Date:
Tue Dec 22 04:24:07 2015 +0000
Parent:
4:4e42c80f56b6
Child:
6:dc06cc75c1c8
Commit message:
Added set_pwm_channel member function

Changed in this revision

MAX7300.lib Show annotated file Show diff for this revision Revisions of this file
max14871_shield.cpp Show annotated file Show diff for this revision Revisions of this file
max14871_shield.h Show annotated file Show diff for this revision Revisions of this file
--- a/MAX7300.lib	Mon Aug 24 17:11:41 2015 +0000
+++ b/MAX7300.lib	Tue Dec 22 04:24:07 2015 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/teams/Maxim-Integrated/code/MAX7300/#c4d2978bdebb
+https://developer.mbed.org/teams/Maxim-Integrated/code/MAX7300/#3674af0a03cf
--- a/max14871_shield.cpp	Mon Aug 24 17:11:41 2015 +0000
+++ b/max14871_shield.cpp	Tue Dec 22 04:24:07 2015 +0000
@@ -385,6 +385,114 @@
 
 
 //*********************************************************************
+int16_t Max14871_Shield::set_pwm_channel(max14871_motor_driver_t md, PinName ch)
+{
+    
+    int16_t result = 0;
+    float pwm_duty_cycle;
+    float pwm_period;
+    
+    
+    if((ch != D3) && (ch != D4) && (ch != D5) && (ch != D6) &&
+       (ch != D8) && (ch != D9) && (ch != D10) && (ch != D11))
+    {
+        result = -1;
+    }
+    else
+    {        
+        switch(md)
+        {
+            case MD1:
+                if((ch != D3) && (ch != D4))
+                {
+                    result = -1;
+                }
+                else
+                {
+                    pwm_duty_cycle = get_pwm_duty_cycle(md);
+                    pwm_period = get_pwm_period(md);
+                    
+                    _p_pwm1->pulsewidth_us(0);
+                    
+                    delete _p_pwm1;
+                    _p_pwm1 = new PwmOut(ch);
+                    
+                    set_pwm_period(md, pwm_period);
+                    set_pwm_duty_cycle(md, pwm_duty_cycle);
+                }
+            break;
+            
+            case MD2:
+                if((ch != D5) && (ch != D6))
+                {
+                    result = -1;
+                }
+                else
+                {
+                    pwm_duty_cycle = get_pwm_duty_cycle(md);
+                    pwm_period = get_pwm_period(md);
+                    
+                    _p_pwm2->pulsewidth_us(0);
+                    
+                    delete _p_pwm2;
+                    _p_pwm2 = new PwmOut(ch);
+                    
+                    set_pwm_period(md, pwm_period);
+                    set_pwm_duty_cycle(md, pwm_duty_cycle);
+                }
+            break;
+            
+            case MD3:
+                if((ch != D8) && (ch != D9))
+                {
+                    result = -1;
+                }
+                else
+                {
+                    pwm_duty_cycle = get_pwm_duty_cycle(md);
+                    pwm_period = get_pwm_period(md);
+                    
+                    _p_pwm3->pulsewidth_us(0);
+                    
+                    delete _p_pwm3;
+                    _p_pwm3 = new PwmOut(ch);
+                    
+                    set_pwm_period(md, pwm_period);
+                    set_pwm_duty_cycle(md, pwm_duty_cycle);
+                }
+            break;
+            
+            case MD4:
+                if((ch != D10) && (ch != D11))
+                {
+                    result = -1;
+                }
+                else
+                {
+                    pwm_duty_cycle = get_pwm_duty_cycle(md);
+                    pwm_period = get_pwm_period(md);
+                    
+                    _p_pwm4->pulsewidth_us(0);
+                    
+                    delete _p_pwm4;
+                    _p_pwm4 = new PwmOut(ch);
+                    
+                    set_pwm_period(md, pwm_period);
+                    set_pwm_duty_cycle(md, pwm_duty_cycle);
+                }
+            break;
+            
+            default:
+                result = -1;
+            break;
+        }
+    }
+    
+    return result;
+}
+
+
+//*********************************************************************
 int16_t Max14871_Shield::set_pwm_period(max14871_motor_driver_t md, float period)
 {
     int16_t result = 0;
@@ -399,18 +507,22 @@
         {
             case MD1:
                 _p_pwm1->period(period);
+                _motor_data_array[(md - 1)].period = period;
             break;
             
             case MD2:
                 _p_pwm2->period(period);
+                _motor_data_array[(md - 1)].period = period;
             break;
             
             case MD3:
                 _p_pwm3->period(period);
+                _motor_data_array[(md - 1)].period = period;
             break;
             
             case MD4:
                 _p_pwm4->period(period);
+                _motor_data_array[(md - 1)].period = period;
             break;
             
             default:
@@ -481,6 +593,13 @@
 
 
 //*********************************************************************
+float Max14871_Shield::get_pwm_period(max14871_motor_driver_t md)
+{
+    return(_motor_data_array[(md - 1)].period);
+}
+
+
+//*********************************************************************
 float Max14871_Shield::get_external_voltage_ref(max14871_motor_driver_t md)
 {
     return(_motor_data_array[(md - 1)].v_ref);
@@ -529,6 +648,7 @@
         _motor_data_array[idx].op_mode = COAST;
         _motor_data_array[idx].i_reg_mode = RIPPLE_25_INTERNAL_REF;
         _motor_data_array[idx].duty_cycle = 0.0f;
+        _motor_data_array[idx].period = MIN_PERIOD;
         _motor_data_array[idx].v_ref = 0.0f;
     }
 }
--- a/max14871_shield.h	Mon Aug 24 17:11:41 2015 +0000
+++ b/max14871_shield.h	Tue Dec 22 04:24:07 2015 +0000
@@ -168,6 +168,24 @@
     
     
     /**********************************************************//**
+    * @brief Sets pwm channel for given motor driver
+    *
+    * @details Must use default, or alternate channel for specific 
+    *          motor driver.  Function allows for mix of default and 
+    *          alternates for each motor driver vs all default or 
+    *          all alternate.
+    *
+    * On Entry:
+    *    @param[in] md - 1 of 4 motor drivers on the shield
+    *    @param[in] ch - PWM channel using Arduino naming convention
+    *
+    * On Exit:
+    *    @return 0 on success, non-0 on failure
+    **************************************************************/
+    int16_t set_pwm_channel(max14871_motor_driver_t md, PinName ch);
+    
+    
+    /**********************************************************//**
     * @brief Sets period of pwm signal for selected motor driver
     *
     * @details period must be in micro-seconds
@@ -241,6 +259,20 @@
     
     
     /**********************************************************//**
+    * @brief Get pwm period of selected motor driver
+    *
+    * @details 
+    *
+    * On Entry:
+    *    @param[in] md - 1 of 4 motor drivers on the shield
+    *    
+    * On Exit:
+    *    @return pwm period of selected motor driver
+    **************************************************************/
+    float get_pwm_period(max14871_motor_driver_t md);
+    
+    
+    /**********************************************************//**
     * @brief Get external voltage reference of selected motor driver
     *
     * @details 
@@ -261,6 +293,7 @@
         max14871_operating_mode_t op_mode;
         max14871_current_regulation_mode_t i_reg_mode;
         float duty_cycle;
+        float period;
         float v_ref;
     };