ADC internal channels read example.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 3:5467a013d0a0
- Parent:
- 2:9bab1d673af9
- Child:
- 4:e784c25594d7
--- a/main.cpp Fri Nov 18 15:58:36 2016 +0000 +++ b/main.cpp Mon Nov 21 13:59:38 2016 +0000 @@ -1,13 +1,13 @@ #include "mbed.h" -#define VREF 3300.0f /* Device power supply in mV */ +#define VREF 3300.0f /* VRef 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 AMBIENT_TEMP 25.0f /* Ambient Temperature in °C */ +#define V25 760.0f /* VSENSE value in mV at ambient temperature (see product datasheet) */ +#define AVG_SLOPE 2.5f /* Average slope in mV/°C (see product datasheet) */ -//AnalogIn vbat(ADC_VBAT); // To measure VBat +AnalogIn vbat(ADC_VBAT); // To measure VBat AnalogIn tempsensor(ADC_TEMP); // To measure Temperature sensor DigitalOut led(LED1); @@ -21,23 +21,15 @@ 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); + // Measure VBat + // Note: 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. + printf("\nVBat = %.1f mV\n", vbat.read() * VREF * 4); + // Measure temperature sensor meas_f = tempsensor.read(); - - /* Compute the Junction Temperature value - JTemp = ((Vsens - V25)/Avg_Slope) + 25°C - The internal temperature sensor supports a temperature range of –40 to 125°C with an accuracy of +/-1.5°C. */ - - JTemp_f = (((meas_f * VREF) - VSENS_AT_AMBIENT_TEMP) * 10.0f / AVG_SLOPE) + AMBIENT_TEMP; + // Compute the Junction Temperature value: JTemp = ((Vsens - V25)/Avg_Slope) + 25°C + JTemp_f = (((meas_f * VREF) - V25) / AVG_SLOPE) + AMBIENT_TEMP; printf("Internal Temperature = %.1f degree C\n", JTemp_f);