Posted: 11:54pm 24 Jul 2015 |
Copy link to clipboard |
Print this post |
|
PIC32MX chips have an internal temperature sensor. This works by applying a constant current to an internal diode and measuring the forward voltage threshold which varies with temperature. This can then be measured by the ADC in the chip.
Unfortunately, the voltage only changes by about 3mV/degC and the measurement accuracy of the ADC with VCC at 3.3V is also about 3mV so it will only read to 1 degree. Also the threshold voltages of the diodes will vary between chips.
The last downside is that this will only work on the MM (MX170) and not the MM+ (MX470) due to the constant current source in the MM+ being non-functional (another Microchip silicon errata).
Given all this, it may be useful.
This code is tested on both the 28 and 44-pin MM chips running 4.7b23.
Note that the temperature reading can be calibrated for an individual chip by putting a frig-factor in the call to the read routine
do
print readinternaltemp()
pause 1000
loop
' Function to read the internal temperature on a 28 or 44-pin Micromite
' Takes one optional parameter which is an offset in degrees to compensate for chip variations
' so readinternaltemp(2) would add 2 degrees to the reading
' NB: the accuracy is relatively poor due to the limitations of the 10-bit ADC
'
CFunction readinternaltemp
00000000
27bdffc8 afbf0034 afbe0030 afb7002c afb60028 afb50024 afb40020 afb3001c
afb20018 afb10014 afb00010 afa40038 3c030200 34638001 3c02bf81 ac43a200
3c031000 3c02bf88 ac431064 3c02bf88 ac401068 34038000 3c02bf81 ac439004
24100001 00008821 3c12bf81 3c13000d 3c14bf88 3c15bf88 3c16bf81 3c17ffff
10000002 3c1ebf81 26100001 ae539040 ae806118 aea06108 aed79050 34028f00
afc29020 24060003 3c03bf81 ac669010 240300e4 3c02bf81 ac439000 34028000
3c06bf81 acc29008 3c04bf88 3c031000 8c821030 00431024 1040fffd 3c02bf81
8c429070 02228821 24020001 12020039 3c031000 3c02bf88 ac431034 3c029d00
8c420004 0040f809 240403e8 2a020009 1440ffde 26100001 3c031000 3c02bf88
ac431064 3c02bf88 ac401068 34038000 3c02bf81 ac439004 3c02bf81 ac40a200
8fa30038 14600009 24020588 00518823 26220007 2a230000 0223100a 000210c3
2442001c 1000000f 00021fc3 00518823 26220007 2a240000 0044880b 001120c3
2484001c 00042fc3 8fa60038 8cc20000 8cc30004 00821021 0044202b 00a31821
00831821 8fbf0034 8fbe0030 8fb7002c 8fb60028 8fb50024 8fb40020 8fb3001c
8fb20018 8fb10014 8fb00010 03e00008 27bd0038 3c02bf88 ac431034 3c029d00
8c420004 0040f809 240403e8 1000ffa6 00008821
End CFunction 'MIPS32 M4K |