ADC internal channels read example.

Dependencies:   mbed

Committer:
bcostm
Date:
Mon Nov 21 13:59:38 2016 +0000
Revision:
3:5467a013d0a0
Parent:
2:9bab1d673af9
Child:
4:e784c25594d7
Typo corrections

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:bd554f9d9a54 1 #include "mbed.h"
bcostm 0:bd554f9d9a54 2
bcostm 3:5467a013d0a0 3 #define VREF 3300.0f /* VRef in mV */
bcostm 1:55c36e464885 4
bcostm 1:55c36e464885 5 // Parameters for temperature sensor only
bcostm 3:5467a013d0a0 6 #define AMBIENT_TEMP 25.0f /* Ambient Temperature in °C */
bcostm 3:5467a013d0a0 7 #define V25 760.0f /* VSENSE value in mV at ambient temperature (see product datasheet) */
bcostm 3:5467a013d0a0 8 #define AVG_SLOPE 2.5f /* Average slope in mV/°C (see product datasheet) */
bcostm 0:bd554f9d9a54 9
bcostm 3:5467a013d0a0 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 3:5467a013d0a0 24 // Measure VBat
bcostm 3:5467a013d0a0 25 // Note: As VBAT voltage could be higher than VDDA, to ensure the correct operation of the ADC, the
bcostm 3:5467a013d0a0 26 // VBAT pin is internally connected to a bridge divider by 4.
bcostm 3:5467a013d0a0 27 printf("\nVBat = %.1f mV\n", vbat.read() * VREF * 4);
bcostm 1:55c36e464885 28
bcostm 3:5467a013d0a0 29 // Measure temperature sensor
bcostm 0:bd554f9d9a54 30 meas_f = tempsensor.read();
bcostm 3:5467a013d0a0 31 // Compute the Junction Temperature value: JTemp = ((Vsens - V25)/Avg_Slope) + 25°C
bcostm 3:5467a013d0a0 32 JTemp_f = (((meas_f * VREF) - V25) / AVG_SLOPE) + AMBIENT_TEMP;
bcostm 0:bd554f9d9a54 33
bcostm 0:bd554f9d9a54 34 printf("Internal Temperature = %.1f degree C\n", JTemp_f);
bcostm 0:bd554f9d9a54 35
bcostm 0:bd554f9d9a54 36 led = !led;
bcostm 0:bd554f9d9a54 37 wait(1.0);
bcostm 0:bd554f9d9a54 38 }
bcostm 0:bd554f9d9a54 39 }