Library for MAX14871 Shield, MAXREFDES89#
Dependents: MAXREFDES89_MAX14871_Shield_Demo MAXREFDES89_Test_Program Line_Following_Bot Line_Following_Bot_Pololu
Revision 3:89bf07b855e5, committed 2015-08-11
- Comitter:
- j3
- Date:
- Tue Aug 11 04:11:46 2015 +0000
- Parent:
- 2:9b50d36d69c8
- Child:
- 4:4e42c80f56b6
- Commit message:
- added get fxs
Changed in this revision
| 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/max14871_shield.cpp Tue Jul 28 03:42:06 2015 +0000
+++ b/max14871_shield.cpp Tue Aug 11 04:11:46 2015 +0000
@@ -181,7 +181,7 @@
port_data |= (MD_EN << 4);
}
- set_pwm_duty_cycle(md, 0.0);
+ set_pwm_duty_cycle(md, 0.0f);
break;
case BRAKE:
@@ -194,7 +194,7 @@
port_data &= ~(MD_EN << 4);
}
- set_pwm_duty_cycle(md, 0.0);
+ set_pwm_duty_cycle(md, 0.0f);
break;
case REVERSE:
@@ -230,6 +230,11 @@
{
//write data back to port
result = _p_io_expander->write_8_ports(low_port, (uint8_t) port_data);
+
+ if(!result)
+ {
+ _motor_data_array[(md - 1)].op_mode = mode;
+ }
}
return result;
@@ -367,6 +372,12 @@
{
//write data back to port
result = _p_io_expander->write_8_ports(low_port, (uint8_t) port_data);
+
+ if(!result)
+ {
+ _motor_data_array[(md - 1)].i_reg_mode = mode;
+ _motor_data_array[(md - 1)].v_ref = vref;
+ }
}
return result;
@@ -421,18 +432,22 @@
{
case MD1:
_p_pwm1->write(duty_cycle);
+ _motor_data_array[(md - 1)].duty_cycle = duty_cycle;
break;
case MD2:
_p_pwm2->write(duty_cycle);
+ _motor_data_array[(md - 1)].duty_cycle = duty_cycle;
break;
case MD3:
_p_pwm3->write(duty_cycle);
+ _motor_data_array[(md - 1)].duty_cycle = duty_cycle;
break;
case MD4:
_p_pwm4->write(duty_cycle);
+ _motor_data_array[(md - 1)].duty_cycle = duty_cycle;
break;
default:
@@ -442,6 +457,34 @@
return result;
}
+
+
+//*********************************************************************
+Max14871_Shield::max14871_operating_mode_t Max14871_Shield::get_operating_mode(max14871_motor_driver_t md)
+{
+ return(_motor_data_array[(md - 1)].op_mode);
+}
+
+
+//*********************************************************************
+Max14871_Shield::max14871_current_regulation_mode_t Max14871_Shield::get_current_regulation_mode(max14871_motor_driver_t md)
+{
+ return(_motor_data_array[(md - 1)].i_reg_mode);
+}
+
+
+//*********************************************************************
+float Max14871_Shield::get_pwm_duty_cycle(max14871_motor_driver_t md)
+{
+ return(_motor_data_array[(md - 1)].duty_cycle);
+}
+
+
+//*********************************************************************
+float Max14871_Shield::get_external_voltage_ref(max14871_motor_driver_t md)
+{
+ return(_motor_data_array[(md - 1)].v_ref);
+}
//*********************************************************************
@@ -479,4 +522,13 @@
_p_pwm2->period(MIN_PERIOD);
_p_pwm3->period(MIN_PERIOD);
_p_pwm4->period(MIN_PERIOD);
+
+ //init motor data to defaults
+ for(uint8_t idx = 0; idx < 4; idx++)
+ {
+ _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].v_ref = 0.0f;
+ }
}
--- a/max14871_shield.h Tue Jul 28 03:42:06 2015 +0000
+++ b/max14871_shield.h Tue Aug 11 04:11:46 2015 +0000
@@ -196,10 +196,76 @@
* @return 0 on success, non-0 on failure
**************************************************************/
int16_t set_pwm_duty_cycle(max14871_motor_driver_t md, float duty_cycle);
+
+
+ /**********************************************************//**
+ * @brief Get operating mode of selected motor driver
+ *
+ * @details
+ *
+ * On Entry:
+ * @param[in] md - 1 of 4 motor drivers on the shield
+ *
+ * On Exit:
+ * @return operating mode of selected motor driver
+ **************************************************************/
+ max14871_operating_mode_t get_operating_mode(max14871_motor_driver_t md);
+
+
+ /**********************************************************//**
+ * @brief Get current regulation mode of selected motor driver
+ *
+ * @details
+ *
+ * On Entry:
+ * @param[in] md - 1 of 4 motor drivers on the shield
+ *
+ * On Exit:
+ * @return current regulation mode of selected motor driver
+ **************************************************************/
+ max14871_current_regulation_mode_t get_current_regulation_mode(max14871_motor_driver_t md);
+
+
+ /**********************************************************//**
+ * @brief Get duty cycle of selected motor driver
+ *
+ * @details
+ *
+ * On Entry:
+ * @param[in] md - 1 of 4 motor drivers on the shield
+ *
+ * On Exit:
+ * @return duty cycle of selected motor driver
+ **************************************************************/
+ float get_pwm_duty_cycle(max14871_motor_driver_t md);
+
+
+ /**********************************************************//**
+ * @brief Get external voltage reference of selected motor driver
+ *
+ * @details
+ *
+ * On Entry:
+ * @param[in] md - 1 of 4 motor drivers on the shield
+ *
+ * On Exit:
+ * @return external voltage reference of selected motor driver
+ **************************************************************/
+ float get_external_voltage_ref(max14871_motor_driver_t md);
private:
+ struct motor_data_s
+ {
+ max14871_operating_mode_t op_mode;
+ max14871_current_regulation_mode_t i_reg_mode;
+ float duty_cycle;
+ float v_ref;
+ };
+
+ struct motor_data_s _motor_data_array[4];
+
I2C *_p_i2c;
Max7300 *_p_io_expander;
Max5387 *_p_digi_pot1;
MAXREFDES89#-MAX14871