mirror of https://github.com/ARMmbed/mbed-os.git
Added API call to return ADC reading in volts, scaled by configurable system ADC reference voltage.
parent
af4c8a94f3
commit
6ffacaef05
|
@ -93,6 +93,16 @@ public:
|
||||||
*/
|
*/
|
||||||
unsigned short read_u16();
|
unsigned short read_u16();
|
||||||
|
|
||||||
|
/** 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
|
||||||
|
* sets the maximum voltage the ADC can quantify (ie: Vin == Vref when ADC output == ADC_MAX_VALUE)
|
||||||
|
*
|
||||||
|
* The target's ADC reference voltage can be configured by overriding "drivers.adc_vref"
|
||||||
|
*
|
||||||
|
* @returns A floating-point value representing the current input voltage, measured in volts.
|
||||||
|
*/
|
||||||
|
float read_volts();
|
||||||
|
|
||||||
/** 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
|
||||||
|
|
|
@ -41,6 +41,9 @@
|
||||||
"qspi_csn": {
|
"qspi_csn": {
|
||||||
"help": "QSPI chip select pin",
|
"help": "QSPI chip select pin",
|
||||||
"value": "QSPI_FLASH1_CSN"
|
"value": "QSPI_FLASH1_CSN"
|
||||||
}
|
},
|
||||||
|
"adc_vref": {
|
||||||
|
"help": "Reference voltage for ADC (float)",
|
||||||
|
"value": 3.3f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,11 @@ unsigned short AnalogIn::read_u16()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float AnalogIn::read_volts() {
|
||||||
|
float ret = this->read();
|
||||||
|
return (ret*MBED_CONF_DRIVERS_ADC_VREF);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace mbed
|
} // namespace mbed
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue