Calculate the actual temperature using the following formula:
((110°C - 30°C) / (TS_CAL2 - TS_CAL1)) * (TS_DATA - TS_CAL1) + 30°C
Where:
• TS_CAL2 is the temperature sensor calibration value acquired at 110°C
• TS_CAL1 is the temperature sensor calibration value acquired at 30°C
• TS_DATA is the actual temperature sensor output value converted by ADC
But I can not read TS_CAL1 and TS_CAL2 ( Marshal.ReadInt32((IntPtr)0x1FF1E820) -> exception OR Marshal.ReadInt16((IntPtr)0x1FF1E820) -> 0).
And need Set the TSEN bit in the ADCx_CCR register (24 bit) to wake up the temperature sensor from power - down mode.
We cook / heat the board up from range ~30°C to ~120°C and see that TS_CAL1 and TS_CAL2 don’t change their values. Each board has a bit different, but not much far from those numbers.
SC20100S:
TS_CAL1 = 0x3058;
TS_CAL2 = 0x4006;
SC20260D:
TS_CAL1 = 0x2FB4;
TS_CAL2 = 0x3F71;
base on that, we have internal processor temperature around ~38°C.
Hope code below help
const uint PERIPH_BASE = 0x40000000;
const uint D3_AHB1PERIPH_BASE = (PERIPH_BASE +0x18020000);
const uint ADC3_COMMON_BASE = (D3_AHB1PERIPH_BASE + 0x6300);
var reTempetureWakup = (IntPtr)(ADC3_COMMON_BASE + 8);
var reTempetureWakupValue = Marshal.ReadInt32(reTempetureWakup);
reTempetureWakupValue |= (1 << 23);
Marshal.WriteInt32(reTempetureWakup, reTempetureWakupValue);
while (true)
{
var v = adcChannel18.ReadValue();
var ts1 = 0x3058; // Marshal.ReadInt32(regTS_CAL1);
var ts2 = 0x4006; // Marshal.ReadInt32(regTS_CAL2);
var t1 = (110 - 30) * 1.0;
var t2 = (ts2 - ts1) * 1.0;
var t3 = (v - ts1) * 1.0;
var temp = t1 / t2 * t3 + 30;
Debug.WriteLine("temp " + temp);
}
For me, the code above returns 12°C on the SC20100S, at a room temperature of approximately 23°C. Could the calibration values TS_CAL1 and TS_CAL2 be obtained via interop (Runtime Loadable Interops)? By the way, where did the interop from TinyCLR 2.0 go? I can’t find it in libraries and documentation.
I use the same published code as you, I copied it. Moreover, now I come to one crazy thing. When I insert Thread.Sleep(x) before adcChannel18.ReadValue, for different x it returns a different temperature.
x = 0, temp = 54°C
x = 1, temp = 50°C
x = 2, temp = 46°C
x = 3, temp = 42°C
x = 4, temp = 39°C
x = 5, temp = 35°C
x = 10, temp = 22°C
x = 15, temp = 13°C
x > 17, temp = 12°C
yes that’s their stated plan. Processors have significant power increases that largely negates the need for this. If you have a need for something that’s not “custom” that others will also need, then GHI will consider baking it into the framework