Skip to content

Commit e2edba5

Browse files
committed
v2.6 firmware update
1 parent 2454a81 commit e2edba5

File tree

2 files changed

+130
-92
lines changed

2 files changed

+130
-92
lines changed

ReflowController/ReflowController.pde

Lines changed: 75 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414

1515
//#define DEBUG
1616

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
1818

1919
// for Albert Lim's version, extra features: outputs a pulse on the TTL serial
2020
// port to open the drawer automatically at the beginning of ramp down
2121
//#define OPENDRAWER
2222

23+
#include "temperature.h"
24+
25+
tcInput A, B; // the two structs for thermocouple data
26+
2327
// data type for the values used in the reflow profile
2428
struct profileValues {
2529
int soakTemp;
@@ -34,6 +38,7 @@ struct profileValues {
3438
profileValues activeProfile; // the one and only instance
3539

3640

41+
3742
int idleTemp = 50; // the temperature at which to consider the oven safe to leave to cool naturally
3843

3944
int fanAssistSpeed = 50; // default fan speed
@@ -130,7 +135,6 @@ double rampRate = 0;
130135

131136
double rateOfRise = 0; // the result that is displayed
132137

133-
double temp1, temp2;
134138
double readingsT1[NUMREADINGS]; // the readings used to make a stable temp rolling average
135139
double readingsT2[NUMREADINGS];
136140
unsigned short index = 0; // the index of the current reading
@@ -164,18 +168,6 @@ enum state {
164168
state currentState = idle, lastState = idle;
165169
boolean stateChanged = false;
166170

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-
179171
void abortWithError(int error){
180172
// set outputs off for safety.
181173
digitalWrite(8,LOW);
@@ -212,76 +204,32 @@ void abortWithError(int error){
212204
}
213205
}
214206

207+
void displayThermocoupleData(struct tcInput* input){
208+
switch(input->stat){
209+
case 0:
215210

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");
228214

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;
235216

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;
240220

241221
}
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-
253222

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;
273223
}
274224

275225
void updateDisplay(){
276226
lcd.clear();
277227

278-
lcd.print(averageT1,1);
279-
lcd.print((char)223);// degrees symbol!
280-
lcd.print("C ");
228+
displayThermocoupleData(&A);
281229

282-
lcd.print(averageT2,1);
283-
lcd.print((char)223);// degrees symbol!
284-
lcd.print("C");
230+
lcd.print(" ");
231+
232+
displayThermocoupleData(&B);
285233

286234
if(currentState!=idle){
287235
lcd.setCursor(16,0);
@@ -331,10 +279,18 @@ void updateDisplay(){
331279
lcd.print("C/S");
332280
}
333281

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+
}
335288

336289
void setup()
337290
{
291+
A.chipSelect = 10; // define the chip select pins for the two MAX31855 ICs
292+
B.chipSelect = 2;
293+
338294
boolean jumperState = getJumperState(); // open for T962(A/C) use, closed for toaster conversion kit keypad
339295
myMenu.init(&control, &lcd, jumperState);
340296

@@ -369,9 +325,9 @@ void setup()
369325
// toby... over to you.
370326
control.addItem(&profileLoad);
371327
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);
375331

376332

377333
// fan speed control
@@ -405,10 +361,10 @@ void setup()
405361
loadFanSpeed();
406362

407363
// 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);
412368
pinMode(DATAOUT, OUTPUT);
413369
pinMode(SPICLOCK,OUTPUT);
414370
//pinMode(10,OUTPUT);
@@ -429,7 +385,7 @@ void setup()
429385
// CPHA - Samples data on the falling edge of the data clock when 1, rising edge when 0'
430386
// SPR1 and SPR0 - Sets the SPI speed, 00 is fastest (4MHz) 11 is slowest (250KHz)
431387

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
433389

434390
clr=SPSR;
435391
clr=SPDR;
@@ -442,10 +398,14 @@ void setup()
442398
//turn the PID on
443399
PID.SetMode(AUTOMATIC);
444400

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;
447407
for(int i =0; i<NUMREADINGS; i++){
448-
airTemp[i]=temp;
408+
airTemp[i]=A.temperature;
449409
}
450410

451411

@@ -463,7 +423,7 @@ void setup()
463423
delay(7500);
464424

465425
myMenu.showCurrent();
466-
426+
467427
}
468428

469429

@@ -477,14 +437,24 @@ void loop()
477437
#endif
478438
lastUpdate = millis();
479439

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+
482447
// keep a rolling average of the temp
483448
totalT1 -= readingsT1[index]; // subtract the last reading
484449
totalT2 -= readingsT2[index];
485450

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+
}
488458

489459
totalT1 += readingsT1[index]; // add the reading to the total
490460
totalT2 += readingsT2[index];
@@ -532,7 +502,12 @@ void loop()
532502
Serial.print("0,0,0,0,0,");
533503
Serial.print(averageT1);
534504
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+
}
536511
#ifdef DEBUG
537512
Serial.print(",");
538513
Serial.print(freeMemory());
@@ -553,7 +528,12 @@ void loop()
553528
Serial.print(",");
554529
Serial.print(averageT1);
555530
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+
}
557537
#ifdef DEBUG
558538
Serial.print(",");
559539
Serial.print(freeMemory());
@@ -976,4 +956,7 @@ void loadLastUsedProfile(){
976956

977957

978958

979-
959+
960+
961+
962+

ReflowController/temperature.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
3+
#ifndef TEMPERATURE_H
4+
#define TEMPERATURE_H
5+
6+
#include <Arduino.h>
7+
8+
typedef struct tcInput {
9+
double temperature;
10+
int stat;
11+
int chipSelect;
12+
13+
};
14+
15+
char spi_transfer(volatile char data)
16+
{
17+
SPDR = data; // Start the transmission
18+
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
19+
{
20+
};
21+
return SPDR; // return the received byte
22+
}
23+
24+
void readThermocouple(struct tcInput* input){
25+
digitalWrite(input->chipSelect, LOW);
26+
27+
uint32_t result = 0x0000;
28+
byte reply = 0;
29+
30+
char data = 0; // dummy data to write
31+
32+
for(int i = 0; i<4;i++){ // read the 32 data bits from the MAX31855
33+
reply = spi_transfer(data);
34+
result = result << 8;
35+
result |= reply;
36+
}
37+
//Serial.print("Read result is: ");
38+
//Serial.print(result, BIN);
39+
40+
result >>= 18;
41+
42+
uint16_t value = 0xFFF & result; // mask off the sign bit and shit to the correct alignment for the temp data
43+
44+
input->stat = reply & B111;
45+
46+
input->temperature = value * 0.25;
47+
48+
digitalWrite(input->chipSelect, HIGH);
49+
50+
}
51+
52+
53+
54+
#endif
55+

0 commit comments

Comments
 (0)