Working on rewriting how we acquire data from LTC chip and sending all temp data over serial for python logging
Fork of TCTF_Control_Main by
main.cpp@15:74a01aaeb60e, 2018-06-11 (annotated)
- Committer:
- jrodenburg
- Date:
- Mon Jun 11 21:10:14 2018 +0000
- Revision:
- 15:74a01aaeb60e
- Parent:
- 14:69cd53434783
- Child:
- 16:a7fd53ab4199
Reduced the number of print statements in an attempt to limit the amount of data on the serial lines (used to help with the connection serial reliability)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jrodenburg | 4:168a446bd0da | 1 | // MBED SCRIPT FOR CONTROLLING THE TEMPERATURE CONTROLLED TEST FIXTURE (TCTF) |
jrodenburg | 0:a28a1035c31b | 2 | // DATE: SEPTEMBER 2017 |
jrodenburg | 0:a28a1035c31b | 3 | |
jrodenburg | 15:74a01aaeb60e | 4 | #define FW_VERSION "V.010" |
jrodenburg | 0:a28a1035c31b | 5 | #include "mbed.h" |
jrodenburg | 0:a28a1035c31b | 6 | #include "MODSERIAL.h" |
jrodenburg | 8:dbf8bd4815f8 | 7 | #include "MCP23008.h" |
jrodenburg | 0:a28a1035c31b | 8 | #include "LTC2487.h" |
jrodenburg | 2:bd118a724f03 | 9 | #include <string> |
jrodenburg | 0:a28a1035c31b | 10 | |
jrodenburg | 0:a28a1035c31b | 11 | //DEFINITIVE VARIABLES |
jrodenburg | 15:74a01aaeb60e | 12 | #define DEBUG 0 |
jrodenburg | 15:74a01aaeb60e | 13 | #define DEBUG1 0 |
jrodenburg | 15:74a01aaeb60e | 14 | #define DEBUG2 0 |
jrodenburg | 15:74a01aaeb60e | 15 | #define DEBUG3 1 |
jrodenburg | 15:74a01aaeb60e | 16 | #define DEBUG5 0 |
jrodenburg | 15:74a01aaeb60e | 17 | #define CHN_COUNT 8 |
jrodenburg | 15:74a01aaeb60e | 18 | #define MIN_TEMP 10 |
jrodenburg | 15:74a01aaeb60e | 19 | #define MAX_TEMP 65 |
jrodenburg | 15:74a01aaeb60e | 20 | #define TEMP_MARGIN 20 |
jrodenburg | 15:74a01aaeb60e | 21 | #define HYST_LOW 0.3 |
jrodenburg | 15:74a01aaeb60e | 22 | #define HYST_HIGH 1 |
jrodenburg | 15:74a01aaeb60e | 23 | #define SAMPLES 5 |
jrodenburg | 15:74a01aaeb60e | 24 | #define I2C_Freq 2000 |
jrodenburg | 15:74a01aaeb60e | 25 | #define VALVE 1 |
jrodenburg | 15:74a01aaeb60e | 26 | #define HEATER 2 |
jrodenburg | 15:74a01aaeb60e | 27 | #define STATUS_GOOD 3 |
jrodenburg | 15:74a01aaeb60e | 28 | #define STATUS_BAD 0 |
jrodenburg | 15:74a01aaeb60e | 29 | #define sizeLUT 34 |
jrodenburg | 15:74a01aaeb60e | 30 | #define BACK_THERM 0 |
jrodenburg | 15:74a01aaeb60e | 31 | #define FRONT_THERM 1 |
jrodenburg | 15:74a01aaeb60e | 32 | #define HEAT_FET_AMP 2 |
jrodenburg | 15:74a01aaeb60e | 33 | #define VALVE_FET_AMP 3 |
jrodenburg | 15:74a01aaeb60e | 34 | #define FET_ON_CURRENT 1.12 |
jrodenburg | 15:74a01aaeb60e | 35 | #define ROOM_TEMP 22 |
jrodenburg | 14:69cd53434783 | 36 | #define MAX_HEATER_ON_TIME 25 |
jrodenburg | 14:69cd53434783 | 37 | #define MAX_CHILL_TIME 10 //10sec |
jrodenburg | 9:1cada1fe4743 | 38 | |
jrodenburg | 8:dbf8bd4815f8 | 39 | // Defines for use with Serial communication |
jrodenburg | 8:dbf8bd4815f8 | 40 | #pragma pack (1) |
jrodenburg | 8:dbf8bd4815f8 | 41 | #define RX_SOF 0x7B |
jrodenburg | 8:dbf8bd4815f8 | 42 | #define RX_EOF 0x7D |
jrodenburg | 8:dbf8bd4815f8 | 43 | #define TX_SOF 0x7B |
jrodenburg | 8:dbf8bd4815f8 | 44 | #define TX_EOF 0x7D |
jrodenburg | 8:dbf8bd4815f8 | 45 | #define DELIMETER 0x2E |
jrodenburg | 8:dbf8bd4815f8 | 46 | #define SET_TEMPERATURE 0xB0 |
jrodenburg | 8:dbf8bd4815f8 | 47 | #define SELECT_CHANNEL 0xB1 |
jrodenburg | 15:74a01aaeb60e | 48 | #define READ_UID 0xB2 |
jrodenburg | 15:74a01aaeb60e | 49 | #define RESPONSE_DATA 0xD0 |
jrodenburg | 15:74a01aaeb60e | 50 | #define TEMP_DATA 0xD1 |
jrodenburg | 15:74a01aaeb60e | 51 | #define UID_DATA 0xD2 |
jrodenburg | 15:74a01aaeb60e | 52 | #define ERROR_DATA 0xDF |
jrodenburg | 9:1cada1fe4743 | 53 | |
jrodenburg | 0:a28a1035c31b | 54 | |
jrodenburg | 8:dbf8bd4815f8 | 55 | unsigned int chanSel_SendTemp = 0; |
jrodenburg | 8:dbf8bd4815f8 | 56 | unsigned int chanSel_SetTemp = 0; |
jrodenburg | 8:dbf8bd4815f8 | 57 | // Default to chan 0 |
jrodenburg | 8:dbf8bd4815f8 | 58 | int currChan = 0; |
jrodenburg | 8:dbf8bd4815f8 | 59 | bool newTempSet = false; |
jrodenburg | 8:dbf8bd4815f8 | 60 | |
jrodenburg | 9:1cada1fe4743 | 61 | |
jrodenburg | 8:dbf8bd4815f8 | 62 | //*********************************************** |
jrodenburg | 8:dbf8bd4815f8 | 63 | // Serial Rx Packet Format |
jrodenburg | 8:dbf8bd4815f8 | 64 | //*********************************************** |
jrodenburg | 8:dbf8bd4815f8 | 65 | typedef struct { |
jrodenburg | 8:dbf8bd4815f8 | 66 | unsigned char SOF_flag; |
jrodenburg | 8:dbf8bd4815f8 | 67 | unsigned char cmd_type; |
jrodenburg | 8:dbf8bd4815f8 | 68 | unsigned char len; |
jrodenburg | 8:dbf8bd4815f8 | 69 | unsigned char Delim; |
jrodenburg | 8:dbf8bd4815f8 | 70 | } HOST_CMD_HEADER; |
jrodenburg | 8:dbf8bd4815f8 | 71 | |
jrodenburg | 8:dbf8bd4815f8 | 72 | typedef struct { |
jrodenburg | 8:dbf8bd4815f8 | 73 | HOST_CMD_HEADER cmd_header; |
jrodenburg | 8:dbf8bd4815f8 | 74 | unsigned char chanID; |
jrodenburg | 8:dbf8bd4815f8 | 75 | unsigned char tempDelim; |
jrodenburg | 8:dbf8bd4815f8 | 76 | float setTemp; |
jrodenburg | 8:dbf8bd4815f8 | 77 | unsigned char chanStatDelim; |
jrodenburg | 8:dbf8bd4815f8 | 78 | unsigned char chanStat; |
jrodenburg | 8:dbf8bd4815f8 | 79 | } SET_TEMPERATURE_CMD; |
jrodenburg | 8:dbf8bd4815f8 | 80 | |
jrodenburg | 8:dbf8bd4815f8 | 81 | typedef struct { |
jrodenburg | 8:dbf8bd4815f8 | 82 | HOST_CMD_HEADER cmd_header; |
jrodenburg | 8:dbf8bd4815f8 | 83 | unsigned char chanIDSel; |
jrodenburg | 8:dbf8bd4815f8 | 84 | unsigned char chanDelim; |
jrodenburg | 8:dbf8bd4815f8 | 85 | unsigned char chanStat; |
jrodenburg | 8:dbf8bd4815f8 | 86 | } SELECT_CHANNEL_CMD; |
jrodenburg | 8:dbf8bd4815f8 | 87 | |
jrodenburg | 8:dbf8bd4815f8 | 88 | typedef struct { |
jrodenburg | 8:dbf8bd4815f8 | 89 | unsigned char SOF_flag; |
jrodenburg | 8:dbf8bd4815f8 | 90 | unsigned char cmd_type; |
jrodenburg | 8:dbf8bd4815f8 | 91 | unsigned char len; |
jrodenburg | 8:dbf8bd4815f8 | 92 | unsigned char Delim; |
jrodenburg | 8:dbf8bd4815f8 | 93 | float data; |
jrodenburg | 8:dbf8bd4815f8 | 94 | unsigned char EOF_flag; |
jrodenburg | 8:dbf8bd4815f8 | 95 | } RESPONSE_CMD; |
jrodenburg | 2:bd118a724f03 | 96 | |
jrodenburg | 15:74a01aaeb60e | 97 | typedef struct { |
jrodenburg | 15:74a01aaeb60e | 98 | HOST_CMD_HEADER cmd_header; |
jrodenburg | 15:74a01aaeb60e | 99 | unsigned char chanIDSel; |
jrodenburg | 15:74a01aaeb60e | 100 | unsigned char chanDelim; |
jrodenburg | 15:74a01aaeb60e | 101 | unsigned char chanStat; |
jrodenburg | 15:74a01aaeb60e | 102 | } READ_UID_CMD; |
jrodenburg | 15:74a01aaeb60e | 103 | |
jrodenburg | 15:74a01aaeb60e | 104 | typedef struct { |
jrodenburg | 15:74a01aaeb60e | 105 | unsigned char SOF_flag; |
jrodenburg | 15:74a01aaeb60e | 106 | unsigned char cmd_type; |
jrodenburg | 15:74a01aaeb60e | 107 | unsigned char len; |
jrodenburg | 15:74a01aaeb60e | 108 | unsigned char Delim; |
jrodenburg | 15:74a01aaeb60e | 109 | uint32_t UIDMH; |
jrodenburg | 15:74a01aaeb60e | 110 | uint32_t UIDML; |
jrodenburg | 15:74a01aaeb60e | 111 | uint32_t UIDL; |
jrodenburg | 15:74a01aaeb60e | 112 | unsigned char EOF_flag; |
jrodenburg | 15:74a01aaeb60e | 113 | } UID_RESPONSE; |
jrodenburg | 15:74a01aaeb60e | 114 | |
jrodenburg | 2:bd118a724f03 | 115 | //TCTF CHANNEL DATA |
jrodenburg | 2:bd118a724f03 | 116 | struct CHNL_DATA{ |
jrodenburg | 2:bd118a724f03 | 117 | bool status; |
jrodenburg | 2:bd118a724f03 | 118 | float setTemp; |
jrodenburg | 7:8a5e65e63e2a | 119 | bool error; |
jrodenburg | 14:69cd53434783 | 120 | int heater_init_time; |
jrodenburg | 2:bd118a724f03 | 121 | }; |
jrodenburg | 2:bd118a724f03 | 122 | |
jrodenburg | 4:168a446bd0da | 123 | CHNL_DATA chnlStatus[] = { |
jrodenburg | 14:69cd53434783 | 124 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 125 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 126 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 127 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 128 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 129 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 130 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 131 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 132 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 133 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 134 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 135 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 136 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 137 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 138 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 139 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 140 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 141 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 142 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 143 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 144 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 145 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 146 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 147 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 148 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 149 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 150 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 151 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 152 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 153 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 154 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 155 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 156 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 157 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 158 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 159 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 160 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 161 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 162 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 163 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 164 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 165 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 166 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 167 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 168 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 169 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 170 | {0, NULL, 0, 0}, |
jrodenburg | 14:69cd53434783 | 171 | {0, NULL, 0, 0}, |
jrodenburg | 2:bd118a724f03 | 172 | }; |
jrodenburg | 2:bd118a724f03 | 173 | |
jrodenburg | 2:bd118a724f03 | 174 | |
jrodenburg | 0:a28a1035c31b | 175 | //I2C AADRESS LOOK UP TABLE, CREATED IN EXCEL SHEET (COUNT, TEMP) |
jrodenburg | 2:bd118a724f03 | 176 | struct I2C_ADDR_LUT{ |
jrodenburg | 0:a28a1035c31b | 177 | int adc; |
jrodenburg | 0:a28a1035c31b | 178 | int io; |
jrodenburg | 0:a28a1035c31b | 179 | }; |
jrodenburg | 0:a28a1035c31b | 180 | |
jrodenburg | 0:a28a1035c31b | 181 | I2C_ADDR_LUT addrLUT[] = { |
jrodenburg | 0:a28a1035c31b | 182 | {0x23, 0x10}, |
jrodenburg | 0:a28a1035c31b | 183 | {0x53, 0x60}, |
jrodenburg | 0:a28a1035c31b | 184 | {0x43, 0x70}, |
jrodenburg | 0:a28a1035c31b | 185 | {0x73, 0x40}, |
jrodenburg | 0:a28a1035c31b | 186 | {0x63, 0x50}, |
jrodenburg | 0:a28a1035c31b | 187 | {0x22, 0x11}, |
jrodenburg | 0:a28a1035c31b | 188 | {0x52, 0x61}, |
jrodenburg | 0:a28a1035c31b | 189 | {0x42, 0x71}, |
jrodenburg | 0:a28a1035c31b | 190 | {0x72, 0x41}, |
jrodenburg | 0:a28a1035c31b | 191 | {0x62, 0x51}, |
jrodenburg | 0:a28a1035c31b | 192 | {0x21, 0x12}, |
jrodenburg | 0:a28a1035c31b | 193 | {0x51, 0x62}, |
jrodenburg | 0:a28a1035c31b | 194 | {0x41, 0x72}, |
jrodenburg | 0:a28a1035c31b | 195 | {0x71, 0x42}, |
jrodenburg | 0:a28a1035c31b | 196 | {0x61, 0x52}, |
jrodenburg | 0:a28a1035c31b | 197 | {0x20, 0x13}, |
jrodenburg | 0:a28a1035c31b | 198 | {0x50, 0x63}, |
jrodenburg | 0:a28a1035c31b | 199 | {0x40, 0x73}, |
jrodenburg | 0:a28a1035c31b | 200 | {0x70, 0x43}, |
jrodenburg | 0:a28a1035c31b | 201 | {0x60, 0x53}, |
jrodenburg | 0:a28a1035c31b | 202 | {0x26, 0x14}, |
jrodenburg | 0:a28a1035c31b | 203 | {0x56, 0x64}, |
jrodenburg | 0:a28a1035c31b | 204 | {0x46, 0x74}, |
jrodenburg | 0:a28a1035c31b | 205 | {0x76, 0x44}, |
jrodenburg | 0:a28a1035c31b | 206 | {0x66, 0x54}, |
jrodenburg | 0:a28a1035c31b | 207 | {0x2C, 0x1F}, |
jrodenburg | 0:a28a1035c31b | 208 | {0x5C, 0x6F}, |
jrodenburg | 0:a28a1035c31b | 209 | {0x4C, 0x7F}, |
jrodenburg | 0:a28a1035c31b | 210 | {0x7C, 0x4F}, |
jrodenburg | 0:a28a1035c31b | 211 | {0x6C, 0x5F}, |
jrodenburg | 0:a28a1035c31b | 212 | {0x2D, 0x1E}, |
jrodenburg | 0:a28a1035c31b | 213 | {0x5D, 0x6E}, |
jrodenburg | 0:a28a1035c31b | 214 | {0x4D, 0x7E}, |
jrodenburg | 0:a28a1035c31b | 215 | {0x7D, 0x4E}, |
jrodenburg | 0:a28a1035c31b | 216 | {0x6D, 0x5E}, |
jrodenburg | 0:a28a1035c31b | 217 | {0x2E, 0x1D}, |
jrodenburg | 0:a28a1035c31b | 218 | {0x5E, 0x6D}, |
jrodenburg | 0:a28a1035c31b | 219 | {0x4E, 0x7D}, |
jrodenburg | 0:a28a1035c31b | 220 | {0x7E, 0x4D}, |
jrodenburg | 0:a28a1035c31b | 221 | {0x6E, 0x5D}, |
jrodenburg | 0:a28a1035c31b | 222 | {0x2F, 0x1C}, |
jrodenburg | 0:a28a1035c31b | 223 | {0x5F, 0x6C}, |
jrodenburg | 0:a28a1035c31b | 224 | {0x4F, 0x7C}, |
jrodenburg | 0:a28a1035c31b | 225 | {0x7F, 0x4C}, |
jrodenburg | 0:a28a1035c31b | 226 | {0x6F, 0x5C}, |
jrodenburg | 0:a28a1035c31b | 227 | {0x20, 0x1B}, |
jrodenburg | 0:a28a1035c31b | 228 | {0x50, 0x6B}, |
jrodenburg | 9:1cada1fe4743 | 229 | {0x40, 0x7B}, |
jrodenburg | 0:a28a1035c31b | 230 | }; |
jrodenburg | 0:a28a1035c31b | 231 | |
jrodenburg | 0:a28a1035c31b | 232 | //THERMISTOR LOOK UP TABLE, CREATED IN EXCEL SHEET (COUNT, TEMP) |
jrodenburg | 2:bd118a724f03 | 233 | struct THERM_LUT{ |
jrodenburg | 0:a28a1035c31b | 234 | int adc; |
jrodenburg | 0:a28a1035c31b | 235 | int temp; |
jrodenburg | 0:a28a1035c31b | 236 | }; |
jrodenburg | 0:a28a1035c31b | 237 | |
jrodenburg | 0:a28a1035c31b | 238 | THERM_LUT thermLUT[] = { |
jrodenburg | 0:a28a1035c31b | 239 | {113779,-40}, |
jrodenburg | 0:a28a1035c31b | 240 | {109152,-35}, |
jrodenburg | 0:a28a1035c31b | 241 | {103830,-30}, |
jrodenburg | 0:a28a1035c31b | 242 | {97855,-25}, |
jrodenburg | 0:a28a1035c31b | 243 | {91319,-20}, |
jrodenburg | 0:a28a1035c31b | 244 | {84352,-15}, |
jrodenburg | 0:a28a1035c31b | 245 | {77124,-10}, |
jrodenburg | 0:a28a1035c31b | 246 | {69820,-5}, |
jrodenburg | 0:a28a1035c31b | 247 | {62621,0}, |
jrodenburg | 0:a28a1035c31b | 248 | {55693,5}, |
jrodenburg | 0:a28a1035c31b | 249 | {49169,10}, |
jrodenburg | 0:a28a1035c31b | 250 | {43144,15}, |
jrodenburg | 0:a28a1035c31b | 251 | {37669,20}, |
jrodenburg | 0:a28a1035c31b | 252 | {32768,25}, |
jrodenburg | 0:a28a1035c31b | 253 | {28429,30}, |
jrodenburg | 0:a28a1035c31b | 254 | {24622,35}, |
jrodenburg | 0:a28a1035c31b | 255 | {21309,40}, |
jrodenburg | 0:a28a1035c31b | 256 | {18439,45}, |
jrodenburg | 0:a28a1035c31b | 257 | {15962,50}, |
jrodenburg | 0:a28a1035c31b | 258 | {13831,55}, |
jrodenburg | 0:a28a1035c31b | 259 | {12002,60}, |
jrodenburg | 0:a28a1035c31b | 260 | {10428,65}, |
jrodenburg | 0:a28a1035c31b | 261 | {9080,70}, |
jrodenburg | 0:a28a1035c31b | 262 | {7919,75}, |
jrodenburg | 0:a28a1035c31b | 263 | {6923,80}, |
jrodenburg | 0:a28a1035c31b | 264 | {6063,85}, |
jrodenburg | 0:a28a1035c31b | 265 | {5323,90}, |
jrodenburg | 0:a28a1035c31b | 266 | {4685,95}, |
jrodenburg | 0:a28a1035c31b | 267 | {4130,100}, |
jrodenburg | 0:a28a1035c31b | 268 | {3653,105}, |
jrodenburg | 0:a28a1035c31b | 269 | {3234,110}, |
jrodenburg | 0:a28a1035c31b | 270 | {2876,115}, |
jrodenburg | 0:a28a1035c31b | 271 | {2563,120}, |
jrodenburg | 0:a28a1035c31b | 272 | {2284,125} |
jrodenburg | 0:a28a1035c31b | 273 | }; |
jrodenburg | 0:a28a1035c31b | 274 | |
jrodenburg | 2:bd118a724f03 | 275 | //SERIAL COMMUNICATION SETUP |
jrodenburg | 2:bd118a724f03 | 276 | MODSERIAL pc(USBTX, USBRX); |
jrodenburg | 1:0182b86f9bd4 | 277 | |
jrodenburg | 0:a28a1035c31b | 278 | //DEFINE PINS |
jrodenburg | 0:a28a1035c31b | 279 | DigitalOut myled(LED2); |
jrodenburg | 0:a28a1035c31b | 280 | |
jrodenburg | 0:a28a1035c31b | 281 | //I2C FOR MCP23008 (I/O Control) |
jrodenburg | 9:1cada1fe4743 | 282 | MCP23008 io_control(PTC9, PTC8, 0x10, 100000); //sda, scl |
jrodenburg | 0:a28a1035c31b | 283 | |
jrodenburg | 0:a28a1035c31b | 284 | //I2C FOR LTC2487 (ADC Control) |
jrodenburg | 9:1cada1fe4743 | 285 | LTC2487 ltc2487(PTC11, PTC10, 0x23, 100000); //sda, scl |
jrodenburg | 0:a28a1035c31b | 286 | |
jrodenburg | 0:a28a1035c31b | 287 | //GLOBAL VARIABLES |
jrodenburg | 9:1cada1fe4743 | 288 | volatile bool dataReceived = false; //used to check if data has been received |
jrodenburg | 8:dbf8bd4815f8 | 289 | volatile bool dataTxReady = false; |
jrodenburg | 2:bd118a724f03 | 290 | char rxBuf[50]; |
jrodenburg | 2:bd118a724f03 | 291 | int chnlSel; |
jrodenburg | 0:a28a1035c31b | 292 | |
jrodenburg | 7:8a5e65e63e2a | 293 | |
jrodenburg | 7:8a5e65e63e2a | 294 | /* Function: turnOffChannel |
jrodenburg | 7:8a5e65e63e2a | 295 | ************************************************************** |
jrodenburg | 7:8a5e65e63e2a | 296 | Description: Turns off a channel |
jrodenburg | 7:8a5e65e63e2a | 297 | Recieves: chnl: channel to turn off |
jrodenburg | 7:8a5e65e63e2a | 298 | Returns: N/A |
jrodenburg | 7:8a5e65e63e2a | 299 | */ |
jrodenburg | 7:8a5e65e63e2a | 300 | |
jrodenburg | 7:8a5e65e63e2a | 301 | void turnOffChannel(int chnl){ |
jrodenburg | 7:8a5e65e63e2a | 302 | io_control.setAddress(addrLUT[chnl].io); |
jrodenburg | 7:8a5e65e63e2a | 303 | io_control.init(); |
jrodenburg | 7:8a5e65e63e2a | 304 | io_control.writeOutput(0,0,0,0); |
jrodenburg | 7:8a5e65e63e2a | 305 | } |
jrodenburg | 7:8a5e65e63e2a | 306 | |
jrodenburg | 8:dbf8bd4815f8 | 307 | |
jrodenburg | 2:bd118a724f03 | 308 | /* Function: rxInterrupt |
jrodenburg | 1:0182b86f9bd4 | 309 | ************************************************************** |
jrodenburg | 8:dbf8bd4815f8 | 310 | Description: serial rx interupt handler |
jrodenburg | 8:dbf8bd4815f8 | 311 | Receives: N/A |
jrodenburg | 8:dbf8bd4815f8 | 312 | Returns: N/A |
jrodenburg | 2:bd118a724f03 | 313 | */ |
jrodenburg | 2:bd118a724f03 | 314 | |
jrodenburg | 8:dbf8bd4815f8 | 315 | DigitalOut rLed(LED1); |
jrodenburg | 8:dbf8bd4815f8 | 316 | DigitalOut gLed(LED2); |
jrodenburg | 8:dbf8bd4815f8 | 317 | |
jrodenburg | 15:74a01aaeb60e | 318 | void sendUID (); |
jrodenburg | 15:74a01aaeb60e | 319 | |
jrodenburg | 8:dbf8bd4815f8 | 320 | //*********************************************** |
jrodenburg | 8:dbf8bd4815f8 | 321 | // Rx Interrupt from serial Host interface |
jrodenburg | 8:dbf8bd4815f8 | 322 | //*********************************************** |
jrodenburg | 8:dbf8bd4815f8 | 323 | void rxInterrupt(MODSERIAL_IRQ_INFO *info) |
jrodenburg | 8:dbf8bd4815f8 | 324 | { |
jrodenburg | 8:dbf8bd4815f8 | 325 | gLed = 0; |
jrodenburg | 8:dbf8bd4815f8 | 326 | dataReceived = true; |
jrodenburg | 8:dbf8bd4815f8 | 327 | gLed = 1; |
jrodenburg | 2:bd118a724f03 | 328 | } |
jrodenburg | 2:bd118a724f03 | 329 | |
jrodenburg | 8:dbf8bd4815f8 | 330 | |
jrodenburg | 8:dbf8bd4815f8 | 331 | //*************************************************************** |
jrodenburg | 8:dbf8bd4815f8 | 332 | // Tx Interrupt from serial Host interface |
jrodenburg | 8:dbf8bd4815f8 | 333 | //*************************************************************** |
jrodenburg | 8:dbf8bd4815f8 | 334 | void txInterrupt(MODSERIAL_IRQ_INFO *info) |
jrodenburg | 8:dbf8bd4815f8 | 335 | { |
jrodenburg | 8:dbf8bd4815f8 | 336 | dataTxReady = true; |
jrodenburg | 8:dbf8bd4815f8 | 337 | } |
jrodenburg | 8:dbf8bd4815f8 | 338 | |
jrodenburg | 8:dbf8bd4815f8 | 339 | |
jrodenburg | 2:bd118a724f03 | 340 | /* Function: parseRXData |
jrodenburg | 2:bd118a724f03 | 341 | ************************************************************** |
jrodenburg | 9:1cada1fe4743 | 342 | Description: The parse received data into |
jrodenburg | 9:1cada1fe4743 | 343 | Receives: chn: The channel we want to put into the channel |
jrodenburg | 9:1cada1fe4743 | 344 | Returns: N/A |
jrodenburg | 1:0182b86f9bd4 | 345 | */ |
jrodenburg | 0:a28a1035c31b | 346 | |
jrodenburg | 8:dbf8bd4815f8 | 347 | void parseRXData() |
jrodenburg | 8:dbf8bd4815f8 | 348 | { |
jrodenburg | 8:dbf8bd4815f8 | 349 | HOST_CMD_HEADER *pRxPktHdr; |
jrodenburg | 2:bd118a724f03 | 350 | string data = ""; |
jrodenburg | 8:dbf8bd4815f8 | 351 | unsigned char *ptemp; |
jrodenburg | 8:dbf8bd4815f8 | 352 | int i; |
jrodenburg | 8:dbf8bd4815f8 | 353 | |
jrodenburg | 8:dbf8bd4815f8 | 354 | pRxPktHdr = (HOST_CMD_HEADER *)rxBuf; |
jrodenburg | 8:dbf8bd4815f8 | 355 | |
jrodenburg | 8:dbf8bd4815f8 | 356 | #ifdef DEBUG |
jrodenburg | 15:74a01aaeb60e | 357 | pc.printf("DBG: fl=%02x, len=%02x\n", pRxPktHdr->SOF_flag, pRxPktHdr->len); |
jrodenburg | 8:dbf8bd4815f8 | 358 | #endif |
jrodenburg | 8:dbf8bd4815f8 | 359 | |
jrodenburg | 8:dbf8bd4815f8 | 360 | // Exit if the packet does not contain correct header |
jrodenburg | 8:dbf8bd4815f8 | 361 | // Maybe send NAK? |
jrodenburg | 8:dbf8bd4815f8 | 362 | if ((pRxPktHdr->SOF_flag != RX_SOF) || (pRxPktHdr->Delim != DELIMETER)) |
jrodenburg | 8:dbf8bd4815f8 | 363 | return; |
jrodenburg | 2:bd118a724f03 | 364 | |
jrodenburg | 8:dbf8bd4815f8 | 365 | switch (pRxPktHdr->cmd_type) |
jrodenburg | 8:dbf8bd4815f8 | 366 | { |
jrodenburg | 8:dbf8bd4815f8 | 367 | case SET_TEMPERATURE: |
jrodenburg | 8:dbf8bd4815f8 | 368 | // Process set temp for specified channel |
jrodenburg | 8:dbf8bd4815f8 | 369 | { |
jrodenburg | 8:dbf8bd4815f8 | 370 | SET_TEMPERATURE_CMD *pRxPkt = (SET_TEMPERATURE_CMD *)(rxBuf); |
jrodenburg | 15:74a01aaeb60e | 371 | #ifdef DEBUG |
jrodenburg | 15:74a01aaeb60e | 372 | pc.printf("DBG: SETTEMP: ch = %02x, tempSet = %f, chanStat = %02x\n", |
jrodenburg | 15:74a01aaeb60e | 373 | pRxPkt->chanID, pRxPkt->setTemp, pRxPkt->chanStat); |
jrodenburg | 8:dbf8bd4815f8 | 374 | #endif |
jrodenburg | 8:dbf8bd4815f8 | 375 | if ((pRxPkt->tempDelim != DELIMETER) || (pRxPkt->chanStatDelim != DELIMETER)) { |
jrodenburg | 8:dbf8bd4815f8 | 376 | // Send NAK back |
jrodenburg | 8:dbf8bd4815f8 | 377 | pc.printf("DBG: Error\n"); |
jrodenburg | 2:bd118a724f03 | 378 | } |
jrodenburg | 8:dbf8bd4815f8 | 379 | else { |
jrodenburg | 8:dbf8bd4815f8 | 380 | chanSel_SetTemp = pRxPkt->chanID; |
jrodenburg | 8:dbf8bd4815f8 | 381 | chnlStatus[pRxPkt->chanID].status = pRxPkt->chanStat; |
jrodenburg | 8:dbf8bd4815f8 | 382 | chnlStatus[pRxPkt->chanID].setTemp = pRxPkt->setTemp; |
jrodenburg | 9:1cada1fe4743 | 383 | chnlStatus[pRxPkt->chanID].error = 0; |
jrodenburg | 14:69cd53434783 | 384 | chnlStatus[pRxPkt->chanID].heater_init_time = 0; |
jrodenburg | 8:dbf8bd4815f8 | 385 | newTempSet = true; |
jrodenburg | 2:bd118a724f03 | 386 | } |
jrodenburg | 2:bd118a724f03 | 387 | } |
jrodenburg | 8:dbf8bd4815f8 | 388 | break; |
jrodenburg | 8:dbf8bd4815f8 | 389 | |
jrodenburg | 8:dbf8bd4815f8 | 390 | case SELECT_CHANNEL: |
jrodenburg | 8:dbf8bd4815f8 | 391 | // Select channel to send temp data to |
jrodenburg | 8:dbf8bd4815f8 | 392 | { |
jrodenburg | 8:dbf8bd4815f8 | 393 | SELECT_CHANNEL_CMD *pRxPkt = (SELECT_CHANNEL_CMD *)(rxBuf); |
jrodenburg | 8:dbf8bd4815f8 | 394 | |
jrodenburg | 8:dbf8bd4815f8 | 395 | chanSel_SendTemp = pRxPkt->chanIDSel; |
jrodenburg | 15:74a01aaeb60e | 396 | #ifdef DEBUG |
jrodenburg | 15:74a01aaeb60e | 397 | pc.printf("DBG: CHAN_SEL: chan=%02x, chanStat = %02x\n", pRxPkt->chanIDSel, pRxPkt->chanStat); |
jrodenburg | 8:dbf8bd4815f8 | 398 | #endif |
jrodenburg | 2:bd118a724f03 | 399 | } |
jrodenburg | 8:dbf8bd4815f8 | 400 | break; |
jrodenburg | 8:dbf8bd4815f8 | 401 | |
jrodenburg | 15:74a01aaeb60e | 402 | case READ_UID: |
jrodenburg | 15:74a01aaeb60e | 403 | { |
jrodenburg | 15:74a01aaeb60e | 404 | READ_UID_CMD *pRxPkt = (READ_UID_CMD *)(rxBuf); |
jrodenburg | 15:74a01aaeb60e | 405 | #ifdef DEBUG |
jrodenburg | 15:74a01aaeb60e | 406 | pc.printf("DBG: Read UID: chan%02x\n", pRxPkt->chanIDSel); |
jrodenburg | 15:74a01aaeb60e | 407 | #endif |
jrodenburg | 15:74a01aaeb60e | 408 | sendUID(); |
jrodenburg | 15:74a01aaeb60e | 409 | } |
jrodenburg | 15:74a01aaeb60e | 410 | break; |
jrodenburg | 15:74a01aaeb60e | 411 | |
jrodenburg | 8:dbf8bd4815f8 | 412 | default: |
jrodenburg | 8:dbf8bd4815f8 | 413 | // Error |
jrodenburg | 8:dbf8bd4815f8 | 414 | break; |
jrodenburg | 2:bd118a724f03 | 415 | } |
jrodenburg | 1:0182b86f9bd4 | 416 | } |
jrodenburg | 0:a28a1035c31b | 417 | |
jrodenburg | 15:74a01aaeb60e | 418 | |
jrodenburg | 15:74a01aaeb60e | 419 | |
jrodenburg | 0:a28a1035c31b | 420 | /* Function: get_temp |
jrodenburg | 0:a28a1035c31b | 421 | ************************************************************** |
jrodenburg | 0:a28a1035c31b | 422 | Description: Retrieve data from thermistor |
jrodenburg | 9:1cada1fe4743 | 423 | Receives: chn: the channel of the fixture to read temp. from |
jrodenburg | 5:0f38a0bd4f86 | 424 | port: the I/O channel to read |
jrodenburg | 0:a28a1035c31b | 425 | Returns: the temperature of the fixture (front or back) |
jrodenburg | 0:a28a1035c31b | 426 | */ |
jrodenburg | 0:a28a1035c31b | 427 | |
jrodenburg | 5:0f38a0bd4f86 | 428 | float get_temp(int chn, int port){ |
jrodenburg | 1:0182b86f9bd4 | 429 | myled = 1; |
jrodenburg | 0:a28a1035c31b | 430 | ltc2487.setAddress(addrLUT[chn].adc); |
jrodenburg | 9:1cada1fe4743 | 431 | |
jrodenburg | 5:0f38a0bd4f86 | 432 | float ADC_val = ltc2487.readOutput(port); //(65536*1.334)/2.5 |
jrodenburg | 9:1cada1fe4743 | 433 | |
jrodenburg | 0:a28a1035c31b | 434 | int i = 0; |
jrodenburg | 9:1cada1fe4743 | 435 | |
jrodenburg | 0:a28a1035c31b | 436 | while((i < sizeLUT) && (thermLUT[i].adc > ADC_val)){ |
jrodenburg | 9:1cada1fe4743 | 437 | i++; |
jrodenburg | 0:a28a1035c31b | 438 | } //find the temp. above therm temp |
jrodenburg | 9:1cada1fe4743 | 439 | |
jrodenburg | 9:1cada1fe4743 | 440 | //Point slope formula extrapolation: |
jrodenburg | 14:69cd53434783 | 441 | // m = (y1-y0)/(x1-x0)+ y0 , y = temp. value, x = adc value |
jrodenburg | 0:a28a1035c31b | 442 | // y1 = thermLUT[i-1].temp y0 = thermLUT[i].temp |
jrodenburg | 0:a28a1035c31b | 443 | // x1 = thermLUT[i-1].adc x0 =thermLUT[i].adc |
jrodenburg | 0:a28a1035c31b | 444 | float a = float(thermLUT[i-1].temp - thermLUT[i].temp); //slope of temp between points where therm temp is between (Tmax - Tmin) |
jrodenburg | 0:a28a1035c31b | 445 | float b = float(thermLUT[i-1].adc - thermLUT[i].adc); //slope of adc between points where therm adc is between (Amax - Amin) |
jrodenburg | 9:1cada1fe4743 | 446 | |
jrodenburg | 0:a28a1035c31b | 447 | float m = a/b; |
jrodenburg | 0:a28a1035c31b | 448 | float y = (m*(ADC_val-thermLUT[i].adc))+thermLUT[i].temp; |
jrodenburg | 9:1cada1fe4743 | 449 | |
jrodenburg | 9:1cada1fe4743 | 450 | if(DEBUG2) pc.printf("DBG: CHAN: %i PORT: %i ADC VAL: %f TEMP: %f \r\n", chn, port, ADC_val, y); |
jrodenburg | 9:1cada1fe4743 | 451 | |
jrodenburg | 9:1cada1fe4743 | 452 | return y; |
jrodenburg | 0:a28a1035c31b | 453 | } |
jrodenburg | 0:a28a1035c31b | 454 | |
jrodenburg | 0:a28a1035c31b | 455 | /* Function: get_heater_current |
jrodenburg | 0:a28a1035c31b | 456 | ************************************************************** |
jrodenburg | 0:a28a1035c31b | 457 | Description: Retrieve current into heater control MOSFET |
jrodenburg | 9:1cada1fe4743 | 458 | Receives: chn: the channel of the fixture to read current from |
jrodenburg | 0:a28a1035c31b | 459 | Returns: the current into the heater control MOSFET |
jrodenburg | 0:a28a1035c31b | 460 | */ |
jrodenburg | 0:a28a1035c31b | 461 | |
jrodenburg | 6:c980535393ed | 462 | float get_heater_current(int chn, int port){ |
jrodenburg | 6:c980535393ed | 463 | return ltc2487.readOutput(port); |
jrodenburg | 0:a28a1035c31b | 464 | } |
jrodenburg | 0:a28a1035c31b | 465 | |
jrodenburg | 0:a28a1035c31b | 466 | /* Function: get_valve_current |
jrodenburg | 0:a28a1035c31b | 467 | ************************************************************** |
jrodenburg | 0:a28a1035c31b | 468 | Description: Retrieve current into valve control MOSFET |
jrodenburg | 9:1cada1fe4743 | 469 | Receives: chn: the channel of the fixture to read current from |
jrodenburg | 0:a28a1035c31b | 470 | Returns: the current into the valve control MOSFET |
jrodenburg | 0:a28a1035c31b | 471 | */ |
jrodenburg | 0:a28a1035c31b | 472 | |
jrodenburg | 6:c980535393ed | 473 | float get_valve_current(int chn, int port){ |
jrodenburg | 6:c980535393ed | 474 | return ltc2487.readOutput(port); |
jrodenburg | 0:a28a1035c31b | 475 | } |
jrodenburg | 0:a28a1035c31b | 476 | |
jrodenburg | 0:a28a1035c31b | 477 | /* Function: turn_valve_on |
jrodenburg | 0:a28a1035c31b | 478 | ************************************************************** |
jrodenburg | 1:0182b86f9bd4 | 479 | Description: Turn valve on and green status LED on |
jrodenburg | 9:1cada1fe4743 | 480 | Receives: chn: the channel of the fixture |
jrodenburg | 1:0182b86f9bd4 | 481 | Returns: N/A |
jrodenburg | 0:a28a1035c31b | 482 | */ |
jrodenburg | 0:a28a1035c31b | 483 | |
jrodenburg | 1:0182b86f9bd4 | 484 | void turn_valve_on(int chn){ |
jrodenburg | 0:a28a1035c31b | 485 | io_control.setAddress(addrLUT[chn].io); |
jrodenburg | 0:a28a1035c31b | 486 | io_control.init(); |
jrodenburg | 1:0182b86f9bd4 | 487 | io_control.writeOutput(1,0,1,0); |
jrodenburg | 0:a28a1035c31b | 488 | } |
jrodenburg | 0:a28a1035c31b | 489 | |
jrodenburg | 0:a28a1035c31b | 490 | /* Function: turn_valve_off |
jrodenburg | 0:a28a1035c31b | 491 | ************************************************************** |
jrodenburg | 1:0182b86f9bd4 | 492 | Description: Turn valve off and green status LED on |
jrodenburg | 9:1cada1fe4743 | 493 | Receives: chn: the channel of the fixture |
jrodenburg | 1:0182b86f9bd4 | 494 | Returns: N/A |
jrodenburg | 0:a28a1035c31b | 495 | */ |
jrodenburg | 0:a28a1035c31b | 496 | |
jrodenburg | 1:0182b86f9bd4 | 497 | void turn_valve_off(int chn){ |
jrodenburg | 0:a28a1035c31b | 498 | io_control.setAddress(addrLUT[chn].io); |
jrodenburg | 0:a28a1035c31b | 499 | io_control.init(); |
jrodenburg | 1:0182b86f9bd4 | 500 | io_control.writeOutput(0,0,1,0); |
jrodenburg | 0:a28a1035c31b | 501 | } |
jrodenburg | 0:a28a1035c31b | 502 | |
jrodenburg | 0:a28a1035c31b | 503 | /* Function: turn_heater_on |
jrodenburg | 0:a28a1035c31b | 504 | ************************************************************** |
jrodenburg | 1:0182b86f9bd4 | 505 | Description: Turn heater on and green status LED on |
jrodenburg | 9:1cada1fe4743 | 506 | Receives: chn: the channel of the fixture |
jrodenburg | 1:0182b86f9bd4 | 507 | Returns: N/A |
jrodenburg | 0:a28a1035c31b | 508 | */ |
jrodenburg | 0:a28a1035c31b | 509 | |
jrodenburg | 1:0182b86f9bd4 | 510 | void turn_heater_on(int chn){ |
jrodenburg | 0:a28a1035c31b | 511 | io_control.setAddress(addrLUT[chn].io); |
jrodenburg | 0:a28a1035c31b | 512 | io_control.init(); |
jrodenburg | 1:0182b86f9bd4 | 513 | io_control.writeOutput(0,1,1,0); |
jrodenburg | 0:a28a1035c31b | 514 | } |
jrodenburg | 0:a28a1035c31b | 515 | |
jrodenburg | 0:a28a1035c31b | 516 | /* Function: turn_heater_off |
jrodenburg | 0:a28a1035c31b | 517 | ************************************************************** |
jrodenburg | 1:0182b86f9bd4 | 518 | Description: Turn heater off and green status LED on |
jrodenburg | 9:1cada1fe4743 | 519 | Receives: chn: the channel of the fixture |
jrodenburg | 1:0182b86f9bd4 | 520 | Returns: N/A |
jrodenburg | 0:a28a1035c31b | 521 | */ |
jrodenburg | 0:a28a1035c31b | 522 | |
jrodenburg | 1:0182b86f9bd4 | 523 | void turn_heater_off(int chn){ |
jrodenburg | 0:a28a1035c31b | 524 | io_control.setAddress(addrLUT[chn].io); |
jrodenburg | 0:a28a1035c31b | 525 | io_control.init(); |
jrodenburg | 1:0182b86f9bd4 | 526 | io_control.writeOutput(0,0,1,0); |
jrodenburg | 0:a28a1035c31b | 527 | } |
jrodenburg | 0:a28a1035c31b | 528 | |
jrodenburg | 0:a28a1035c31b | 529 | /* Function: status_led |
jrodenburg | 0:a28a1035c31b | 530 | ************************************************************** |
jrodenburg | 0:a28a1035c31b | 531 | Description: Turn status LED on (turns on green or red) |
jrodenburg | 9:1cada1fe4743 | 532 | Receives: chn: the channel of the fixture |
jrodenburg | 0:a28a1035c31b | 533 | status: the status of channel (good (1) or bad (0)) |
jrodenburg | 1:0182b86f9bd4 | 534 | Returns: N/A |
jrodenburg | 0:a28a1035c31b | 535 | */ |
jrodenburg | 0:a28a1035c31b | 536 | |
jrodenburg | 1:0182b86f9bd4 | 537 | void status_led(int chn, int status){ |
jrodenburg | 0:a28a1035c31b | 538 | io_control.setAddress(addrLUT[chn].io); |
jrodenburg | 0:a28a1035c31b | 539 | if(status){ |
jrodenburg | 1:0182b86f9bd4 | 540 | io_control.writeOutput(0,0,1,0); |
jrodenburg | 0:a28a1035c31b | 541 | } |
jrodenburg | 0:a28a1035c31b | 542 | else{ |
jrodenburg | 8:dbf8bd4815f8 | 543 | //turn valve on too |
jrodenburg | 8:dbf8bd4815f8 | 544 | io_control.writeOutput(1,0,0,1); |
jrodenburg | 0:a28a1035c31b | 545 | } |
jrodenburg | 0:a28a1035c31b | 546 | } |
jrodenburg | 0:a28a1035c31b | 547 | |
jrodenburg | 1:0182b86f9bd4 | 548 | /* Function: test_mcp23008 |
jrodenburg | 1:0182b86f9bd4 | 549 | ************************************************************** |
jrodenburg | 1:0182b86f9bd4 | 550 | Description: Test each output of the MCP23009 |
jrodenburg | 9:1cada1fe4743 | 551 | Receives: N/A |
jrodenburg | 1:0182b86f9bd4 | 552 | Returns: N/A |
jrodenburg | 1:0182b86f9bd4 | 553 | */ |
jrodenburg | 1:0182b86f9bd4 | 554 | |
jrodenburg | 1:0182b86f9bd4 | 555 | void test_mcp23008(int chn){ |
jrodenburg | 1:0182b86f9bd4 | 556 | turn_valve_on(chn); |
jrodenburg | 7:8a5e65e63e2a | 557 | wait(0.5); |
jrodenburg | 1:0182b86f9bd4 | 558 | turn_valve_off(chn); |
jrodenburg | 7:8a5e65e63e2a | 559 | wait(0.5); |
jrodenburg | 1:0182b86f9bd4 | 560 | turn_heater_on(chn); |
jrodenburg | 7:8a5e65e63e2a | 561 | wait(0.5); |
jrodenburg | 1:0182b86f9bd4 | 562 | turn_heater_off(chn); |
jrodenburg | 7:8a5e65e63e2a | 563 | wait(0.5); |
jrodenburg | 1:0182b86f9bd4 | 564 | status_led(chn, 0); |
jrodenburg | 7:8a5e65e63e2a | 565 | wait(0.5); |
jrodenburg | 1:0182b86f9bd4 | 566 | status_led(chn, 1); |
jrodenburg | 1:0182b86f9bd4 | 567 | } |
jrodenburg | 1:0182b86f9bd4 | 568 | |
jrodenburg | 2:bd118a724f03 | 569 | /* Function: test_ltc2487 |
jrodenburg | 2:bd118a724f03 | 570 | ************************************************************** |
jrodenburg | 2:bd118a724f03 | 571 | Description: Test the reading from LTC2487 |
jrodenburg | 9:1cada1fe4743 | 572 | Receives: N/A |
jrodenburg | 2:bd118a724f03 | 573 | Returns: N/A |
jrodenburg | 2:bd118a724f03 | 574 | */ |
jrodenburg | 2:bd118a724f03 | 575 | |
jrodenburg | 2:bd118a724f03 | 576 | void test_ltc2487(int chn){ |
jrodenburg | 5:0f38a0bd4f86 | 577 | get_temp(chn, FRONT_THERM); |
jrodenburg | 5:0f38a0bd4f86 | 578 | wait(0.1); |
jrodenburg | 6:c980535393ed | 579 | get_temp(chn, BACK_THERM); |
jrodenburg | 6:c980535393ed | 580 | wait(0.1); |
jrodenburg | 8:dbf8bd4815f8 | 581 | get_temp(chn, VALVE_FET_AMP); |
jrodenburg | 8:dbf8bd4815f8 | 582 | wait(0.1); |
jrodenburg | 4:168a446bd0da | 583 | //if(DEBUG1) pc.printf("TEMPERATURE READING: %f \r\n", get_temp(chn)); |
jrodenburg | 2:bd118a724f03 | 584 | } |
jrodenburg | 2:bd118a724f03 | 585 | |
jrodenburg | 8:dbf8bd4815f8 | 586 | //*************************************************************** |
jrodenburg | 8:dbf8bd4815f8 | 587 | // Build packet with temperature readings to send to GUI |
jrodenburg | 8:dbf8bd4815f8 | 588 | //*************************************************************** |
jrodenburg | 8:dbf8bd4815f8 | 589 | void sendTempReadings (int chan, float currentTemp) |
jrodenburg | 8:dbf8bd4815f8 | 590 | { |
jrodenburg | 8:dbf8bd4815f8 | 591 | RESPONSE_CMD response; |
jrodenburg | 8:dbf8bd4815f8 | 592 | unsigned char *ptr = (unsigned char *)&response; |
jrodenburg | 8:dbf8bd4815f8 | 593 | int i; |
jrodenburg | 8:dbf8bd4815f8 | 594 | |
jrodenburg | 8:dbf8bd4815f8 | 595 | response.SOF_flag = TX_SOF; |
jrodenburg | 15:74a01aaeb60e | 596 | response.cmd_type = TEMP_DATA; |
jrodenburg | 8:dbf8bd4815f8 | 597 | response.len = 9; |
jrodenburg | 8:dbf8bd4815f8 | 598 | response.Delim = DELIMETER; |
jrodenburg | 8:dbf8bd4815f8 | 599 | response.data = (float)currentTemp; |
jrodenburg | 8:dbf8bd4815f8 | 600 | response.EOF_flag = TX_EOF; |
jrodenburg | 8:dbf8bd4815f8 | 601 | |
jrodenburg | 8:dbf8bd4815f8 | 602 | // Send response to GUI |
jrodenburg | 8:dbf8bd4815f8 | 603 | for (i=0; i < response.len; i++, ptr++) |
jrodenburg | 8:dbf8bd4815f8 | 604 | pc.printf("%02x", *ptr); |
jrodenburg | 8:dbf8bd4815f8 | 605 | pc.printf("\n"); |
jrodenburg | 8:dbf8bd4815f8 | 606 | } |
jrodenburg | 8:dbf8bd4815f8 | 607 | |
jrodenburg | 9:1cada1fe4743 | 608 | //*************************************************************** |
jrodenburg | 15:74a01aaeb60e | 609 | // Build packet with Board UID (Unique Identification) |
jrodenburg | 15:74a01aaeb60e | 610 | //*************************************************************** |
jrodenburg | 15:74a01aaeb60e | 611 | void sendUID () |
jrodenburg | 15:74a01aaeb60e | 612 | { |
jrodenburg | 15:74a01aaeb60e | 613 | UID_RESPONSE response; |
jrodenburg | 15:74a01aaeb60e | 614 | unsigned char *ptr = (unsigned char *)&response; |
jrodenburg | 15:74a01aaeb60e | 615 | int i; |
jrodenburg | 15:74a01aaeb60e | 616 | |
jrodenburg | 15:74a01aaeb60e | 617 | response.SOF_flag = TX_SOF; |
jrodenburg | 15:74a01aaeb60e | 618 | response.cmd_type = UID_DATA; |
jrodenburg | 15:74a01aaeb60e | 619 | response.len = 17; |
jrodenburg | 15:74a01aaeb60e | 620 | response.Delim = DELIMETER; |
jrodenburg | 15:74a01aaeb60e | 621 | response.UIDMH = (uint32_t)SIM->UIDMH; |
jrodenburg | 15:74a01aaeb60e | 622 | response.UIDML = (uint32_t)SIM->UIDML; |
jrodenburg | 15:74a01aaeb60e | 623 | response.UIDL = (uint32_t)SIM->UIDL; |
jrodenburg | 15:74a01aaeb60e | 624 | response.EOF_flag = TX_EOF; |
jrodenburg | 15:74a01aaeb60e | 625 | |
jrodenburg | 15:74a01aaeb60e | 626 | // Send response to GUI |
jrodenburg | 15:74a01aaeb60e | 627 | for (i=0; i < response.len; i++, ptr++) |
jrodenburg | 15:74a01aaeb60e | 628 | pc.printf("%02x", *ptr); |
jrodenburg | 15:74a01aaeb60e | 629 | pc.printf("\n"); |
jrodenburg | 15:74a01aaeb60e | 630 | } |
jrodenburg | 15:74a01aaeb60e | 631 | |
jrodenburg | 15:74a01aaeb60e | 632 | //*************************************************************** |
jrodenburg | 9:1cada1fe4743 | 633 | // Build packet with errors to send to GUI |
jrodenburg | 9:1cada1fe4743 | 634 | //*************************************************************** |
jrodenburg | 9:1cada1fe4743 | 635 | void sendError (int chan, float error) |
jrodenburg | 9:1cada1fe4743 | 636 | { |
jrodenburg | 9:1cada1fe4743 | 637 | RESPONSE_CMD response; |
jrodenburg | 9:1cada1fe4743 | 638 | unsigned char *ptr = (unsigned char *)&response; |
jrodenburg | 9:1cada1fe4743 | 639 | int i; |
jrodenburg | 9:1cada1fe4743 | 640 | |
jrodenburg | 9:1cada1fe4743 | 641 | response.SOF_flag = TX_SOF; |
jrodenburg | 9:1cada1fe4743 | 642 | response.cmd_type = ERROR_DATA; |
jrodenburg | 9:1cada1fe4743 | 643 | response.len = 9; |
jrodenburg | 9:1cada1fe4743 | 644 | response.Delim = DELIMETER; |
jrodenburg | 9:1cada1fe4743 | 645 | response.data = (float)error; |
jrodenburg | 9:1cada1fe4743 | 646 | response.EOF_flag = TX_EOF; |
jrodenburg | 9:1cada1fe4743 | 647 | |
jrodenburg | 9:1cada1fe4743 | 648 | // Send response to GUI |
jrodenburg | 9:1cada1fe4743 | 649 | for (i=0; i < response.len; i++, ptr++) |
jrodenburg | 9:1cada1fe4743 | 650 | pc.printf("%02x", *ptr); |
jrodenburg | 9:1cada1fe4743 | 651 | pc.printf("\n"); |
jrodenburg | 9:1cada1fe4743 | 652 | } |
jrodenburg | 6:c980535393ed | 653 | |
jrodenburg | 14:69cd53434783 | 654 | /* Function: error_check |
jrodenburg | 14:69cd53434783 | 655 | ************************************************************** |
jrodenburg | 14:69cd53434783 | 656 | Description: Checks for any system errors |
jrodenburg | 14:69cd53434783 | 657 | Recieves: frontTemp: temp. of front thermistor |
jrodenburg | 14:69cd53434783 | 658 | backTemp: temp. of back thermistor |
jrodenburg | 14:69cd53434783 | 659 | currTimeMin: currentTime in minutes |
jrodenburg | 14:69cd53434783 | 660 | Returns: N/A |
jrodenburg | 14:69cd53434783 | 661 | */ |
jrodenburg | 14:69cd53434783 | 662 | |
jrodenburg | 14:69cd53434783 | 663 | void error_check(int chnl, float currentTempFront, float currentTempBack, int currTimeMin){ |
jrodenburg | 14:69cd53434783 | 664 | if((currentTempFront >= MAX_TEMP) && (currentTempBack >= MAX_TEMP)){ |
jrodenburg | 14:69cd53434783 | 665 | status_led(chnl, STATUS_BAD); |
jrodenburg | 14:69cd53434783 | 666 | sendError(chnl, 1); |
jrodenburg | 14:69cd53434783 | 667 | chnlStatus[chnl].error = 1; |
jrodenburg | 14:69cd53434783 | 668 | if(DEBUG3) pc.printf("DBG: [%d] ERROR 1 \r\n", chnl); |
jrodenburg | 14:69cd53434783 | 669 | } |
jrodenburg | 14:69cd53434783 | 670 | if(((currentTempFront == 0) || (currentTempBack == 0))){ |
jrodenburg | 14:69cd53434783 | 671 | status_led(chnl, STATUS_BAD); |
jrodenburg | 14:69cd53434783 | 672 | sendError(chnl, 2); |
jrodenburg | 14:69cd53434783 | 673 | chnlStatus[chnl].error = 1; |
jrodenburg | 14:69cd53434783 | 674 | if(DEBUG3) pc.printf("DBG: [%d] ERROR 2 \r\n", chnl); |
jrodenburg | 14:69cd53434783 | 675 | } |
jrodenburg | 14:69cd53434783 | 676 | if((abs(currentTempBack - currentTempFront) >= TEMP_MARGIN)){ |
jrodenburg | 14:69cd53434783 | 677 | status_led(chnl, STATUS_BAD); |
jrodenburg | 14:69cd53434783 | 678 | sendError(chnl, 3); |
jrodenburg | 14:69cd53434783 | 679 | chnlStatus[chnl].error = 1; |
jrodenburg | 14:69cd53434783 | 680 | if(DEBUG3) pc.printf("DBG: [%d] ERROR 3 \r\n", chnl); |
jrodenburg | 14:69cd53434783 | 681 | } |
jrodenburg | 14:69cd53434783 | 682 | if(((currentTempFront <= MIN_TEMP) && (currentTempBack <= MIN_TEMP))){ |
jrodenburg | 14:69cd53434783 | 683 | status_led(chnl, STATUS_BAD); |
jrodenburg | 14:69cd53434783 | 684 | sendError(chnl, 4); |
jrodenburg | 14:69cd53434783 | 685 | chnlStatus[chnl].error = 1; |
jrodenburg | 14:69cd53434783 | 686 | if(DEBUG3) pc.printf("DBG: [%d] ERROR 4 \r\n", chnl); |
jrodenburg | 14:69cd53434783 | 687 | } |
jrodenburg | 14:69cd53434783 | 688 | if(chnlStatus[chnl].heater_init_time != 0){ |
jrodenburg | 14:69cd53434783 | 689 | int init_time = chnlStatus[chnl].heater_init_time; |
jrodenburg | 15:74a01aaeb60e | 690 | int on_time_heater = currTimeMin - init_time; |
jrodenburg | 14:69cd53434783 | 691 | //account for 0 crossover |
jrodenburg | 14:69cd53434783 | 692 | if(init_time > currTimeMin){ |
jrodenburg | 14:69cd53434783 | 693 | on_time_heater = (60 - init_time)+currTimeMin; |
jrodenburg | 14:69cd53434783 | 694 | } |
jrodenburg | 14:69cd53434783 | 695 | |
jrodenburg | 14:69cd53434783 | 696 | if(on_time_heater > MAX_HEATER_ON_TIME){ |
jrodenburg | 14:69cd53434783 | 697 | status_led(chnl, STATUS_BAD); |
jrodenburg | 14:69cd53434783 | 698 | sendError(chnl, 5); |
jrodenburg | 14:69cd53434783 | 699 | chnlStatus[chnl].error = 1; |
jrodenburg | 14:69cd53434783 | 700 | chnlStatus[chnl].heater_init_time = 0; |
jrodenburg | 14:69cd53434783 | 701 | if(DEBUG3) pc.printf("DBG: [%d] ERROR 5 \r\n", chnl); |
jrodenburg | 14:69cd53434783 | 702 | } |
jrodenburg | 14:69cd53434783 | 703 | } |
jrodenburg | 14:69cd53434783 | 704 | if(chnlStatus[chnl].error == 1){ |
jrodenburg | 14:69cd53434783 | 705 | status_led(chnl, STATUS_BAD); |
jrodenburg | 14:69cd53434783 | 706 | chnlStatus[chnl].error = 1; |
jrodenburg | 14:69cd53434783 | 707 | } |
jrodenburg | 14:69cd53434783 | 708 | } |
jrodenburg | 14:69cd53434783 | 709 | |
jrodenburg | 6:c980535393ed | 710 | |
jrodenburg | 6:c980535393ed | 711 | /*************************************************************/ |
jrodenburg | 6:c980535393ed | 712 | /* MAIN FUNCTION */ |
jrodenburg | 6:c980535393ed | 713 | /*************************************************************/ |
jrodenburg | 0:a28a1035c31b | 714 | |
jrodenburg | 9:1cada1fe4743 | 715 | int main() { |
jrodenburg | 14:69cd53434783 | 716 | //variables for controlling board |
jrodenburg | 9:1cada1fe4743 | 717 | Timer t; |
jrodenburg | 14:69cd53434783 | 718 | Timer t_cool; |
jrodenburg | 14:69cd53434783 | 719 | int time_min = 0; |
jrodenburg | 14:69cd53434783 | 720 | int init_heat_time = 0; |
jrodenburg | 15:74a01aaeb60e | 721 | uint32_t UIDMH, UIDML, UIDL; |
jrodenburg | 8:dbf8bd4815f8 | 722 | |
jrodenburg | 8:dbf8bd4815f8 | 723 | // Setup serial port |
jrodenburg | 8:dbf8bd4815f8 | 724 | // Look for RX_EOF |
jrodenburg | 8:dbf8bd4815f8 | 725 | pc.baud(9600); |
jrodenburg | 8:dbf8bd4815f8 | 726 | pc.autoDetectChar(RX_EOF); |
jrodenburg | 8:dbf8bd4815f8 | 727 | pc.attach(&rxInterrupt, MODSERIAL::RxAutoDetect); |
jrodenburg | 8:dbf8bd4815f8 | 728 | |
jrodenburg | 8:dbf8bd4815f8 | 729 | myled = 1; |
jrodenburg | 9:1cada1fe4743 | 730 | rLed = 1; |
jrodenburg | 9:1cada1fe4743 | 731 | gLed = 0; |
jrodenburg | 9:1cada1fe4743 | 732 | |
jrodenburg | 8:dbf8bd4815f8 | 733 | t.start(); |
jrodenburg | 9:1cada1fe4743 | 734 | |
jrodenburg | 15:74a01aaeb60e | 735 | sendUID(); |
jrodenburg | 15:74a01aaeb60e | 736 | |
jrodenburg | 15:74a01aaeb60e | 737 | UIDMH = (uint32_t)SIM->UIDMH; |
jrodenburg | 15:74a01aaeb60e | 738 | UIDML = (uint32_t)SIM->UIDML; |
jrodenburg | 15:74a01aaeb60e | 739 | UIDL = (uint32_t)SIM->UIDL; |
jrodenburg | 15:74a01aaeb60e | 740 | |
jrodenburg | 0:a28a1035c31b | 741 | while(1) { |
jrodenburg | 9:1cada1fe4743 | 742 | |
jrodenburg | 15:74a01aaeb60e | 743 | if(DEBUG3) { |
jrodenburg | 15:74a01aaeb60e | 744 | pc.printf("DBG: <%f>[UID: %04X%08X%08X] PSTARTED\n", t.read(), UIDMH, UIDML, UIDL); |
jrodenburg | 15:74a01aaeb60e | 745 | } |
jrodenburg | 9:1cada1fe4743 | 746 | |
jrodenburg | 14:69cd53434783 | 747 | //setup timer used to track how long the heater is on |
jrodenburg | 14:69cd53434783 | 748 | float time_sec = t.read(); |
jrodenburg | 14:69cd53434783 | 749 | |
jrodenburg | 13:604e6933366f | 750 | if(time_sec >= 60){ |
jrodenburg | 14:69cd53434783 | 751 | time_min++; |
jrodenburg | 14:69cd53434783 | 752 | //time_sec = 0; |
jrodenburg | 13:604e6933366f | 753 | t.reset(); |
jrodenburg | 13:604e6933366f | 754 | } |
jrodenburg | 14:69cd53434783 | 755 | |
jrodenburg | 14:69cd53434783 | 756 | if(time_min >= 60){ |
jrodenburg | 14:69cd53434783 | 757 | time_min = 0; |
jrodenburg | 14:69cd53434783 | 758 | } |
jrodenburg | 14:69cd53434783 | 759 | |
jrodenburg | 14:69cd53434783 | 760 | //pc.printf("Time: %f \r\n", time_sec); |
jrodenburg | 13:604e6933366f | 761 | |
jrodenburg | 5:0f38a0bd4f86 | 762 | for(int chnl = 0; chnl < CHN_COUNT; chnl++){ |
jrodenburg | 5:0f38a0bd4f86 | 763 | float currentTempFront = get_temp(chnl, FRONT_THERM); |
jrodenburg | 9:1cada1fe4743 | 764 | |
jrodenburg | 8:dbf8bd4815f8 | 765 | //check if we received data/need to update TCTF data |
jrodenburg | 8:dbf8bd4815f8 | 766 | if(dataReceived){ |
jrodenburg | 8:dbf8bd4815f8 | 767 | dataReceived = false; |
jrodenburg | 15:74a01aaeb60e | 768 | #ifdef DEBUG |
jrodenburg | 9:1cada1fe4743 | 769 | pc.printf("DBG: %d bytes Rx'd\n", pc.rxBufferGetCount()); |
jrodenburg | 15:74a01aaeb60e | 770 | #endif |
jrodenburg | 8:dbf8bd4815f8 | 771 | pc.move(rxBuf, 50); |
jrodenburg | 8:dbf8bd4815f8 | 772 | parseRXData(); |
jrodenburg | 8:dbf8bd4815f8 | 773 | pc.rxBufferFlush(); |
jrodenburg | 9:1cada1fe4743 | 774 | } |
jrodenburg | 8:dbf8bd4815f8 | 775 | |
jrodenburg | 13:604e6933366f | 776 | float currentTempBack = get_temp(chnl, BACK_THERM); |
jrodenburg | 13:604e6933366f | 777 | float currentTemp = currentTempBack; |
jrodenburg | 13:604e6933366f | 778 | |
jrodenburg | 8:dbf8bd4815f8 | 779 | if (chnl == chanSel_SendTemp){ |
jrodenburg | 9:1cada1fe4743 | 780 | //Send temp readings for selected chan to GUI |
jrodenburg | 8:dbf8bd4815f8 | 781 | sendTempReadings(currChan, currentTemp); |
jrodenburg | 8:dbf8bd4815f8 | 782 | } |
jrodenburg | 14:69cd53434783 | 783 | |
jrodenburg | 14:69cd53434783 | 784 | //Error check on fixture |
jrodenburg | 14:69cd53434783 | 785 | error_check(chnl, currentTempFront, currentTempBack, time_min); |
jrodenburg | 9:1cada1fe4743 | 786 | |
jrodenburg | 2:bd118a724f03 | 787 | //CONTROL LOOP: |
jrodenburg | 4:168a446bd0da | 788 | if(chnlStatus[chnl].status == 1){ |
jrodenburg | 15:74a01aaeb60e | 789 | if(DEBUG) pc.printf("DBG: [%d] Temp: F: %f B: %f\r\n", chnl, currentTempFront, currentTempBack); |
jrodenburg | 14:69cd53434783 | 790 | //main loop for channels |
jrodenburg | 7:8a5e65e63e2a | 791 | if(chnlStatus[chnl].error == 0){ |
jrodenburg | 9:1cada1fe4743 | 792 | if(currentTemp > ((chnlStatus[chnl].setTemp)+HYST_HIGH)){ |
jrodenburg | 9:1cada1fe4743 | 793 | if(DEBUG3) pc.printf("DBG: [%d] Chiller ON \r\n", chnl); |
jrodenburg | 14:69cd53434783 | 794 | //reset heater on time |
jrodenburg | 14:69cd53434783 | 795 | chnlStatus[chnl].heater_init_time = 0; |
jrodenburg | 14:69cd53434783 | 796 | //reset cooling timer |
jrodenburg | 14:69cd53434783 | 797 | float time_sec = 0; |
jrodenburg | 13:604e6933366f | 798 | //check if the temp. diff. is small and can't wait for an entire period (~4.18) to turn valve off |
jrodenburg | 13:604e6933366f | 799 | if(abs(currentTemp - (chnlStatus[chnl].setTemp)) < 5){ |
jrodenburg | 14:69cd53434783 | 800 | //start timer |
jrodenburg | 14:69cd53434783 | 801 | t_cool.start(); |
jrodenburg | 14:69cd53434783 | 802 | //turn chiller on |
jrodenburg | 13:604e6933366f | 803 | turn_valve_on(chnl); |
jrodenburg | 14:69cd53434783 | 804 | //read timer |
jrodenburg | 14:69cd53434783 | 805 | time_sec = t_cool.read(); |
jrodenburg | 14:69cd53434783 | 806 | while((currentTemp > ((chnlStatus[chnl].setTemp)+HYST_HIGH)) && (time_sec < MAX_CHILL_TIME)){ |
jrodenburg | 13:604e6933366f | 807 | currentTemp = get_temp(chnl, BACK_THERM); |
jrodenburg | 14:69cd53434783 | 808 | time_sec = t_cool.read(); |
jrodenburg | 14:69cd53434783 | 809 | if(DEBUG5) pc.printf("DBG: [%d] TIME: %f \r\n", chnl, time_sec); |
jrodenburg | 13:604e6933366f | 810 | } |
jrodenburg | 14:69cd53434783 | 811 | time_sec = 0; |
jrodenburg | 14:69cd53434783 | 812 | t_cool.stop(); |
jrodenburg | 14:69cd53434783 | 813 | t_cool.reset(); |
jrodenburg | 13:604e6933366f | 814 | turn_valve_off(chnl); |
jrodenburg | 13:604e6933366f | 815 | } |
jrodenburg | 13:604e6933366f | 816 | else{ |
jrodenburg | 13:604e6933366f | 817 | //Turn chiller on |
jrodenburg | 14:69cd53434783 | 818 | turn_valve_on(chnl); |
jrodenburg | 13:604e6933366f | 819 | } |
jrodenburg | 7:8a5e65e63e2a | 820 | } |
jrodenburg | 8:dbf8bd4815f8 | 821 | else if (currentTemp < ((chnlStatus[chnl].setTemp)-HYST_LOW)){ |
jrodenburg | 9:1cada1fe4743 | 822 | if(DEBUG3) pc.printf("DBG: [%d] Heater ON \r\n", chnl); |
jrodenburg | 14:69cd53434783 | 823 | //establish starting time for heater |
jrodenburg | 14:69cd53434783 | 824 | if(chnlStatus[chnl].heater_init_time == 0){ //check if it is the first time that heater has turned on |
jrodenburg | 14:69cd53434783 | 825 | //make sure time isn't zero, otherwise keeping looping until we are not at 0 |
jrodenburg | 14:69cd53434783 | 826 | if(time_min != 0){ |
jrodenburg | 14:69cd53434783 | 827 | chnlStatus[chnl].heater_init_time = time_min; |
jrodenburg | 14:69cd53434783 | 828 | } |
jrodenburg | 14:69cd53434783 | 829 | } |
jrodenburg | 14:69cd53434783 | 830 | if(DEBUG5) pc.printf("DBG: TIME ON: %d %d %f %d %d\r\n", chnlStatus[chnl].heater_init_time, time_min, time_sec, init_heat_time, (chnlStatus[chnl].heater_init_time == NULL)); |
jrodenburg | 7:8a5e65e63e2a | 831 | //Turn heater on |
jrodenburg | 7:8a5e65e63e2a | 832 | turn_heater_on(chnl); |
jrodenburg | 7:8a5e65e63e2a | 833 | } |
jrodenburg | 7:8a5e65e63e2a | 834 | else{ |
jrodenburg | 9:1cada1fe4743 | 835 | if(DEBUG3) pc.printf("DBG: [%d] All OFF \r\n", chnl); |
jrodenburg | 14:69cd53434783 | 836 | //reset heater on time |
jrodenburg | 14:69cd53434783 | 837 | chnlStatus[chnl].heater_init_time = 0; |
jrodenburg | 7:8a5e65e63e2a | 838 | //turn off chiller |
jrodenburg | 7:8a5e65e63e2a | 839 | turn_valve_off(chnl); |
jrodenburg | 9:1cada1fe4743 | 840 | //turn off heater |
jrodenburg | 7:8a5e65e63e2a | 841 | turn_heater_off(chnl); |
jrodenburg | 7:8a5e65e63e2a | 842 | //turn on green LED status light |
jrodenburg | 9:1cada1fe4743 | 843 | status_led(chnl, 1); |
jrodenburg | 9:1cada1fe4743 | 844 | } |
jrodenburg | 9:1cada1fe4743 | 845 | } |
jrodenburg | 2:bd118a724f03 | 846 | } |
jrodenburg | 13:604e6933366f | 847 | else{ |
jrodenburg | 14:69cd53434783 | 848 | if(chnlStatus[chnl].error == 0){ |
jrodenburg | 15:74a01aaeb60e | 849 | //turn off chiller |
jrodenburg | 15:74a01aaeb60e | 850 | turn_valve_off(chnl); |
jrodenburg | 15:74a01aaeb60e | 851 | //turn off heater |
jrodenburg | 15:74a01aaeb60e | 852 | turn_heater_off(chnl); |
jrodenburg | 15:74a01aaeb60e | 853 | //turn on green LED status light |
jrodenburg | 15:74a01aaeb60e | 854 | status_led(chnl, 1); |
jrodenburg | 15:74a01aaeb60e | 855 | } |
jrodenburg | 14:69cd53434783 | 856 | else{ |
jrodenburg | 14:69cd53434783 | 857 | status_led(chnl, STATUS_BAD); |
jrodenburg | 14:69cd53434783 | 858 | } |
jrodenburg | 14:69cd53434783 | 859 | //reset heater on time |
jrodenburg | 14:69cd53434783 | 860 | chnlStatus[chnl].heater_init_time = 0; |
jrodenburg | 13:604e6933366f | 861 | } |
jrodenburg | 2:bd118a724f03 | 862 | } |
jrodenburg | 0:a28a1035c31b | 863 | } |
jrodenburg | 9:1cada1fe4743 | 864 | } |