' -------------------------------------------------------------------------------------------------
'  The PT100/500/1000 sensor must be connected with 3 or 4 wires
'  as explained in the ADC24 documentation
' -------------------------------------------------------------------------------------------------
'  And the HAL must be programmed as follows:
'  Pin  7 = ADC24 / Pins > 4 / Samples/sec = 1000 / Filter = Fast
'  Pin 21 = Max = 3.3 / Min = -3.3 / Response Speed (grayed) = 30 / Diff.  / Gain = 1 / Not biased
'  Pin 23 = Max = 3.3 / Min = 0    / Response Speed (grayed) = 30 / Single / Gain = 1 / Not biased
' -------------------------------------------------------------------------------------------------
Variable Numeric Slot_PT100_Volt1   = 21
Variable Numeric Slot_PT100_VResI   = 23
Variable Numeric Slot_PT100_Temp    = 25

Load Theremino_HAL.exe
Load Theremino_SlotViewer.exe
Load Theremino_SignalScope.exe
Load Hide

Option Speed 9
Loop
Stop

Label EventStop
	Load CloseApps Theremino_HAL.exe
	Load CloseApps Theremino_SlotViewer.exe
	Load CloseApps Theremino_SignalScope.exe
End

Label Loop
	Read_PT100
	Wait Seconds 0.01
Goto Loop

' =============================================== READ PT100
Variable Numeric c0     = -245.19
Variable Numeric c1     =    2.5293
Variable Numeric c2     =   -0.066046
Variable Numeric c3     =    0.0040422
Variable Numeric c4     =   -0.0000020697
Variable Numeric c5     =   -0.025422
Variable Numeric c6     =    0.0016883
Variable Numeric c7     =   -0.0000013601
Variable Numeric RPT    =  100                ' Sensor resistance value (100 500 or 1000)
Variable Numeric ResI   =  990                ' Resistor to measure the current (1K to 10K)

Variable Numeric R1                           ' Measured sensor resistance
Variable Numeric Volt1
Variable Numeric VResI
Variable Numeric Temp

Label Read_PT100
	Volt1 = Slot(Slot_PT100_Volt1)
	VResI = Slot(Slot_PT100_VResI)
	'
	R1 = ResI * Volt1 / VResI
	'
	R1 = R1 * 100 / RPT  ' <-- Normalize to 100 for PT500 and PT 1000
	Temp =  c0 + R1 * (c1 + R1 * (c2 + R1 * (c3 + c4 * R1))) / (1 + R1 * (c5 + R1 * (c6 + c7 * R1)))
	'
	Print "Temperature = " + Format(Temp, "0.0") + "°C" + CRLF
	Slot(Slot_PT100_Temp) = Temp
Return





'BOOKMARKS 

'EDITEDLINES -1 3 3 4 5 4 6 4 0 4 8 4 -1 3 7 4 26 5 -1 9 -1 7 23 10 24 10 25 10 

