Add reference voltage getter and clarify some comments

pull/12471/head
George Beckstein 2020-02-19 13:58:31 -05:00
parent 2db9917117
commit b76300f57c
2 changed files with 16 additions and 4 deletions

View File

@ -93,7 +93,8 @@ public:
*/ */
unsigned short read_u16(); unsigned short read_u16();
/** Read the input voltage in volts. The output depends on the target board's /**
* Read the input voltage in volts. The output depends on the target board's
* ADC reference voltage (typically equal to supply voltage). The ADC reference voltage * ADC reference voltage (typically equal to supply voltage). The ADC reference voltage
* sets the maximum voltage the ADC can quantify (ie: Vin == Vref when ADC output == ADC_MAX_VALUE) * sets the maximum voltage the ADC can quantify (ie: Vin == Vref when ADC output == ADC_MAX_VALUE)
* *
@ -104,16 +105,23 @@ public:
float read_volts(); float read_volts();
/** /**
* Sets this ADC instance's reference voltage. * Sets this AnalogIn instance's reference voltage.
* *
* Defaults to the configurable MBED_CONF_DRIVERS_DEFAULT_ADC_VREF setting. * Defaults to the configurable MBED_CONF_DRIVERS_DEFAULT_ADC_VREF setting.
* *
* The ADC's reference voltage is used to scale the output when calling AnalogIn::read_volts * The AnalogIn's reference voltage is used to scale the output when calling AnalogIn::read_volts
* *
* @param[in] vref New ADC reference voltage for this ADC instance. * @param[in] vref New ADC reference voltage for this AnalogIn instance.
*/ */
void set_reference_voltage(float vref); void set_reference_voltage(float vref);
/**
* Gets this AnalogIn instance's reference voltage.
*
* @returns A floating-point value representing this AnalogIn's reference voltage, measured in volts.
*/
float get_reference_voltage(void);
/** An operator shorthand for read() /** An operator shorthand for read()
* *
* The float() operator can be used as a shorthand for read() to simplify common code sequences * The float() operator can be used as a shorthand for read() to simplify common code sequences

View File

@ -63,6 +63,10 @@ void AnalogIn::set_reference_voltage(float vref) {
this->vref = vref; this->vref = vref;
} }
float AnalogIn::get_reference_voltage(void) {
return this->vref;
}
} // namespace mbed } // namespace mbed
#endif #endif