Thermocouple - When fun and frugality are more important than dead-on accuracy

mrburnette

Senior Member
12-05-12 Note: more here: Blog: Thought-on-thermocouples

For situation(s) where dead-on accuracy is not required. This is intended to be a POC and a fun project, not intended to compete for real serious action, but may be useful conceptually. As written, the code will run from about 23C to 279C, the limit of 256 eeprom addresses - but, the table can be adjusted upwards to take higher temperatures with a few changes in the looping and conditional logic. The FOR / NEXT loop runs the addresses of 0 to 255, but the logic is looking at the data value to match to the millivolts on the AD line ( times X10); therefore, 1mV on the AD is processed as 10mV. The NIST table is also X10 and rounded, so it is possible to rework the table and use any 256 consecutive range of NIST normalized values.

Goal: Use the low-end PICAXE and a thermocouple without any instrumentation amps or compensation.
How: Use the internal 10-BIT AD with a 1.024V internal reference to create a 1mV per step voltmeter. Incorporate normalized and rounded NIST table to do temperature lookup. Use the internal temperature sensor to gauge and correct COLD Junction compensation.

Caveat: There are lots of assumptions in this program, specifically one big one regarding the linear nature of T thermocouples... I ran a trend in Excel and R^2 comes up to about 0.99 but not every thermocouple exhibits characteristics such as this. The T would not have been quiet so forgiving had I narrowed the ranges rather than work with the entire NIST span of numbers. Not also, the R^2 was based upon 4-digit accuracy and NOT on the integer-rounded numbers used in the PICAXE BASIC code below. (One is NOT suppose to add temperature, but one is suppose to look up and add voltages, then convert the voltage to temperature. However careful inspection of the table in the area of 20C shows that adding temp or voltage gives the same answer.)

Homemade Type "T" thermocouple
NIST tables
PICAXE08M2

Code:
; 147 bytes
; by M. Ray Burnette 20120508 as POC for using a Thermocouple Type T
; Without thermocouple amplification or conditioning
; Thermocouple tables courtesy of NIST: http://srdata.nist.gov/its90/download/download.html
; Program is placed in public domain by author for any/all non-profit purposes
;
#Picaxe 08M2				; PICAXE 08M2+ used in prototype
#Terminal 4800
;#no_data

Symbol ADval = w0				; b1:b0
Symbol DegCx = b2				; Thermistor "HOT" junction
Symbol DegCi = b3				; "COLD" junction is the CHIP/Breadboard
Symbol mV10  = w2				; b5:b4
Symbol VMINUS_0V_VPLUS_FVR = %011	; Page 28, Man#2
Symbol Channel = 4			; 08M2 Physical PIN#3, Port C.4

LET ADCsetup = %0000000000010000	; Channel 4 == C.4 / Page33, Man#2

Do

  readinternaltemp IT_5V0,-10, DegCi     ; Modify -10 so that connected Thermocouple at room temp (HOT/COLD ends) reads room temp
  Pause 500
  
  fvrsetup FVR1024			; set FVR as 1.024V reference = 1mV / step
  ;fvrsetup FVR2048			; set FVR as 2.048V reference = 2mV / step
  ADCconfig VMINUS_0V_VPLUS_FVR
  
  Pause 500
  ReadAdc10 Channel, ADval	; ADval = millivolts
  ADval = ADval - 2		; Specific 08M2 offset voltage in my prototype: AD output should read 0 at room temperature (both junctions)
  ADval = ADval * 10		; millivolts X 10 to match table configuration
  ; To calculate offset, with hot junction and cold junction at same temp ADval ==0

  ; PICAXE EEPROM only 256 bytes, I elected to use the first 256 but any consecutive group is OK
  For DegCx = 0 to 255		; Normalized NIST Type T table is 10X true mV value & Rounded
  	Read DegCx, mV10

  	if mV10 = ADval then		; If the index points to a match then GREAT
  		EXIT
  	ElseIf mV10 > ADval then	; No exact match and we went too far, back up 1
  		DegCx = DegCx - 1		; Select previous temperature before greater-than
  		Read DegCx, mV10		; Re-read
  		EXIT
	endif
  Next

  DegCx = DegCx + DegCi			; assuming a linear relationship of temp/mV
  ADval = ADval / 10			; normalize to original AD value
  ; Send it to PC for terminal display
  sertxd("degree C= ", #DegCx," ... Thermocouple mV= ",#ADval, CR, LF)
  
Loop

; Below data comes from cut & paste from Excel file: Type_T_mvX10rounded.xls
; Type "T" thermocouple millivolts X10 rounded - only 256 bytes in EEPROM
; Temperature in degrees Celsius 
;         ADDRESS+	0		1		2		3		4		5		6		7		8		9	
EEPROM	0	,(	0	,	0	,	1	,	1	,	2	,	2	,	2	,	3	,	3	,	4	)
EEPROM	10	,(	4	,	4	,	5	,	5	,	5	,	6	,	6	,	7	,	7	,	7	)
EEPROM	20	,(	8	,	8	,	9	,	9	,	10	,	10	,	10	,	11	,	11	,	12	)
EEPROM	30	,(	12	,	12	,	13	,	13	,	14	,	14	,	14	,	15	,	15	,	16	)
EEPROM	40	,(	16	,	17	,	17	,	17	,	18	,	18	,	19	,	19	,	20	,	20	)
EEPROM	50	,(	20	,	21	,	21	,	22	,	22	,	23	,	23	,	23	,	24	,	24	)
EEPROM	60	,(	25	,	25	,	26	,	26	,	26	,	27	,	27	,	28	,	28	,	29	)
EEPROM	70	,(	29	,	30	,	30	,	30	,	31	,	31	,	32	,	32	,	33	,	33	)
EEPROM	80	,(	34	,	34	,	34	,	35	,	35	,	36	,	36	,	37	,	37	,	38	)
EEPROM	90	,(	38	,	39	,	39	,	40	,	40	,	40	,	41	,	41	,	42	,	42	)
EEPROM	100	,(	43	,	43	,	44	,	44	,	45	,	45	,	46	,	46	,	47	,	47	)
EEPROM	110	,(	48	,	48	,	48	,	49	,	49	,	50	,	50	,	51	,	51	,	52	)
EEPROM	120	,(	52	,	53	,	53	,	54	,	54	,	55	,	55	,	56	,	56	,	57	)
EEPROM	130	,(	57	,	58	,	58	,	59	,	59	,	60	,	60	,	61	,	61	,	62	)
EEPROM	140	,(	62	,	63	,	63	,	64	,	64	,	65	,	65	,	66	,	66	,	67	)
EEPROM	150	,(	67	,	68	,	68	,	69	,	69	,	70	,	70	,	71	,	71	,	72	)
EEPROM	160	,(	72	,	73	,	73	,	74	,	74	,	75	,	75	,	76	,	76	,	77	)
EEPROM	170	,(	77	,	78	,	78	,	79	,	79	,	80	,	80	,	81	,	81	,	82	)
EEPROM	180	,(	82	,	83	,	83	,	84	,	84	,	85	,	86	,	86	,	87	,	87	)
EEPROM	190	,(	88	,	88	,	89	,	89	,	90	,	90	,	91	,	91	,	92	,	92	)
EEPROM	200	,(	93	,	93	,	94	,	94	,	95	,	96	,	96	,	97	,	97	,	98	)
EEPROM	210	,(	98	,	99	,	99	,	100	,	100	,	101	,	101	,	102	,	103	,	103	)
EEPROM	220	,(	104	,	104	,	105	,	105	,	106	,	106	,	107	,	107	,	108	,	109	)
EEPROM	230	,(	109	,	110	,	110	,	111	,	111	,	112	,	112	,	113	,	113	,	114	)
EEPROM	240	,(	115	,	115	,	116	,	116	,	117	,	117	,	118	,	118	,	119	,	120	)
EEPROM	250	,(	120	,	121	,	121	,	122	,	122	,	123	)
; Excess table ... Pick any 256 consecutive values for range needed to cover
#rem

,	123	,	124	,	125	,	125	)
EEPROM	260	,(	126	,	126	,	127	,	127	,	128	,	129	,	129	,	130	,	130	,	131	)
EEPROM	270	,(	131	,	132	,	133	,	133	,	134	,	134	,	135	,	135	,	136	,	137	)
EEPROM	280	,(	137	,	138	,	138	,	139	,	139	,	140	,	141	,	141	,	142	,	142	)
EEPROM	290	,(	143	,	143	,	144	,	145	,	145	,	146	,	146	,	147	,	147	,	148	)
EEPROM	300	,(	149	,	149	,	150	,	150	,	151	,	152	,	152	,	153	,	153	,	154	)
EEPROM	310	,(	154	,	155	,	156	,	156	,	157	,	157	,	158	,	159	,	159	,	160	)
EEPROM	320	,(	160	,	161	,	162	,	162	,	163	,	163	,	164	,	164	,	165	,	166	)
EEPROM	330	,(	166	,	167	,	167	,	168	,	169	,	169	,	170	,	170	,	171	,	172	)
EEPROM	340	,(	172	,	173	,	173	,	174	,	175	,	175	,	176	,	176	,	177	,	178	)
EEPROM	350	,(	178	,	179	,	179	,	180	,	181	,	181	,	182	,	182	,	183	,	184	)
EEPROM	360	,(	184	,	185	,	185	,	186	,	187	,	187	,	188	,	188	,	189	,	190	)
EEPROM	370	,(	190	,	191	,	192	,	192	,	193	,	193	,	194	,	195	,	195	,	196	)
EEPROM	380	,(	196	,	197	,	198	,	198	,	199	,	199	,	200	,	201	,	201	,	202	)
EEPROM	390	,(	203	,	203	,	204	,	204	,	205	,	206	,	206	,	207	,	207	,	208	)
EEPROM	400	,(	209	)																		
#endrem

- Ray

T Chart.JPG

View attachment Excel-Thermocouple.zip
 
Last edited:
Top