Compare commits

...

5 Commits

Author SHA1 Message Date
d33566ad16 fix: touch and update constants 2021-11-17 17:23:31 +01:00
87899316b1 3d model 2021-09-04 15:33:42 +02:00
eddaa9003a added FT6206 flip 2021-08-30 13:49:46 +02:00
ddc6f271e8 cad design 2021-08-30 10:22:20 +02:00
c8d9052bcf changed to max31855 2021-08-25 12:34:33 +02:00
25 changed files with 540930 additions and 163 deletions

Binary file not shown.

BIN
CAD/3D/LCD.SLDPRT Normal file

Binary file not shown.

394634
CAD/3D/OUTPUT/UM2_case.gcode Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

126492
CAD/3D/OUTPUT/case.STL Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

BIN
CAD/3D/PSU_5V.SLDPRT Normal file

Binary file not shown.

BIN
CAD/3D/SSR40.SLDPRT Normal file

Binary file not shown.

Binary file not shown.

BIN
CAD/3D/case.SLDPRT Normal file

Binary file not shown.

BIN
CAD/3D/dril_template.SLDDRW Normal file

Binary file not shown.

Binary file not shown.

BIN
CAD/Datasheet/MAX31855.pdf Normal file

Binary file not shown.

View File

@@ -1,39 +0,0 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

View File

@@ -1,47 +0,0 @@
// See SetupX_Template.h for all options available
#define SSD1351_DRIVER
#define TFT_WIDTH 128
#define TFT_HEIGHT 128
#define STM32
#define TFT_SPI_PORT 1
#define SSD1351_1DOT5_INCH_128 // For 128 x 128 display
// Wiring:
// +-------------+------------+-------------------------------------------------------------------+
// | Display PCB | TFT_eSPI | Info |
// +-------------+------------+-------------------------------------------------------------------+
// | GND | GND (0V) | Common |
// | VCC | 5V or 3.3V | Better to power with 5V if display PCB supports it |
// | DIN | TFT_MOSI | SPI data |
// | SCK | TFT_SCLK | SPI clock |
// | DC | TFT_DC | Distinguish between a command or its data |
// | RST | TFT_RST | Hardware reset, can connect to MCU RST pin as well |
// | CS | TFT_CS | Chip select, Set to -1 if for manually use with multiple displays |
// +-------------+------------+-------------------------------------------------------------------+
//#define TFT_MOSI PA7
//#define TFT_SCLK PA5
#define TFT_DC PB1
#define TFT_RST PA12
#define TFT_CS PB0
#define LOAD_GLCD // Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
#define LOAD_FONT2 // Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
#define LOAD_FONT4 // Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
#define LOAD_FONT6 // Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
#define LOAD_FONT7 // 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:.
#define LOAD_FONT8 // Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
//#define LOAD_FONT8N // Alternative to Font 8 above, slightly narrower, so 3 digits fit a 160 pixel TFT
#define LOAD_GFXFF // FreeFonts- 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts
#define SMOOTH_FONT
#define SPI_FREQUENCY 20000000
//#define SPI_FREQUENCY 40000000 // Works after shielding the wires!

View File

@@ -0,0 +1,277 @@
#include "ft6206_touch.h"
/**************************************************************************/
/*!
@brief Instantiates a new FT6206 class
*/
/**************************************************************************/
// I2C, no address adjustments or pins
FT6206::FT6206() { touches = 0; }
/**************************************************************************/
/*!
@brief Setups the I2C interface and hardware, identifies if chip is found
@param thresh Optional threshhold-for-touch value, default is
FT6206_DEFAULT_THRESSHOLD but you can try changing it if your screen is
too/not sensitive.
@returns True if an FT6206 is found, false on any failure
*/
/**************************************************************************/
// bool begin(uint8_t thresh = FT62XX_DEFAULT_THRESHOLD, uint16_t width, uint16_t height, bool flip );
bool FT6206::begin(uint8_t sda, uint8_t scl, uint16_t width, uint16_t height, bool flip, uint8_t thresh) {
Wire.begin(sda, scl);
_width = width;
_height = height;
_flip = flip;
#ifdef FT6206_DEBUG
Serial.print("Vend ID: 0x");
Serial.println(readRegister8(FT62XX_REG_VENDID), HEX);
Serial.print("Chip ID: 0x");
Serial.println(readRegister8(FT62XX_REG_CHIPID), HEX);
Serial.print("Firm V: ");
Serial.println(readRegister8(FT62XX_REG_FIRMVERS));
Serial.print("Point Rate Hz: ");
Serial.println(readRegister8(FT62XX_REG_POINTRATE));
Serial.print("Thresh: ");
Serial.println(readRegister8(FT62XX_REG_THRESHHOLD));
// dump all registers
for (int16_t i = 0; i < 0x10; i++) {
Serial.print("I2C $");
Serial.print(i, HEX);
Serial.print(" = 0x");
Serial.println(readRegister8(i), HEX);
}
#endif
// change threshhold to be higher/lower
writeRegister8(FT62XX_REG_THRESHHOLD, thresh);
if (readRegister8(FT62XX_REG_VENDID) != FT62XX_VENDID) {
return false;
}
uint8_t id = readRegister8(FT62XX_REG_CHIPID);
if ((id != FT6206_CHIPID) && (id != FT6236_CHIPID) &&
(id != FT6236U_CHIPID)) {
return false;
}
return true;
}
/**************************************************************************/
/*!
@brief Determines if there are any touches detected
@returns Number of touches detected, can be 0, 1 or 2
*/
/**************************************************************************/
uint8_t FT6206::touched(void) {
uint8_t n = readRegister8(FT62XX_REG_NUMTOUCHES);
if (n > 2) {
n = 0;
}
return n;
}
/**************************************************************************/
/*!
@brief Queries the chip and retrieves a point data
@param n The # index (0 or 1) to the points we can detect. In theory we can
detect 2 points but we've found that you should only use this for
single-touch since the two points cant share the same half of the screen.
@returns {@link TS_Point} object that has the x and y coordinets set. If the
z coordinate is 0 it means the point is not touched. If z is 1, it is
currently touched.
*/
/**************************************************************************/
TS_Point FT6206::getPoint(uint8_t n) {
readData();
if ((touches == 0) || (n > 1)) {
return TS_Point(0, 0, 0);
} else {
if(_flip)
{
return TS_Point(_width - touchX[n], _height - touchY[n], 1);
}
else
{
return TS_Point(touchX[n], touchY[n], 1);
}
}
}
/************ lower level i/o **************/
/**************************************************************************/
/*!
@brief Reads the bulk of data from captouch chip. Fill in {@link touches},
{@link touchX}, {@link touchY} and {@link touchID} with results
*/
/**************************************************************************/
void FT6206::readData(void) {
uint8_t i2cdat[16];
Wire.beginTransmission(FT62XX_ADDR);
Wire.write((byte)0);
Wire.endTransmission();
Wire.requestFrom((byte)FT62XX_ADDR, (byte)16);
for (uint8_t i = 0; i < 16; i++)
i2cdat[i] = Wire.read();
#ifdef FT6206_DEBUG
for (int16_t i = 0; i < 16; i++) {
Serial.print("I2C $");
Serial.print(i, HEX);
Serial.print(" = 0x");
Serial.println(i2cdat[i], HEX);
}
#endif
touches = i2cdat[0x02];
if ((touches > 2) || (touches == 0)) {
touches = 0;
}
#ifdef FT6206_DEBUG
Serial.print("# Touches: ");
Serial.println(touches);
for (uint8_t i = 0; i < 16; i++) {
Serial.print("0x");
Serial.print(i2cdat[i], HEX);
Serial.print(" ");
}
Serial.println();
if (i2cdat[0x01] != 0x00) {
Serial.print("Gesture #");
Serial.println(i2cdat[0x01]);
}
#endif
for (uint8_t i = 0; i < 2; i++) {
touchX[i] = i2cdat[0x03 + i * 6] & 0x0F;
touchX[i] <<= 8;
touchX[i] |= i2cdat[0x04 + i * 6];
touchY[i] = i2cdat[0x05 + i * 6] & 0x0F;
touchY[i] <<= 8;
touchY[i] |= i2cdat[0x06 + i * 6];
touchID[i] = i2cdat[0x05 + i * 6] >> 4;
}
#ifdef FT6206_DEBUG
Serial.println();
for (uint8_t i = 0; i < touches; i++) {
Serial.print("ID #");
Serial.print(touchID[i]);
Serial.print("\t(");
Serial.print(touchX[i]);
Serial.print(", ");
Serial.print(touchY[i]);
Serial.print(") ");
}
Serial.println();
#endif
}
uint8_t FT6206::readRegister8(uint8_t reg) {
uint8_t x;
// use i2c
Wire.beginTransmission(FT62XX_ADDR);
Wire.write((byte)reg);
Wire.endTransmission();
Wire.requestFrom((byte)FT62XX_ADDR, (byte)1);
x = Wire.read();
#ifdef I2C_DEBUG
Serial.print("$");
Serial.print(reg, HEX);
Serial.print(": 0x");
Serial.println(x, HEX);
#endif
return x;
}
void FT6206::writeRegister8(uint8_t reg, uint8_t val) {
// use i2c
Wire.beginTransmission(FT62XX_ADDR);
Wire.write((byte)reg);
Wire.write((byte)val);
Wire.endTransmission();
}
/*
// DONT DO THIS - REALLY - IT DOESNT WORK
void FT6206::autoCalibrate(void) {
writeRegister8(FT06_REG_MODE, FT6206_REG_FACTORYMODE);
delay(100);
//Serial.println("Calibrating...");
writeRegister8(FT6206_REG_CALIBRATE, 4);
delay(300);
for (uint8_t i = 0; i < 100; i++) {
uint8_t temp;
temp = readRegister8(FT6206_REG_MODE);
Serial.println(temp, HEX);
//return to normal mode, calibration finish
if (0x0 == ((temp & 0x70) >> 4))
break;
}
delay(200);
//Serial.println("Calibrated");
delay(300);
writeRegister8(FT6206_REG_MODE, FT6206_REG_FACTORYMODE);
delay(100);
writeRegister8(FT6206_REG_CALIBRATE, 5);
delay(300);
writeRegister8(FT6206_REG_MODE, FT6206_REG_WORKMODE);
delay(300);
}
*/
/****************/
/**************************************************************************/
/*!
@brief Instantiates a new FT6206 class with x, y and z set to 0 by default
*/
/**************************************************************************/
TS_Point::TS_Point(void) { x = y = z = 0; }
/**************************************************************************/
/*!
@brief Instantiates a new FT6206 class with x, y and z set by params.
@param _x The X coordinate
@param _y The Y coordinate
@param _z The Z coordinate
*/
/**************************************************************************/
TS_Point::TS_Point(int16_t _x, int16_t _y, int16_t _z) {
x = _x;
y = _y;
z = _z;
}
/**************************************************************************/
/*!
@brief Simple == comparator for two TS_Point objects
@returns True if x, y and z are the same for both points, False otherwise.
*/
/**************************************************************************/
bool TS_Point::operator==(TS_Point p1) {
return ((p1.x == x) && (p1.y == y) && (p1.z == z));
}
/**************************************************************************/
/*!
@brief Simple != comparator for two TS_Point objects
@returns False if x, y and z are the same for both points, True otherwise.
*/
/**************************************************************************/
bool TS_Point::operator!=(TS_Point p1) {
return ((p1.x != x) || (p1.y != y) || (p1.z != z));
}

View File

@@ -0,0 +1,74 @@
#pragma once
#include "Arduino.h"
#include <Wire.h>
#define FT62XX_ADDR 0x38 //!< I2C address
#define FT62XX_G_FT5201ID 0xA8 //!< FocalTech's panel ID
#define FT62XX_REG_NUMTOUCHES 0x02 //!< Number of touch points
#define FT62XX_NUM_X 0x33 //!< Touch X position
#define FT62XX_NUM_Y 0x34 //!< Touch Y position
#define FT62XX_REG_MODE 0x00 //!< Device mode, either WORKING or FACTORY
#define FT62XX_REG_CALIBRATE 0x02 //!< Calibrate mode
#define FT62XX_REG_WORKMODE 0x00 //!< Work mode
#define FT62XX_REG_FACTORYMODE 0x40 //!< Factory mode
#define FT62XX_REG_THRESHHOLD 0x80 //!< Threshold for touch detection
#define FT62XX_REG_POINTRATE 0x88 //!< Point rate
#define FT62XX_REG_FIRMVERS 0xA6 //!< Firmware version
#define FT62XX_REG_CHIPID 0xA3 //!< Chip selecting
#define FT62XX_REG_VENDID 0xA8 //!< FocalTech's panel ID
#define FT62XX_VENDID 0x11 //!< FocalTech's panel ID
#define FT6206_CHIPID 0x06 //!< Chip selecting
#define FT6236_CHIPID 0x36 //!< Chip selecting
#define FT6236U_CHIPID 0x64 //!< Chip selecting
// calibrated for Adafruit 2.8" ctp screen
#define FT62XX_DEFAULT_THRESHOLD 128 //!< Default threshold for touch detection
/**************************************************************************/
/*!
@brief Helper class that stores a TouchScreen Point with x, y, and z
coordinates, for easy math/comparison
*/
/**************************************************************************/
class TS_Point {
public:
TS_Point(void);
TS_Point(int16_t x, int16_t y, int16_t z);
bool operator==(TS_Point);
bool operator!=(TS_Point);
int16_t x; /*!< X coordinate */
int16_t y; /*!< Y coordinate */
int16_t z; /*!< Z coordinate (often used for pressure) */
};
/**************************************************************************/
/*!
@brief Class that stores state and functions for interacting with FT6206
capacitive touch chips
*/
/**************************************************************************/
class FT6206 {
public:
FT6206(void);
bool begin(uint8_t sda, uint8_t scl, uint16_t width, uint16_t height, bool flip = false, uint8_t thresh = FT62XX_DEFAULT_THRESHOLD);
uint8_t touched(void);
TS_Point getPoint(uint8_t n = 0);
// void autoCalibrate(void);
private:
uint16_t _width, _height;
bool _flip;
void writeRegister8(uint8_t reg, uint8_t val);
uint8_t readRegister8(uint8_t reg);
void readData(void);
uint8_t touches;
uint16_t touchX[2], touchY[2], touchID[2];
};

View File

@@ -15,11 +15,12 @@ framework = arduino
upload_protocol = stlink
debug_tool = stlink
monitor_speed = 115200
monitor_port = /dev/cu.usbmodem3474359635391
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
;adafruit/Adafruit FT6206 Library@^1.0.6
lib_ldf_mode = deep+
build_flags =
-D USER_SETUP_LOADED=1

View File

@@ -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

View File

@@ -215,7 +215,7 @@ String getReflowState_str(void)
return String("Completed");
break;
case REFLOW_STATE_TOO_HOT:
return String("OVERHEATING!");
return String("HOT!");
break;
case REFLOW_STATE_ERROR:
return String("Error");
@@ -582,7 +582,7 @@ void handleControlLoop()
Serial.println("handlecontrolloop: ERROR state");
return;
}
getSafetyCheck();
//getSafetyCheck();
handleTemperatureReadings();
handleReflowStatemachine();
handleReflowPID();

View File

@@ -3,37 +3,35 @@
#include "Arduino.h"
// ***** CONSTANTS *****
#define TEMPERATURE_ROOM 50
#define TEMPERATURE_ROOM 75
#define SENSOR_SAMPLING_TIME 1000
#define DEBOUNCE_PERIOD_MIN 50
// ***** PARAMETERS *****
// ***** PRE-HEAT STAGE *****
#define PID_KP_PREHEAT 100
#define PID_KI_PREHEAT 0.025
#define PID_KD_PREHEAT 20
#define PREHEAT_PERIOD 20000
// ***** SOAKING STAGE *****
#define PID_KP_SOAK 300
#define PID_KI_SOAK 0.05
#define PID_KD_SOAK 250
#define TEMPERATURE_SOAK_MIN 150
#define TEMPERATURE_SOAK_MAX 185
#define TEMPERATURE_REFLOW_MAX 220
#define TEMPERATURE_COOL_MIN 100
#define SENSOR_SAMPLING_TIME 1000
#define SOAK_TEMPERATURE_STEP 5
#define SOAK_MICRO_PERIOD 9000
#define DEBOUNCE_PERIOD_MIN 50
#define PREHEAT_PERIOD 12000
#define REFLOW_PERIOD 12000
#define COOLDOWN_PERIOD 30000
// ***** PID PARAMETERS *****
// ***** PRE-HEAT STAGE *****
#define PID_KP_PREHEAT 100
#define PID_KI_PREHEAT 0.025
#define PID_KD_PREHEAT 20
// ***** SOAKING STAGE *****
#define PID_KP_SOAK 300
#define PID_KI_SOAK 0.05
#define PID_KD_SOAK 250
// ***** REFLOW STAGE *****
#define PID_KP_REFLOW 300
#define PID_KI_REFLOW 0.05
#define PID_KD_REFLOW 350
#define PID_SAMPLE_TIME 1000
// This is for testing on different board
// #define LCD_PIN 14
// #define ODROID
#define PID_KP_REFLOW 300
#define PID_KI_REFLOW 0.05
#define PID_KD_REFLOW 350
#define TEMPERATURE_REFLOW_MAX 220
#define REFLOW_PERIOD 30000
// ***** COOLING STAGE *****
#define COOLDOWN_PERIOD 180000
#define TEMPERATURE_COOL_MIN 100
//PID settings
#define PID_SAMPLE_TIME 1000
// ***** TYPE DEFINITIONS *****
typedef enum REFLOW_STATE

View File

@@ -6,6 +6,9 @@
#include <vector>
#include <TFT_eSPI.h> // Include the graphics library
#include "ft6206_touch.h"
FT6206 ts = FT6206();
TFT_eSPI tft = TFT_eSPI(); // Create object "tft"
TFT_eSprite looptime_spr = TFT_eSprite(&tft);
@@ -59,13 +62,13 @@ uint32_t calcTime(uint32_t timeMs)
return map((timeMs / 1000), 0, CHART_TIME_MAX, 0, CHART_W - CHART_Y_AXIS_OFFSET);
}
std::vector<double> temperatureReading;
std::vector<float> temperatureReading;
uint32_t lastReading = 0;
#define TEMPINTERVAL 1000
void updateRealtimeGraph(void)
{
if(getReflowStatus() == REFLOW_STATUS_OFF)
if (getReflowStatus() == REFLOW_STATUS_OFF)
{
temperatureReading.clear();
return;
@@ -86,10 +89,10 @@ void updateRealtimeGraph(void)
{
uint32_t nowX = calcTime(timeIndex * TEMPINTERVAL);
uint32_t nowY = calcTemp(sample);
chartArea_spr.drawLine(lastX,lastY, nowX, nowY, CHART_ACTUAL_COLOR);
chartArea_spr.drawLine(lastX, lastY, nowX, nowY, CHART_ACTUAL_COLOR);
lastX = nowX;
lastY = nowY;
timeIndex ++;
timeIndex++;
}
}
@@ -151,7 +154,7 @@ void prepTargetChart(void)
void updateReflowState(void)
{
uint32_t statusColor = STATE_BG_COLOR;
if(getOverheating())
if (getOverheating())
{
statusColor = TFT_RED;
}
@@ -208,7 +211,7 @@ void prepChart(void)
for (int i = 0; i < CHART_Y_TICKS; i++)
{
//tick value
uint16_t y_tick_step = calcTempY( tickIndex * (i +1));//CHART_TEMP_MAX - ((CHART_TEMP_MAX - CHART_TEMP_MIN) / CHART_Y_TICKS * i + 1) + CHART_TEMP_MIN;
uint16_t y_tick_step = calcTempY(tickIndex * (i + 1)); //CHART_TEMP_MAX - ((CHART_TEMP_MAX - CHART_TEMP_MIN) / CHART_Y_TICKS * i + 1) + CHART_TEMP_MIN;
chartYaxis_spr.drawLine(CHART_Y_AXIS_OFFSET - 8, tickIndex * (i + 1), CHART_Y_AXIS_OFFSET, tickIndex * (i + 1), CHART_LINE_COLOR);
chartYaxis_spr.setTextDatum(BR_DATUM);
chartYaxis_spr.drawString(String(y_tick_step), CHART_Y_AXIS_OFFSET - 3, tickIndex * (i + 1), CHART_FONT);
@@ -265,6 +268,7 @@ void prepButtons(void)
}
}
#if defined(TOUCH_CS)
void touch_calibrate()
{
uint16_t calData[5];
@@ -297,14 +301,21 @@ void touch_calibrate()
while (1)
;
}
#endif
void updateGUIButtons(void)
{
uint32_t timeNow = millis();
if (timeNow - lastButtonTime > BUTTON_INTERVAL)
{
uint16_t t_x = 0, t_y = 0; // To store the touch coordinates
bool pressed = tft.getTouch(&t_x, &t_y);
uint16_t t_x = 0, t_y = 0; // To store the touch coordinates
bool pressed = ts.touched(); //.getTouch(&t_x, &t_y);
if (pressed)
{
TS_Point p = ts.getPoint();
t_x = p.x;
t_y = p.y;
}
for (uint8_t b = 0; b < BUTTONS_N; b++)
{
@@ -344,15 +355,33 @@ void updateGUIButtons(void)
// -------------------------------------------------------------------------
// Setup
// -------------------------------------------------------------------------
void initTouchScreen(void)
{
//ts.begin();
if (!ts.begin(TOUCH_SDA, TOUCH_SCL, tft.width(), tft.height(), true, 40))
{
Serial.println("Unable to start touchscreen.");
}
else
{
Serial.println("Touchscreen started.");
}
}
void initLCD(void)
{
tft.init();
tft.setRotation(2);
tft.setRotation(TFT_ROTATION);
tft.setTextFont(2);
tft.fillScreen(TFT_BLACK);
tft.invertDisplay(false);
#if defined(TOUCH_CS)
//touch_calibrate();
tft.setTouch(calData);
#endif
initTouchScreen();
prepStatus();
prepButtons();
@@ -366,12 +395,12 @@ void initLCD(void)
// Main loop
// -------------------------------------------------------------------------
uint32_t lastLCDupdate = 0;
void handleLCD()
{
updateStatus();
uint32_t timeNow = millis();
if (timeNow - lastLCDupdate > LCD_INTERVAL)
{

View File

@@ -6,6 +6,7 @@
#define TFT_WIDTH 240
#define TFT_HEIGT 320
#define TFT_DEFAULT_R 4
#define TFT_ROTATION 0 //2 = upsidedown
#define LCD_INTERVAL 100
@@ -27,10 +28,10 @@
#define CHART_H 200
#define CHART_FONT 1
#define CHART_TIME_MAX 140 //time scale in seconds
#define CHART_TIME_MAX 500 //time scale in seconds
#define CHART_TEMP_MIN 20 //offset in degrees
#define CHART_TEMP_MAX 240 //degrees
#define CHART_Y_TICKS 10
#define CHART_Y_TICKS 10
#define CHART_X_TICKS 7
#define CHART_LINE_COLOR TFT_WHITE
#define CHART_TEXT_COLOR TFT_RED
@@ -38,7 +39,6 @@
#define CHART_ACTUAL_COLOR TFT_RED
#define CHART_BG_COLOR TFT_BLACK
#define STATE_X 0
#define STATE_Y 13
#define STATE_W TFT_WIDTH

View File

@@ -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();
}

View File

@@ -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);