9 years, 2 months ago.

STM32F103RB ADC (pics included) strange values for temperature sensor (LM35)

/media/uploads/alexlungu10/1.jpg I've connected one battery/2 batteries (GND and A0) and the measuremet displayed on the com26 port is ok. I've connected the LM35 (The LM35 has 1 celsius degree for 10mV measured value) on the VCC and GND and the output pin is connected to the A0(analog input). The value read on the com26 port at room temperature (26 celsius degrees) is 40 celsius degrees. I don't understand what is the problem. The sensor is ok because I've used a multimeter and the output value is 262mV, divided by 10 =26 celsius degrees. but the uC measures 400mV (instead of 262mV) that means 40 degrees. I've used external power source for the LM35 sensor and the same problem. I've used 3.3 and 5V for the LM35 (from the uC board) and the same problem...I'm very courios about this problem ...

I'm a beginner in STM32, so please help me.

Update: I've made firmware upgrades, stm32 library updates, picture 2 updates... In picture two, first rows readings are from a 1.28V battery the rest are from the LM35 sensor. Battery seemns ok but for LM35 I get 367mV instead of 270mV (measured with a multimeter) I don't know why the value from L35 is not ok from the uC's ADC

/media/uploads/alexlungu10/capture_JRWGvl1.jpg

The code:

  1. include "test_env.h" Serial pc(USBTX, USBRX); AnalogIn analogValue(A2); DigitalIn userButton(USER_BUTTON); DigitalOut led(LED1);

Calculate the corresponding acquisition measure for a given value in mV

  1. define MV(x) ((0xFFF*x)/3300)

void notify_completion(bool success) { led = 0; pc.baud(9600); int count = 0; bool enFlag = true; while (1) {

count++; if (userButton == 0) { enFlag = (enFlag == true) ? false : true; pc.close(); } if (enFlag) { unsigned short meas = (analogValue.read_u16()); float final = (float) 3300 / 65535 * (float) meas; normal 0.0008 or 3.3v-3300mV 0,8058608058608059 3300/4095 pc.printf("%d;%d val in mV: %d, mV from percentage:%d \n", count, meas, (int) final, int(analogValue.read() * 3300));

}

led = !led;

wait(2.f); }

}

1 Answer

9 years, 2 months ago.

analogin.read_u16() returns 16bit 0-FFFF not 0-FFF (4095) If you are going to use floats, use analogin.read()

float temp = analogValue.read()*330;

http://developer.mbed.org/users/mbed_official/code/mbed-src/file/fc4922e0c183/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/analogin_api.c

Hello Geremia G, and thank you for your answer, but I've made firmware upgrades, stm32 library updates, picture 2 updates... In picture two, first rows readings are from a 1.28V battery the rest are from the LM35 sensor. Battery seemns ok but for LM35 I get 367mV instead of 270mV (measured with a multimeter) I don't know why the value from L35 is not ok from the uC's ADC**

posted by alex alex 09 Feb 2015