ADC internal channels read example.
Dependencies: mbed
Revision 1:55c36e464885, committed 2016-11-18
- Comitter:
- bcostm
- Date:
- Fri Nov 18 15:53:34 2016 +0000
- Parent:
- 0:bd554f9d9a54
- Child:
- 2:9bab1d673af9
- Commit message:
- Add VBat example
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Nov 15 10:04:05 2016 +0000 +++ b/main.cpp Fri Nov 18 15:53:34 2016 +0000 @@ -1,11 +1,14 @@ #include "mbed.h" +#define VREF 3300.0f /* Device power supply in mV */ + +// Parameters for temperature sensor only #define AMBIENT_TEMP 25.0f /* Ambient Temperature in °C */ #define VSENS_AT_AMBIENT_TEMP 760.0f /* VSENSE value in mV at ambient temperature */ #define AVG_SLOPE 25.0f /* Average slope in mV/°C multiplied by 10 */ -#define VREF 3300.0f /* Device power supply in mV */ -AnalogIn tempsensor(ADC_TEMP); +//AnalogIn vbat(ADC_VBAT); // To measure VBat +AnalogIn tempsensor(ADC_TEMP); // To measure Temperature sensot DigitalOut led(LED1); @@ -14,10 +17,20 @@ float meas_f; float JTemp_f; - printf("\nSTM32 Internal Temperature Sensor example\n"); + printf("\nSTM32 Internal Channels example\n"); while(1) { + /* + Note 1: As VBAT voltage could be higher than VDDA, to ensure the correct operation of the ADC, the + VBAT pin is internally connected to a bridge divider by 4. + Note 2: On some devices the VBAT and temperature sensor are connected to the same ADC internal channel + Only one conversion, either temperature sensor or VBAT, must be selected at a time. + When both conversion are enabled simultaneously, only the VBAT conversion is + performed. + */ + //printf("\nVBat = %.1f mV\n", vbat.read() * VREF * 4); + meas_f = tempsensor.read(); /* Compute the Junction Temperature value