![](/media/cache/group/ST_logo_2020_blue_V_cmyk.jpg.50x50_q85.jpg)
ADC internal channels read example.
Dependencies: mbed
main.cpp@2:9bab1d673af9, 2016-11-18 (annotated)
- Committer:
- bcostm
- Date:
- Fri Nov 18 15:58:36 2016 +0000
- Revision:
- 2:9bab1d673af9
- Parent:
- 1:55c36e464885
- Child:
- 3:5467a013d0a0
Typo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bcostm | 0:bd554f9d9a54 | 1 | #include "mbed.h" |
bcostm | 0:bd554f9d9a54 | 2 | |
bcostm | 1:55c36e464885 | 3 | #define VREF 3300.0f /* Device power supply in mV */ |
bcostm | 1:55c36e464885 | 4 | |
bcostm | 1:55c36e464885 | 5 | // Parameters for temperature sensor only |
bcostm | 0:bd554f9d9a54 | 6 | #define AMBIENT_TEMP 25.0f /* Ambient Temperature in °C */ |
bcostm | 0:bd554f9d9a54 | 7 | #define VSENS_AT_AMBIENT_TEMP 760.0f /* VSENSE value in mV at ambient temperature */ |
bcostm | 0:bd554f9d9a54 | 8 | #define AVG_SLOPE 25.0f /* Average slope in mV/°C multiplied by 10 */ |
bcostm | 0:bd554f9d9a54 | 9 | |
bcostm | 1:55c36e464885 | 10 | //AnalogIn vbat(ADC_VBAT); // To measure VBat |
bcostm | 2:9bab1d673af9 | 11 | AnalogIn tempsensor(ADC_TEMP); // To measure Temperature sensor |
bcostm | 0:bd554f9d9a54 | 12 | |
bcostm | 0:bd554f9d9a54 | 13 | DigitalOut led(LED1); |
bcostm | 0:bd554f9d9a54 | 14 | |
bcostm | 0:bd554f9d9a54 | 15 | int main() |
bcostm | 0:bd554f9d9a54 | 16 | { |
bcostm | 0:bd554f9d9a54 | 17 | float meas_f; |
bcostm | 0:bd554f9d9a54 | 18 | float JTemp_f; |
bcostm | 0:bd554f9d9a54 | 19 | |
bcostm | 1:55c36e464885 | 20 | printf("\nSTM32 Internal Channels example\n"); |
bcostm | 0:bd554f9d9a54 | 21 | |
bcostm | 0:bd554f9d9a54 | 22 | while(1) { |
bcostm | 0:bd554f9d9a54 | 23 | |
bcostm | 1:55c36e464885 | 24 | /* |
bcostm | 1:55c36e464885 | 25 | Note 1: As VBAT voltage could be higher than VDDA, to ensure the correct operation of the ADC, the |
bcostm | 1:55c36e464885 | 26 | VBAT pin is internally connected to a bridge divider by 4. |
bcostm | 1:55c36e464885 | 27 | Note 2: On some devices the VBAT and temperature sensor are connected to the same ADC internal channel |
bcostm | 1:55c36e464885 | 28 | Only one conversion, either temperature sensor or VBAT, must be selected at a time. |
bcostm | 1:55c36e464885 | 29 | When both conversion are enabled simultaneously, only the VBAT conversion is |
bcostm | 1:55c36e464885 | 30 | performed. |
bcostm | 1:55c36e464885 | 31 | */ |
bcostm | 1:55c36e464885 | 32 | //printf("\nVBat = %.1f mV\n", vbat.read() * VREF * 4); |
bcostm | 1:55c36e464885 | 33 | |
bcostm | 0:bd554f9d9a54 | 34 | meas_f = tempsensor.read(); |
bcostm | 0:bd554f9d9a54 | 35 | |
bcostm | 0:bd554f9d9a54 | 36 | /* Compute the Junction Temperature value |
bcostm | 0:bd554f9d9a54 | 37 | JTemp = ((Vsens - V25)/Avg_Slope) + 25°C |
bcostm | 0:bd554f9d9a54 | 38 | The internal temperature sensor supports a temperature range of –40 to 125°C with an accuracy of +/-1.5°C. */ |
bcostm | 0:bd554f9d9a54 | 39 | |
bcostm | 0:bd554f9d9a54 | 40 | JTemp_f = (((meas_f * VREF) - VSENS_AT_AMBIENT_TEMP) * 10.0f / AVG_SLOPE) + AMBIENT_TEMP; |
bcostm | 0:bd554f9d9a54 | 41 | |
bcostm | 0:bd554f9d9a54 | 42 | printf("Internal Temperature = %.1f degree C\n", JTemp_f); |
bcostm | 0:bd554f9d9a54 | 43 | |
bcostm | 0:bd554f9d9a54 | 44 | led = !led; |
bcostm | 0:bd554f9d9a54 | 45 | wait(1.0); |
bcostm | 0:bd554f9d9a54 | 46 | } |
bcostm | 0:bd554f9d9a54 | 47 | } |