ADC internal channels read example.

Dependencies:   mbed

main.cpp

Committer:
bcostm
Date:
2016-11-15
Revision:
0:bd554f9d9a54
Child:
1:55c36e464885

File content as of revision 0:bd554f9d9a54:

#include "mbed.h"

#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);

DigitalOut led(LED1);

int main()
{
    float meas_f;
    float JTemp_f;

    printf("\nSTM32 Internal Temperature Sensor example\n");

    while(1) {

        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;

        printf("Internal Temperature = %.1f degree C\n", JTemp_f);

        led = !led;
        wait(1.0);
    }
}