Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 4:e784c25594d7
- Parent:
- 3:5467a013d0a0
- Child:
- 6:3e184b0bcc33
diff -r 5467a013d0a0 -r e784c25594d7 main.cpp
--- a/main.cpp Mon Nov 21 13:59:38 2016 +0000
+++ b/main.cpp Thu Nov 24 08:52:42 2016 +0000
@@ -1,38 +1,25 @@
#include "mbed.h"
-#define VREF 3300.0f /* VRef in mV */
+/*
+ This basic example just shows how to read the ADC internal channels raw values.
+ Please look in the corresponding device reference manual for a complete
+ description of how to make a temperature sensor, VBat or Vref measurement.
+*/
-// 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
+AnalogIn adc_temp(ADC_TEMP);
+AnalogIn adc_vref(ADC_VREF);
+AnalogIn adc_vbat(ADC_VBAT); // Warning: Not available on all devices
DigitalOut led(LED1);
int main()
{
- float meas_f;
- float JTemp_f;
-
- printf("\nSTM32 Internal Channels example\n");
-
+ printf("\nSTM32 ADC internal channels reading 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);
-
+ printf("ADC Temp = %f\n", adc_temp.read());
+ printf("ADC VRef = %f\n", adc_vref.read());
+ printf("ADC VBat = %f\n", adc_vbat.read());
+ printf("\033[3A");
led = !led;
wait(1.0);
}