diff --git a/CAD/Datasheet/MAX31855.pdf b/CAD/Datasheet/MAX31855.pdf new file mode 100644 index 0000000..2ef87d3 Binary files /dev/null and b/CAD/Datasheet/MAX31855.pdf differ diff --git a/reflow_plate_fw/platformio.ini b/reflow_plate_fw/platformio.ini index 0c7f493..a9eb38c 100644 --- a/reflow_plate_fw/platformio.ini +++ b/reflow_plate_fw/platformio.ini @@ -18,8 +18,7 @@ monitor_speed = 115200 lib_deps = bodmer/TFT_eSPI@^2.3.70 br3ttb/PID@^1.2.1 - ;siruli/MAX6675@^2.1.0 - zhenek-kreker/MAX6675 with hardware SPI@^1.0.0 + robtillaart/MAX31855@^0.2.5 lib_ldf_mode = deep+ build_flags = -D USER_SETUP_LOADED=1 diff --git a/reflow_plate_fw/src/board.h b/reflow_plate_fw/src/board.h index 72dfa56..d25b4dc 100644 --- a/reflow_plate_fw/src/board.h +++ b/reflow_plate_fw/src/board.h @@ -8,8 +8,8 @@ // #define LCD_CS PB0 #define THERM_SS PB12 -#define THERM_MISO PB13 -#define THERM_CLK PB14 +#define THERM_MISO PB14 +#define THERM_CLK PB13 #define THERM_MOSI PB15 //not used diff --git a/reflow_plate_fw/src/lcd.cpp b/reflow_plate_fw/src/lcd.cpp index 73e5579..6fab460 100644 --- a/reflow_plate_fw/src/lcd.cpp +++ b/reflow_plate_fw/src/lcd.cpp @@ -59,7 +59,7 @@ uint32_t calcTime(uint32_t timeMs) return map((timeMs / 1000), 0, CHART_TIME_MAX, 0, CHART_W - CHART_Y_AXIS_OFFSET); } -std::vector temperatureReading; +std::vector temperatureReading; uint32_t lastReading = 0; #define TEMPINTERVAL 1000 diff --git a/reflow_plate_fw/src/thermo.cpp b/reflow_plate_fw/src/thermo.cpp index bb6eb03..c87bb55 100644 --- a/reflow_plate_fw/src/thermo.cpp +++ b/reflow_plate_fw/src/thermo.cpp @@ -1,40 +1,48 @@ #include "thermo.h" #include "controlloop.h" -MAX6675 thermocouple(THERM_SS, THERM_MISO, THERM_CLK); +//MAX6675 thermocouple(THERM_SS, THERM_MISO, THERM_CLK); +MAX31855 thermocouple(THERM_CLK, THERM_SS, THERM_MISO); //uint8_t CS, uint8_t MISO); + +// initialize the Thermocouple +//Adafruit_MAX31855 thermocouple(THERM_CLK, THERM_SS, THERM_MISO); uint32_t thermo_lastTime = 0; -double lastTemperature = 0; +float lastTemperature = 0; +float internal = 0; -bool simulation = true; +bool simulation = false; #define SIM_TEMP_STEP 1 #define SIM_TEMP_COOL 0.08 #define SIM_INTERVAL 100 uint32_t simTimer = 0; +uint32_t sampleTimer = 0; void initThermo() { - if(simulation) + thermocouple.begin(); + if (simulation) { - lastTemperature = TEMPERATURE_ROOM-20; + lastTemperature = TEMPERATURE_ROOM - 20; } } void handleThermo(void) { - if(simulation) + uint32_t timeNow = millis(); + if (simulation) { - uint32_t timeNow = millis(); - if(timeNow - simTimer > SIM_INTERVAL) + + if (timeNow - simTimer > SIM_INTERVAL) { - if(getOutputState()) + if (getOutputState()) { lastTemperature += SIM_TEMP_STEP; } else { - if(lastTemperature > TEMPERATURE_ROOM-20) + if (lastTemperature > TEMPERATURE_ROOM - 20) { lastTemperature -= SIM_TEMP_COOL; } @@ -44,33 +52,22 @@ void handleThermo(void) } else { - lastTemperature = thermocouple.readTempC(); - + if (timeNow - sampleTimer > THERMO_INTERVAL) + { + int state = thermocouple.read(); + lastTemperature = thermocouple.getTemperature(); + internal = thermocouple.getInternal(); + sampleTimer = timeNow; + } } } -double getTemperature(void) +float getTemperature(void) { return lastTemperature; //lastTemperature; } bool getThermoCoupleFault(void) { -#ifdef MAX31856 - uint8_t fault = thermocouple.readFault(); - if (fault) - { - if (fault & MAX6675_FAULT_CJRANGE) //Serial.println("Cold Junction Range Fault"); - if (fault & MAX31856_FAULT_TCRANGE) //Serial.println("Thermocouple Range Fault"); - if (fault & MAX31856_FAULT_CJHIGH) //Serial.println("Cold Junction High Fault"); - if (fault & MAX31856_FAULT_CJLOW) //Serial.println("Cold Junction Low Fault"); - if (fault & MAX31856_FAULT_TCHIGH) //Serial.println("Thermocouple High Fault"); - if (fault & MAX31856_FAULT_TCLOW) //Serial.println("Thermocouple Low Fault"); - if (fault & MAX31856_FAULT_OVUV) //Serial.println("Over/Under Voltage Fault"); - if (fault & MAX31856_FAULT_OPEN) //Serial.println("Thermocouple Open Fault"); - return true; - } -#else - return false; -#endif + return thermocouple.genericError(); } diff --git a/reflow_plate_fw/src/thermo.h b/reflow_plate_fw/src/thermo.h index e4197c2..095ed27 100644 --- a/reflow_plate_fw/src/thermo.h +++ b/reflow_plate_fw/src/thermo.h @@ -3,13 +3,14 @@ #include "Arduino.h" #include "board.h" -#include "max6675.h" +//#include "max6675.h" +#include "MAX31855.h" #define THERMO_INTERVAL 200 #define SMOOTHING_FACTOR 2 void initThermo(void); void handleThermo(void); -double getTemperature(void); +float getTemperature(void); bool getThermoCoupleFault(void);