ADC internal channels read example.

Dependencies:   mbed

Committer:
bcostm
Date:
Tue Nov 15 10:04:05 2016 +0000
Revision:
0:bd554f9d9a54
Child:
1:55c36e464885
Initial version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:bd554f9d9a54 1 #include "mbed.h"
bcostm 0:bd554f9d9a54 2
bcostm 0:bd554f9d9a54 3 #define AMBIENT_TEMP 25.0f /* Ambient Temperature in °C */
bcostm 0:bd554f9d9a54 4 #define VSENS_AT_AMBIENT_TEMP 760.0f /* VSENSE value in mV at ambient temperature */
bcostm 0:bd554f9d9a54 5 #define AVG_SLOPE 25.0f /* Average slope in mV/°C multiplied by 10 */
bcostm 0:bd554f9d9a54 6 #define VREF 3300.0f /* Device power supply in mV */
bcostm 0:bd554f9d9a54 7
bcostm 0:bd554f9d9a54 8 AnalogIn tempsensor(ADC_TEMP);
bcostm 0:bd554f9d9a54 9
bcostm 0:bd554f9d9a54 10 DigitalOut led(LED1);
bcostm 0:bd554f9d9a54 11
bcostm 0:bd554f9d9a54 12 int main()
bcostm 0:bd554f9d9a54 13 {
bcostm 0:bd554f9d9a54 14 float meas_f;
bcostm 0:bd554f9d9a54 15 float JTemp_f;
bcostm 0:bd554f9d9a54 16
bcostm 0:bd554f9d9a54 17 printf("\nSTM32 Internal Temperature Sensor example\n");
bcostm 0:bd554f9d9a54 18
bcostm 0:bd554f9d9a54 19 while(1) {
bcostm 0:bd554f9d9a54 20
bcostm 0:bd554f9d9a54 21 meas_f = tempsensor.read();
bcostm 0:bd554f9d9a54 22
bcostm 0:bd554f9d9a54 23 /* Compute the Junction Temperature value
bcostm 0:bd554f9d9a54 24 JTemp = ((Vsens - V25)/Avg_Slope) + 25°C
bcostm 0:bd554f9d9a54 25 The internal temperature sensor supports a temperature range of –40 to 125°C with an accuracy of +/-1.5°C. */
bcostm 0:bd554f9d9a54 26
bcostm 0:bd554f9d9a54 27 JTemp_f = (((meas_f * VREF) - VSENS_AT_AMBIENT_TEMP) * 10.0f / AVG_SLOPE) + AMBIENT_TEMP;
bcostm 0:bd554f9d9a54 28
bcostm 0:bd554f9d9a54 29 printf("Internal Temperature = %.1f degree C\n", JTemp_f);
bcostm 0:bd554f9d9a54 30
bcostm 0:bd554f9d9a54 31 led = !led;
bcostm 0:bd554f9d9a54 32 wait(1.0);
bcostm 0:bd554f9d9a54 33 }
bcostm 0:bd554f9d9a54 34 }