Library for MAX14871 Shield, MAXREFDES89#
Dependents: MAXREFDES89_MAX14871_Shield_Demo MAXREFDES89_Test_Program Line_Following_Bot Line_Following_Bot_Pololu
Diff: max14871_shield.cpp
- Revision:
- 3:89bf07b855e5
- Parent:
- 2:9b50d36d69c8
- Child:
- 5:a206f6505109
--- 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; + } }