Spark Logic

Reading internal temperature sensor

Pito Mon Aug 15, 2016 6:12 pm

When reading the ADC channel 16 (temperature sensor) I get constant readings like 1880 even I change temperature of the package by say 15degrees.
The sensor is enabled (from Read Vcc post):
void setup_vcc_sensor() {
adc_reg_map *regs = ADC1->regs;
regs->CR2 |= ADC_CR2_TSEREFE; // enable VREFINT and temp sensor
regs->SMPR1 = ADC_SMPR1_SMP17; // sample rate for VREFINT ADC channel
}

Replies

Pito Tue Aug 16, 2016 7:30 am

Andy thanks!
Now it works with
// Reading Vdd and Temperature Sensor
// Pito 8/2016
// Temperature sensor at ADC16, VREFINT at ADC17
// BluePill and Maple Mini

void setup_vdd_tempr_sensor() {
adc_reg_map *regs = ADC1->regs;
regs->CR2 |= ADC_CR2_TSEREFE; // enable VREFINT and Temperature sensor
// sample rate for VREFINT ADC channel and for Temperature sensor
regs->SMPR1 |= (0b111 << 18); // sample rate temperature
regs->SMPR1 |= (0b111 << 21); // sample rate vrefint
adc_calibrate(ADC1);
}

void setup(){
setup_vdd_tempr_sensor();
Serial.begin(115200);
delay(1);
}

void loop() {
float tempr, vdd;
// reading Vdd by utilising the internal 1.20V VREF
vdd = 1.20 * 4096.0 / adc_read(ADC1, 17);
// following 1.43 and 0.0043 parameters come from F103 datasheet - ch. 5.9.13
// and need to be calibrated for every chip (large fab parameters variance)
tempr = (1.43 - (vdd / 4096.0 * adc_read(ADC1, 16))) / 0.0043 + 25.0;
Serial.print("Vdd= ");
Serial.print(vdd);
Serial.println(" V");
Serial.print("Temp= ");
Serial.print(tempr);
Serial.println(" C");
delay(500);
}

RogerClark Tue Aug 16, 2016 8:11 am

@pito and Andy

Perhaps we should add this function somewhere inside libmaple ??

(any suggestions welcome ;-)

Pito Tue Aug 16, 2016 8:27 am

The refman claims the spread of the two params in the tempr calc function is large, so the sensor has to be calibrated for each chip separately. Moreover, the temperature measured depends on the CPU utilization (it measures temperature of the mcu’s silicon die), so it is not intended for measuring an ambient temperature..

Btw – do we Calibrate the ADCs somewhere in the ADC init code? (there is an ADC self-calibration procedure for STM3210x).
A: there is adc_calibrate(ADC1); available..

ahull Tue Aug 16, 2016 3:06 pm

RogerClark wrote:@pito and Andy

Perhaps we should add this function somewhere inside libmaple ??

(any suggestions welcome ;-)

Pito Tue Aug 16, 2016 5:09 pm

FYI – my ambient is 24C, after power on it shows 30C, after 5min 35-36C while running the above sketch.
There is only 2.3bit/degC, what is inside the noise background on the BluePill, so the measurement is really rather indicative.

ahull Tue Aug 16, 2016 7:51 pm

Pito wrote:FYI – my ambient is 24C, after power on it shows 30C, after 5min 35-36C while running the above sketch.
There is only 2.3bit/degC, what is inside the noise background on the BluePill, so the measurement is really rather indicative.

Pito Tue Aug 16, 2016 9:21 pm

I placed the BPill into my fridge (-16C inside). Let it freeze there for 20minutes. 1.5m long usb cable (50cm inside the fridge).
Then measured (BP still in the fridge):
10seconds after power on = -13C
5min after power on = -5C
The readings are noisy, jump +/- 1.5C, so the numbers are rather average.
Interestingly, the Vdd measurement is rock stable, much stable than under ambient temp.

And finally I dipped the BP into boiling water. It stopped sending data almost immediately (last data 40C). Immersing only the crystal part/side of the pcb into the boiling water stops the data, so it seems to me this part is critical. Or the water from my water tap is too conductive :)
I did with hair dryer and I got 60C reading (the max of my dryer) while BP worked. I can try harder with my hot air soldering gun but I do not want to remove the chip off the BP’s pcb :D

So subtracting 10C from my readings may indicate the ambient temperature with say +/- 2degC accuracy. That is valid for my chip only, of course..

RogerClark Tue Aug 16, 2016 11:20 pm

LOL moment when you said you put the board in boiling water and it stopped working ;-)

I have an infrared thermometer and I measured the temperature of the GD32 at different clock rates ( I think i probably posted the data to the forum, but it would be ages ago)

I also have a thermocouple thermometer ( but I don’t trust it that much), but I could clip the thermocouple to the top of the STM32 and take a reading if you want.

Pito Wed Aug 17, 2016 10:09 am

Long time back I had almost unlimited access to liquid nitrogen and deionized water. Plunging electronics into LN was a clear NoGo (semiconductors stop working at that temperature), boiling distilled (and best deionized) water cannot harm much with modern devices when properly designed.

ahull Wed Aug 17, 2016 1:04 pm

Pito wrote:Long time back I had almost unlimited access to liquid nitrogen and deionized water. Plunging electronics into LN was a clear NoGo (semiconductors stop working at that temperature), boiling distilled (and best deionized) water cannot harm much with modern devices when properly designed.

Pito Wed Aug 17, 2016 3:38 pm

In 80ties I had access to vacuum chamber(s), we used tons of LN in order to create ultra high vacuum. BPill in vacuum may overheat :) when running demanding sketches – as there is only cooling via radiation available.. In vacuum (outer space) the measuring the internal chip temperature would be recommended.. :)
There is an option to spend winter holidays in Oymyakon, Russia, and open your window for a while when calibrating your BPill :)

ahull Wed Aug 17, 2016 3:48 pm

Pito wrote:In 80ties I had access to vacuum chamber(s), we used tons of LN in order to create ultra high vacuum. BPill in vacuum may overheat :) when running demanding sketches – as there is only cooling via radiation available.. In vacuum (outer space) the measuring the internal chip temperature would be recommended.. :)

Pito Wed Aug 17, 2016 4:10 pm

You are right, closing the window during the measurement would be a good idea. Otherwise your LCD screen stops working, sure..

RogerClark Wed Aug 17, 2016 9:35 pm

LOL. You need a very long USB cable to test in outer space ;-)

In all seriousness… I suspect there is probably some way to test in a vacuum using fairly readily available items.

Perhaps using a vacuum pump used in commissioning air conditioning systems.
( probably not as good as the vacuum in space, but probably good enough for testing )

But of course, irradiating with heat from the sun while testing in a vacuum would be challenging.

Pito Wed Aug 17, 2016 9:44 pm

In all seriousness… I suspect there is probably some way to test in a vacuum using fairly readily available items.
For example try your hoover :)
“Vacuum” is a common term mostly used for describing “lower than atmospheric pressure”. For example 10000 Pascal.
Vacuum in space (say interstellar space) is something like 0.00000000000000001 Pascal.

RogerClark Wed Aug 17, 2016 11:04 pm

Thanks Pito

I just wondered how good a vacuum you get from a $50 pump used to install air conditioning.

Probably not that good, but I wonder what vacuum you would need to achieve to give a good simulation of orbital space etc.

Unfortunately, I can’t find the specification of the vacuum used when commissioning air conditioning systems.

simonf Wed Aug 17, 2016 11:15 pm

On the flip side I wonder how accurate it would be as a temperature sensor where the processor only wakes for a second or so to read the temperature transmit and shutdown. Like the lux sensor super low power, Super cheap.

RogerClark Wed Aug 17, 2016 11:24 pm

simonf wrote:On the flip side I wonder how accurate it would be as a temperature sensor where the processor only wakes for a second or so to read the temperature transmit and shutdown. Like the lux sensor super low power, Super cheap.

zoomx Thu Aug 18, 2016 10:11 am

Pito wrote:Long time back I had almost unlimited access to liquid nitrogen and deionized water. Plunging electronics into LN was a clear NoGo (semiconductors stop working at that temperature), boiling distilled (and best deionized) water cannot harm much with modern devices when properly designed.

Sign in to reply