File tree Expand file tree Collapse file tree 3 files changed +23
-5
lines changed Expand file tree Collapse file tree 3 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -103,6 +103,17 @@ class AnalogIn {
103
103
*/
104
104
float read_volts ();
105
105
106
+ /* *
107
+ * Sets this ADC instance's reference voltage.
108
+ *
109
+ * Defaults to the configurable MBED_CONF_DRIVERS_DEFAULT_ADC_VREF setting.
110
+ *
111
+ * The ADC's reference voltage is used to scale the output when calling AnalogIn::read_volts
112
+ *
113
+ * @param[in] vref New ADC reference voltage for this ADC instance.
114
+ */
115
+ void set_reference_voltage (float vref);
116
+
106
117
/* * An operator shorthand for read()
107
118
*
108
119
* The float() operator can be used as a shorthand for read() to simplify common code sequences
@@ -141,6 +152,9 @@ class AnalogIn {
141
152
142
153
analogin_t _adc;
143
154
static SingletonPtr<PlatformMutex> _mutex;
155
+
156
+ float vref;
157
+
144
158
#endif // !defined(DOXYGEN_ONLY)
145
159
146
160
};
Original file line number Diff line number Diff line change 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)" ,
45
+ "default_adc_vref " : {
46
+ "help" : " Default reference voltage for ADC (float)" ,
47
47
"value" : 3.3 f
48
48
}
49
49
}
Original file line number Diff line number Diff line change @@ -23,14 +23,14 @@ namespace mbed {
23
23
24
24
SingletonPtr<PlatformMutex> AnalogIn::_mutex;
25
25
26
- AnalogIn::AnalogIn (PinName pin)
26
+ AnalogIn::AnalogIn (PinName pin) : vref(MBED_CONF_DRIVERS_DEFAULT_ADC_VREF)
27
27
{
28
28
lock ();
29
29
analogin_init (&_adc, pin);
30
30
unlock ();
31
31
}
32
32
33
- AnalogIn::AnalogIn (const PinMap &pinmap)
33
+ AnalogIn::AnalogIn (const PinMap &pinmap) : vref(MBED_CONF_DRIVERS_DEFAULT_ADC_VREF)
34
34
{
35
35
lock ();
36
36
analogin_init_direct (&_adc, &pinmap);
@@ -56,7 +56,11 @@ unsigned short AnalogIn::read_u16()
56
56
57
57
float AnalogIn::read_volts () {
58
58
float ret = this ->read ();
59
- return (ret*MBED_CONF_DRIVERS_ADC_VREF);
59
+ return (ret*this ->vref );
60
+ }
61
+
62
+ void AnalogIn::set_reference_voltage (float vref) {
63
+ this ->vref = vref;
60
64
}
61
65
62
66
} // namespace mbed
You can’t perform that action at this time.
0 commit comments