14
14
15
15
// #define DEBUG
16
16
17
- String ver = " 2.5 " ; // bump minor version number on small changes, major on large changes, eg when eeprom layout changes
17
+ String ver = " 2.6 " ; // bump minor version number on small changes, major on large changes, eg when eeprom layout changes
18
18
19
19
// for Albert Lim's version, extra features: outputs a pulse on the TTL serial
20
20
// port to open the drawer automatically at the beginning of ramp down
21
21
// #define OPENDRAWER
22
22
23
+ #include " temperature.h"
24
+
25
+ tcInput A , B ; // the two structs for thermocouple data
26
+
23
27
// data type for the values used in the reflow profile
24
28
struct profileValues {
25
29
int soakTemp;
@@ -34,6 +38,7 @@ struct profileValues {
34
38
profileValues activeProfile; // the one and only instance
35
39
36
40
41
+
37
42
int idleTemp = 50 ; // the temperature at which to consider the oven safe to leave to cool naturally
38
43
39
44
int fanAssistSpeed = 50 ; // default fan speed
@@ -130,7 +135,6 @@ double rampRate = 0;
130
135
131
136
double rateOfRise = 0 ; // the result that is displayed
132
137
133
- double temp1, temp2;
134
138
double readingsT1[NUMREADINGS ]; // the readings used to make a stable temp rolling average
135
139
double readingsT2[NUMREADINGS ];
136
140
unsigned short index = 0 ; // the index of the current reading
@@ -164,18 +168,6 @@ enum state {
164
168
state currentState = idle, lastState = idle;
165
169
boolean stateChanged = false ;
166
170
167
-
168
- char spi_transfer(volatile char data)
169
- {
170
- SPDR = data; // Start the transmission
171
- while (! (SPSR & (1 << SPIF ))) // Wait the end of the transmission
172
- {
173
- };
174
- return SPDR ; // return the received byte
175
- }
176
-
177
-
178
-
179
171
void abortWithError (int error ){
180
172
// set outputs off for safety.
181
173
digitalWrite(8 ,LOW );
@@ -212,76 +204,32 @@ void abortWithError(int error){
212
204
}
213
205
}
214
206
207
+ void displayThermocoupleData (struct tcInput * input ){
208
+ switch (input- > stat){
209
+ case 0 :
215
210
216
- double getTemperature (){
217
- // this does not do chip select for you, chip select first, then call getTemperature() for the result from the selected IC, dont'
218
- // forget to release chip select when done
219
- // we simply read four bytes from SPI here...
220
- // bit 31 is temperature sign, 30-18 are 14 bit thermocouple reading, 17 is reserved, 16 is fault bit, 15 is internal reference sign,
221
-
222
- // 14-4 internal ref 12 bit reading, 3 reserved, 2 short to vcc bit, 1 short to gnd bit, 0 is open circuit bit
223
- // (last three being set = error!!)
224
- // we;re being incredibly lazy and only reading the first two bytes
225
-
226
- uint16_t result = 0x0000 ;
227
- byte reply = 0 ;
211
+ lcd. print(input- > temperature,1 );
212
+ lcd. print((char )223 );// degrees symbol!
213
+ lcd. print(" C" );
228
214
229
- char data = 0 ; // dummy data to write
230
- // spi_transfer(data);
231
- reply = spi_transfer(data);
232
- result = reply << 8 ;
233
- reply = spi_transfer(data);
234
- result = result | reply;
215
+ break ;
235
216
236
- spi_transfer(data);
237
- reply = spi_transfer(data); // get the last byte, we care about the error bits
238
- if (reply & 1 ){
239
- abortWithError(3 );
217
+ case 1 :
218
+ lcd. print(" ---" );
219
+ break ;
240
220
241
221
}
242
- // lcd.clear();
243
- // lcd.print(result, BIN);
244
- result = (uint16_t)result >> 2 ;
245
- // lcd.clear();
246
-
247
- result = result * 0.25 ;
248
-
249
- return result;
250
-
251
- }
252
-
253
222
254
- double getAirTemperature1 (){
255
- digitalWrite(CHIPSELECT1 , LOW );
256
- double temp = getTemperature();
257
- digitalWrite(CHIPSELECT1 , HIGH );
258
- return temp;
259
- }
260
-
261
- double getAirTemperature2 (){
262
- digitalWrite(CHIPSELECT2 , LOW );
263
- double temp = getTemperature();
264
- digitalWrite(CHIPSELECT2 , HIGH );
265
- return temp;
266
- }
267
-
268
- boolean getJumperState (){
269
- boolean result = false ; // jumper open
270
- unsigned int val = analogRead(7 );
271
- if (val < 500 ) result = true ;
272
- return result;
273
223
}
274
224
275
225
void updateDisplay (){
276
226
lcd. clear();
277
227
278
- lcd. print(averageT1,1 );
279
- lcd. print((char )223 );// degrees symbol!
280
- lcd. print(" C " );
228
+ displayThermocoupleData(& A );
281
229
282
- lcd. print(averageT2, 1 );
283
- lcd . print(( char ) 223 ); // degrees symbol!
284
- lcd . print( " C " );
230
+ lcd. print(" " );
231
+
232
+ displayThermocoupleData( & B );
285
233
286
234
if (currentState!= idle){
287
235
lcd. setCursor(16 ,0 );
@@ -331,10 +279,18 @@ void updateDisplay(){
331
279
lcd. print(" C/S" );
332
280
}
333
281
334
-
282
+ boolean getJumperState (){
283
+ boolean result = false ; // jumper open
284
+ unsigned int val = analogRead(7 );
285
+ if (val < 500 ) result = true ;
286
+ return result;
287
+ }
335
288
336
289
void setup ()
337
290
{
291
+ A . chipSelect = 10 ; // define the chip select pins for the two MAX31855 ICs
292
+ B . chipSelect = 2 ;
293
+
338
294
boolean jumperState = getJumperState(); // open for T962(A/C) use, closed for toaster conversion kit keypad
339
295
myMenu. init(& control, & lcd, jumperState);
340
296
@@ -369,9 +325,9 @@ void setup()
369
325
// toby... over to you.
370
326
control. addItem(& profileLoad);
371
327
control. addItem(& profileSave);
372
- // profileLoadSave.addChild(&profile_number);
373
- // profile_number.addItem(&load_profile);
374
- // load_profile.addItem(&save_profile);
328
+ // profileLoadSave.addChild(&profile_number);
329
+ // profile_number.addItem(&load_profile);
330
+ // load_profile.addItem(&save_profile);
375
331
376
332
377
333
// fan speed control
@@ -405,10 +361,10 @@ void setup()
405
361
loadFanSpeed();
406
362
407
363
// setting up SPI bus
408
- digitalWrite(CHIPSELECT1 , HIGH );
409
- digitalWrite(CHIPSELECT2 , HIGH );
410
- pinMode(CHIPSELECT1 , OUTPUT );
411
- pinMode(CHIPSELECT2 , OUTPUT );
364
+ digitalWrite(A . chipSelect , HIGH );
365
+ digitalWrite(B . chipSelect , HIGH );
366
+ pinMode(A . chipSelect , OUTPUT );
367
+ pinMode(B . chipSelect , OUTPUT );
412
368
pinMode(DATAOUT , OUTPUT );
413
369
pinMode(SPICLOCK ,OUTPUT );
414
370
// pinMode(10,OUTPUT);
@@ -429,7 +385,7 @@ void setup()
429
385
// CPHA - Samples data on the falling edge of the data clock when 1, rising edge when 0'
430
386
// SPR1 and SPR0 - Sets the SPI speed, 00 is fastest (4MHz) 11 is slowest (250KHz)
431
387
432
- SPCR = (1 << SPE )| (1 << MSTR )| (1 << CPHA )| ( 1 << SPR1 ) | ( 1 << SPR0 ) ;// SPI enable bit set, master, data valid on falling edge of clock
388
+ SPCR = (1 << SPE )| (1 << MSTR )| (1 << CPHA );// SPI enable bit set, master, data valid on falling edge of clock
433
389
434
390
clr= SPSR ;
435
391
clr= SPDR ;
@@ -442,10 +398,14 @@ void setup()
442
398
// turn the PID on
443
399
PID . SetMode (AUTOMATIC );
444
400
445
- int temp = getAirTemperature1();
446
- runningTotalRampRate = temp * NUMREADINGS ;
401
+ readThermocouple(& A );
402
+
403
+ if (A . stat != 0 ){
404
+ abortWithError(3 );
405
+ }
406
+ runningTotalRampRate = A . temperature * NUMREADINGS ;
447
407
for (int i = 0 ; i< NUMREADINGS ; i++ ){
448
- airTemp[i]= temp ;
408
+ airTemp[i]= A . temperature ;
449
409
}
450
410
451
411
@@ -463,7 +423,7 @@ void setup()
463
423
delay (7500 );
464
424
465
425
myMenu. showCurrent();
466
-
426
+
467
427
}
468
428
469
429
@@ -477,14 +437,24 @@ void loop()
477
437
#endif
478
438
lastUpdate = millis ();
479
439
480
- temp1 = getAirTemperature1();
481
- temp2 = getAirTemperature2();
440
+ readThermocouple(& A );// read the thermocouple
441
+ readThermocouple(& B );// read the thermocouple
442
+
443
+ if (A . stat != 0 ){
444
+ abortWithError(3 );
445
+ }
446
+
482
447
// keep a rolling average of the temp
483
448
totalT1 -= readingsT1[index]; // subtract the last reading
484
449
totalT2 -= readingsT2[index];
485
450
486
- readingsT1[index] = temp1; // read the thermocouple
487
- readingsT2[index] = temp2; // read the thermocouple
451
+ readingsT1[index] = A . temperature;
452
+ if (B . stat == 0 ){
453
+ readingsT2[index] = B . temperature;
454
+ }
455
+ else {
456
+ readingsT2[index] = 0 ;
457
+ }
488
458
489
459
totalT1 += readingsT1[index]; // add the reading to the total
490
460
totalT2 += readingsT2[index];
@@ -532,7 +502,12 @@ void loop()
532
502
Serial . print(" 0,0,0,0,0," );
533
503
Serial . print(averageT1);
534
504
Serial . print(" ," );
535
- Serial . print(averageT2);
505
+ if (B . stat == 0 ){ // only print the second C data if the input is valid
506
+ Serial . print(averageT2);
507
+ }
508
+ else {
509
+ Serial . print(" 999" );
510
+ }
536
511
#ifdef DEBUG
537
512
Serial . print(" ," );
538
513
Serial . print(freeMemory());
@@ -553,7 +528,12 @@ void loop()
553
528
Serial . print(" ," );
554
529
Serial . print(averageT1);
555
530
Serial . print(" ," );
556
- Serial . print(averageT2);
531
+ if (B . stat == 0 ){ // only print the second C data if the input is valid
532
+ Serial . print(averageT2);
533
+ }
534
+ else {
535
+ Serial . print(" 999" );
536
+ }
557
537
#ifdef DEBUG
558
538
Serial . print(" ," );
559
539
Serial . print(freeMemory());
@@ -976,4 +956,7 @@ void loadLastUsedProfile(){
976
956
977
957
978
958
979
-
959
+
960
+
961
+
962
+
0 commit comments