File tree Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -93,6 +93,16 @@ class AnalogIn {
93
93
*/
94
94
unsigned short read_u16 ();
95
95
96
+ /* * Read the input voltage in volts. The output depends on the target board's
97
+ * ADC reference voltage (typically equal to supply voltage). The ADC reference voltage
98
+ * sets the maximum voltage the ADC can quantify (ie: Vin == Vref when ADC output == ADC_MAX_VALUE)
99
+ *
100
+ * The target's ADC reference voltage can be configured by overriding "drivers.adc_vref"
101
+ *
102
+ * @returns A floating-point value representing the current input voltage, measured in volts.
103
+ */
104
+ float read_volts ();
105
+
96
106
/* * An operator shorthand for read()
97
107
*
98
108
* The float() operator can be used as a shorthand for read() to simplify common code sequences
Original file line number Diff line number Diff line change 41
41
"qspi_csn" : {
42
42
"help" : " QSPI chip select pin" ,
43
43
"value" : " QSPI_FLASH1_CSN"
44
- }
44
+ },
45
+ "adc_vref" : {
46
+ "help" : " Reference voltage for ADC (float)" ,
47
+ "value" : 3.3 f
45
48
}
46
49
}
Original file line number Diff line number Diff line change @@ -54,6 +54,11 @@ unsigned short AnalogIn::read_u16()
54
54
return ret;
55
55
}
56
56
57
+ float AnalogIn::read_volts () {
58
+ float ret = this ->read ();
59
+ return (ret*MBED_CONF_DRIVERS_ADC_VREF);
60
+ }
61
+
57
62
} // namespace mbed
58
63
59
64
#endif
You can’t perform that action at this time.
0 commit comments