I'm doing a basic university project where we want to see how much a microcontroller heats up when it is performing complex operations. We have a temperature sensor that is directly attached to the microcontroller like this:
so, I need to run a piece of code that loops something complex for X seconds followed by something to cool it down again for X seconds. This is what I have so far:
#define TIME 4000 //'Heating up' time in milliseconds
void setup(){
Serial.begin(115200);
}
void loop(){
// Doing 'something' complex for TIME milliseconds to heat up the chip
Serial.println(F("Doing something complex..."));
const uint32_t heatingUpStart = millis();
while( (millis() - heatingUpStart) < TIME ){
log(exp(3.14159265358))/sqrt(2.71828182845);
}
// Go to sleep for TIME milliseconds to let the chip cool
Serial.println(F("Cooling..."));
delay(1); //just to let the "Cooling..." print
goToSleep();
}
void goToSleep(){
//Set power down mode and set sleep enable
SMCR |= bit(SM1) | bit(SE);
//Set watch dog timer to interrupt after time selected using the WDTCSR registers WDP3..0 bits
WDTCSR = bit(WDE) | bit(WDCE); //WDT enable and change enable
WDTCSR = bit(WDP3); //bit(WDP3)||bit(WDP1) = 8 s, bit(WDP3) = 4 s, bit(WDP2)||bit(WDP1)||bit(WDP0) = 2 s
WDTCSR |= bit(WDIE); //Set interrupt enable
// -------------- BOD disable - Assumes 5V supply won't fail! then sleep -----------
MCUCR |= (3 << 5);
MCUCR = (MCUCR & ~(1 << 5)) | (1 << 6);
__asm__ __volatile__("sleep");
}
I'm pretty happy with how I let the chip cool (unless there's more I could do that someone could point out), but is there something better I could do to make the chip heat up more during the 'Heating up' part of the loop?
Good luck, I've not noticed any change in chip temperature when doing complex maths or sitting idle. The only time is when the IO pins are being driven, and then it was micro watts of energy.
Yeah, I've actually just realised it might be better to just drive some resistors on some of the digital outputs to force some milliamps through the chip! that will probably be better than anything purely code but we'll see if some guru comes if with some interesting insight haha
Yes driving loads will heat it up, but you can calculate that .
It’s only a slow processor so wouldn’t expect much heat , hence no heat sink is fitted . The sensor and glue you are fitting will alter the heat dissipation too , probably dramatically , pt 100 sensors do warm up too - so you need to think how you use that .
The data sheet is worth a look for some numbers .
You really need the raw processor then you can also accurately measure power in
yeah we've used the internal temperature sensor before, but there can be some significant jumps in the measured temperature due to the resolution of the ADC
by using the PT1000, we can get a high-resolution temperature curve that's only limited by the resolution of the digital multimeter/source meter we use
Still though, actually measuring the temperature isn't what we're trying to do here, we can do that already. It's more the heating of the microcontroller when it's on that we're trying to achieve
saying that, it would be interesting to compare the temperature profiles of the internal IC to the PT1000!
A modern PC CPU will produce widely varying amounts of heat depending on what it's doing. More complex instructions mean more transistors switching than an idle NOP loop and turbo modes involving higher clock speeds mean even more heat. Worse still if the CPU is doing the job of a graphics adapter.
By contrast, the instruction set on the Arduino CPUs is far less complex, although it might be looking at it to try and guess which op codes are likely to be more expensive. The clock speed is fixed too, so there's no extra heating to be found there. I'll guess that you can find more expensive instructions that cause temperature variation, but I don't think you're going to find the kind of swings a PC can manage when it's being used to play some high end game.
Although a slightly better accuracy is seldom beneficial when accompanied by a terrible resolution. The internal temperature of the Atmega328p just isn't worth utilising unless there is an extreme cost or code minimisation consideration
As an example, here are some temperature data I took last year on a different project where I used the slightly better internal temperature sensor of the DS3231 RTC and the purpose-built LM35CAZ temperature sensor which were compared to the calibrated internal temperature sensor of the Atmega328p:
as you can see, it's not really worth it if alternative sensors are available... And is also the reason you're unlikely to find any examples of people actually using the internal temperature sensor for applications
I appreciate where you're coming from, as the internal temperature sensor of the Atmega328p is internal by design and removes any artefacts from using a resistive temperature sensor that we're using. However, the drive current we are using for the temperature sensor is 10 uA and the resistance of the PT1000 is ~1000 ohms at room temperature correlating to a heat loss of 100 nW (basically nothing).
Thanks for pointing it out though! Thinking about it more, we may actually use it as well for comparative purposes
Interesting! I didn't consider the differing clock speeds in a PC but that does make a lot of sense and explains why we wouldn't see too much difference purely from changing code. Thanks!
I didn't say that the internal sensor was good. I thought it might be something to evaluate. I thought, a decent study would have some interesting hypothesis, so an experiment would lead to some interesting conclusion. So far, I haven't recognized anything like that from what you've posted.
From this discussion, I’m thinking thermal inertia and the testing environment are going to have a lot of effect on the relatively small changes observed.
Tests in a controlled environment, with long cycle times might help.
To add to what @wildbill said, I think you misunderstand complexity from the point of view of the processor.
This:
while( (millis() - heatingUpStart) < TIME ){
log(exp(3.14159265358))/sqrt(2.71828182845);
}
Might seem complex to you but all the CPU sees is machine instructions coming at it from flash, which it executes then the asks for the next instruction. The processor knows nothing about your concept of complexity. Whether the final result is 'complex' to you or just something 'simple' like adding 1 to a variable a few times, it's all the same to the processor, just a long string of machine instructions, none of which are complex to the machine. The complexity emerges at a higher level by the way those instructions are organised, but the processor does not know or care about that.
Interesting project though, I'm sure you'll learn something from it.
I wonder though, if the heat dissipation isn't just a direct function of the applied voltage and current, which is much easier to measure, and with much higher bandwidth.
So I have a question. If the processor is always running code at the same rate regardless of what the code is, wouldn't the "number crunching" and "running a loop" be the same?
This processor doesn't have a throttle or clock frequency control.
Assuming you are not interested in the temperature rise due to loads on the output pins I would think the only modes you would have are:
Sleep and any other low power loads.
Running normal
enabling all the internal hardware (timers, a/d etc).
In addition I guess you could run the processor with different clock speeds and internal vs external.
You can dynamically change the operating frequency of the microcontroller through the OSCCAL register and so with the same program you will be able to monitor the temperature at different speeds.