Sometimes, we need to measure or check the internal temperature of the microcontrollers for safety reasons. So, in this article, I’ll cover how to measure the Internal Temperature of STM32 microcontrollers using the STM32CubeIDE compiler. So let’s begin.

Disclaimer:

Electricity poses inherent risks. Adequate skills are crucial for handling it safely. Undertake tasks at your own risk; the author disclaims responsibility for misuse, harm, or errors. Website content is unique and copyrighted; refrain from unauthorized copying. Most articles are open-source for your benefit. Feel free to use the knowledge freely, and consider purchasing available resources. For assistance or guidance, comment below; the author aims to help. Some articles may contain affiliate links, having no impact on you but supporting the author with a commission. Thank you for your understanding.

Advertisements

Table of Contents

Why need to measure Internal Temperature?

The answer is simple, for safety. Sometimes the MCU can become overheated. So to ensure MCU is not getting burnt, and for safety measures, we can monitor this temperature from time to time. And is important for industrial systems where downtime should not be over a limit.

Internal Temperature of STM32

Steps:

First, after project creation or from any existing project, go to ADC settings and select the internal temperature sensing channel.

And from the Continuous Conversion: select Enable. And then from Rank, select the max sample you want. Note that, the more the sample more the time and the more stable the reading.

Now save the project to generate or add code to your existing project.

After saving, simply add the following lines. Note: You can set any name as you want for the variables.

Here, I took 5 samples and then made an average value. Which gives a stable reading. But keep in mind that, as this is an additional feature for a MCU or project, so you should allocate the memory for this task comparing other main tasks.

Now, the code is ready. Compile and debug for the result.

In my case, it was the result on average. Also, note that this reading will change frequently. And it depends on the internal CPU load. So you may find that the temperature is fluctuating within a limit.

Calculation:

Now, you may ask where I get the calculation. Then, you have to read this application note and goto page 236.

You will get a relation between the internal temperature sensor and the ADC. Now, what are those Vsense?

For that, you need to read the datasheet of your microcontroller. In my case, it was like this:

So, putting all these values, the equation forms like this:

V25 = 1.43
Avg_Slope = 4.3 mV/C = 0.0043 V/C
VSENSE = 3.3/4096 * ADCReading
Temperature (in °C) = {(1.43 – 3.3/4096 * ADCReading) / 0.0043} + 25
Temperature (in °C) = {332.558 – 0.187364 * ADCReading} + 25
Temperature (in °C) = 357.558 – 0.187364 * ADCReading

And this calculation is used in the code. Also note that you can do all these calculations within your code, but it will consume RAM and ROM. So, if you can simplify the calculations, MCU consumes less RAM. So? Why not?

End:

I hope, this article will help you in your project by adding protection or just for curiosity. See you soon with the next article.

You can read other articles too:

For Professional Designs or Help:

Loading

MKDas

Mithun K. Das; B. Sc. in EEE from KUET; Head of R&D @ M's Lab Engineering Solution. "This is my personal blog. I post articles on different subjects related to electronics in the easiest way so that everything becomes easy for all, especially for beginners. If you have any questions, feel free to ask through the contact us page." Thanks.

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *