ADC internal channels read example.
Dependencies: mbed
main.cpp
- Committer:
- bcostm
- Date:
- 2016-11-21
- Revision:
- 3:5467a013d0a0
- Parent:
- 2:9bab1d673af9
- Child:
- 4:e784c25594d7
File content as of revision 3:5467a013d0a0:
#include "mbed.h" #define VREF 3300.0f /* VRef in mV */ // Parameters for temperature sensor only #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 tempsensor(ADC_TEMP); // To measure Temperature sensor DigitalOut led(LED1); int main() { float meas_f; float JTemp_f; printf("\nSTM32 Internal Channels example\n"); while(1) { // 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 JTemp_f = (((meas_f * VREF) - V25) / AVG_SLOPE) + AMBIENT_TEMP; printf("Internal Temperature = %.1f degree C\n", JTemp_f); led = !led; wait(1.0); } }