Aes encryption code
Dependencies: Crypto USBDevice mbed
Fork of larada by
main.cpp@1:ccb26dd9845a, 2016-02-22 (annotated)
- Committer:
- stupid
- Date:
- Mon Feb 22 12:47:47 2016 +0000
- Revision:
- 1:ccb26dd9845a
- Parent:
- 0:aaf22a04f350
- Child:
- 2:35e620097381
added on/off switch monitoring, some code cleanup
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
stupid | 0:aaf22a04f350 | 1 | #include "mbed.h" |
stupid | 0:aaf22a04f350 | 2 | #include "USBSerial.h" |
stupid | 0:aaf22a04f350 | 3 | #include "IAP.h" |
stupid | 0:aaf22a04f350 | 4 | |
stupid | 1:ccb26dd9845a | 5 | // #define SERIAL //comment for USB operation, uncomment for serial |
stupid | 0:aaf22a04f350 | 6 | #define CALIBRATE 0 |
stupid | 0:aaf22a04f350 | 7 | #define FUNCTION_CHECK 0 |
stupid | 0:aaf22a04f350 | 8 | |
stupid | 1:ccb26dd9845a | 9 | // debounce duration for ON/OFF switch |
stupid | 1:ccb26dd9845a | 10 | #define ON_OFF_DEBOUNCE 3000 |
stupid | 1:ccb26dd9845a | 11 | |
stupid | 0:aaf22a04f350 | 12 | // longest user command we will accept |
stupid | 0:aaf22a04f350 | 13 | #define MAX_COMMAND_LEN 64 |
stupid | 0:aaf22a04f350 | 14 | |
stupid | 0:aaf22a04f350 | 15 | // where to start reading stored values from the EEPROM |
stupid | 0:aaf22a04f350 | 16 | #define BASE_ADDRESS 1 |
stupid | 0:aaf22a04f350 | 17 | |
stupid | 1:ccb26dd9845a | 18 | // temperature control stuff // |
stupid | 0:aaf22a04f350 | 19 | // fixed values |
stupid | 0:aaf22a04f350 | 20 | #define CONTROL_INTERRUPT 1000 // every 1ms |
stupid | 0:aaf22a04f350 | 21 | #define MAX_DUTY 100 // This is both the number of times the heater_control interrupt will run per control period and the max amount of interrupts the heater triac can be on. |
stupid | 0:aaf22a04f350 | 22 | |
stupid | 0:aaf22a04f350 | 23 | // adjustable values |
stupid | 0:aaf22a04f350 | 24 | #define DEFAULT_FILTER 0.05 // first order digital filter parameter, should be [0.0 - 1]. less means filter more, a value of 1 should turn it off |
stupid | 0:aaf22a04f350 | 25 | //#define INITIAL_DUTY 25 // 25% duty generally results in a few degrees under 57C output for the ambient temperatures I've been testing at |
stupid | 0:aaf22a04f350 | 26 | #define DEFAULT_INITIAL_DUTY 45 |
stupid | 1:ccb26dd9845a | 27 | #define DEFAULT_NOMINAL_DUTY 28 // 11% duty is a good set point for Beta init (testing at 20C ambient) |
stupid | 0:aaf22a04f350 | 28 | //#define SETPOINT 435 // this results in roughly 57C at the tines on the Alphas (really 53) |
stupid | 1:ccb26dd9845a | 29 | #define DEFAULT_SETPOINT 58 //seems like there is a ~4C temperature drop between the sensor and the outside of the tips |
stupid | 0:aaf22a04f350 | 30 | #define DEFAULT_TOLERANCE 2 // if we are within this many ADC counts of the setpoint don't make any changes to the duty cycle |
stupid | 0:aaf22a04f350 | 31 | //#define DUTY_TOO_LARGE 40 // If the duty gets larger than this we have problems (Alphas) |
stupid | 0:aaf22a04f350 | 32 | #define DEFAULT_DUTY_TOO_LARGE 70 // If the duty gets larger than this we have problems (Betas) -> 65 duty should result in roughly 62C tip temps |
stupid | 0:aaf22a04f350 | 33 | //#define DUTY_TOO_LARGE 85 // For testing |
stupid | 1:ccb26dd9845a | 34 | #define DEFAULT_TEMP_LIMIT_LOWER 12 // If the temperature measures too low during operation we are either doing a bad job or have a faulty temperature sensor |
stupid | 1:ccb26dd9845a | 35 | //#define DEFAULT_TEMP_LIMIT_LOWER 0 // For testing |
stupid | 0:aaf22a04f350 | 36 | //#define TEMP_LIMIT_UPPER 485 // No burning allowed (Alphas) |
stupid | 1:ccb26dd9845a | 37 | #define DEFAULT_TEMP_LIMIT_UPPER 65 // No burning allowed (Betas) |
stupid | 0:aaf22a04f350 | 38 | |
stupid | 0:aaf22a04f350 | 39 | float filter = DEFAULT_FILTER; |
stupid | 0:aaf22a04f350 | 40 | uint8_t initial_duty = DEFAULT_INITIAL_DUTY; |
stupid | 0:aaf22a04f350 | 41 | uint8_t nominal_duty = DEFAULT_NOMINAL_DUTY; |
stupid | 0:aaf22a04f350 | 42 | uint16_t setpoint = DEFAULT_SETPOINT; |
stupid | 0:aaf22a04f350 | 43 | uint8_t tolerance = DEFAULT_TOLERANCE; |
stupid | 0:aaf22a04f350 | 44 | uint8_t duty_too_large = DEFAULT_DUTY_TOO_LARGE; |
stupid | 0:aaf22a04f350 | 45 | uint16_t temp_limit_lower = DEFAULT_TEMP_LIMIT_LOWER; |
stupid | 0:aaf22a04f350 | 46 | uint16_t temp_limit_upper = DEFAULT_TEMP_LIMIT_UPPER; |
stupid | 0:aaf22a04f350 | 47 | |
stupid | 0:aaf22a04f350 | 48 | enum State { |
stupid | 0:aaf22a04f350 | 49 | IDLE, |
stupid | 0:aaf22a04f350 | 50 | WAIT_FOR_TIP, |
stupid | 0:aaf22a04f350 | 51 | INITIAL_RAMP, |
stupid | 0:aaf22a04f350 | 52 | ACTIVE, |
stupid | 1:ccb26dd9845a | 53 | DONE, |
stupid | 0:aaf22a04f350 | 54 | ERROR, |
stupid | 0:aaf22a04f350 | 55 | }; |
stupid | 0:aaf22a04f350 | 56 | |
stupid | 0:aaf22a04f350 | 57 | enum Heater_State { |
stupid | 0:aaf22a04f350 | 58 | ON, |
stupid | 0:aaf22a04f350 | 59 | OFF, |
stupid | 0:aaf22a04f350 | 60 | }; |
stupid | 0:aaf22a04f350 | 61 | |
stupid | 0:aaf22a04f350 | 62 | // not used yet |
stupid | 0:aaf22a04f350 | 63 | enum Error { |
stupid | 0:aaf22a04f350 | 64 | NONE, |
stupid | 0:aaf22a04f350 | 65 | TEMP_TOO_LOW, |
stupid | 0:aaf22a04f350 | 66 | TEMP_TOO_HIGH, |
stupid | 0:aaf22a04f350 | 67 | DUTY_TOO_LARGE, |
stupid | 0:aaf22a04f350 | 68 | }; |
stupid | 0:aaf22a04f350 | 69 | |
stupid | 0:aaf22a04f350 | 70 | // Heater control pins |
stupid | 0:aaf22a04f350 | 71 | DigitalOut fan(P0_22); |
stupid | 0:aaf22a04f350 | 72 | DigitalOut heater_pin(P1_27); |
stupid | 0:aaf22a04f350 | 73 | AnalogIn temp_sense(P0_16); |
stupid | 0:aaf22a04f350 | 74 | |
stupid | 0:aaf22a04f350 | 75 | // LED pins |
stupid | 0:aaf22a04f350 | 76 | DigitalInOut empty_led(P0_10); |
stupid | 0:aaf22a04f350 | 77 | DigitalInOut fuel_gage_1(P0_9); |
stupid | 0:aaf22a04f350 | 78 | DigitalInOut fuel_gage_2(P0_8); |
stupid | 0:aaf22a04f350 | 79 | DigitalInOut fuel_gage_3(P1_21); |
stupid | 0:aaf22a04f350 | 80 | DigitalInOut fuel_gage_4(P1_31); |
stupid | 0:aaf22a04f350 | 81 | DigitalOut tip_light(P1_14); |
stupid | 0:aaf22a04f350 | 82 | |
stupid | 1:ccb26dd9845a | 83 | // Other pins |
stupid | 0:aaf22a04f350 | 84 | DigitalIn tip_sensor(P0_14); |
stupid | 1:ccb26dd9845a | 85 | DigitalIn on_off(P1_28); |
stupid | 0:aaf22a04f350 | 86 | |
stupid | 0:aaf22a04f350 | 87 | #define ON_TIME_S 2700L // The device is active for 45 minutes |
stupid | 0:aaf22a04f350 | 88 | //#define ON_TIME_S 150L |
stupid | 0:aaf22a04f350 | 89 | #define RED_LED_ON_TIME_S 300L // The red LED is active for the last 5 minutes |
stupid | 0:aaf22a04f350 | 90 | //#define RED_LED_ON_TIME_S 30L |
stupid | 1:ccb26dd9845a | 91 | #define TIP_FLASH_INTERVAL_S 25L // How often the tip will flash |
stupid | 0:aaf22a04f350 | 92 | //Serial pc(0x1f00, 0x2012, 0x0001, false); |
stupid | 0:aaf22a04f350 | 93 | |
stupid | 0:aaf22a04f350 | 94 | #ifdef SERIAL |
stupid | 0:aaf22a04f350 | 95 | Serial pc(P0_19, P0_18); // tx, rx |
stupid | 0:aaf22a04f350 | 96 | #else |
stupid | 0:aaf22a04f350 | 97 | USBSerial pc(0x1f00, 0x2012, 0x0001); |
stupid | 0:aaf22a04f350 | 98 | #endif |
stupid | 0:aaf22a04f350 | 99 | |
stupid | 0:aaf22a04f350 | 100 | Ticker control_interrupt; |
stupid | 0:aaf22a04f350 | 101 | Ticker check_limits_interrupt; |
stupid | 0:aaf22a04f350 | 102 | Ticker temperature_interrupt; |
stupid | 0:aaf22a04f350 | 103 | Ticker tick_interrupt; |
stupid | 0:aaf22a04f350 | 104 | |
stupid | 0:aaf22a04f350 | 105 | volatile Heater_State heater = OFF; |
stupid | 1:ccb26dd9845a | 106 | volatile State state = IDLE; |
stupid | 0:aaf22a04f350 | 107 | volatile Error error_state = NONE; |
stupid | 0:aaf22a04f350 | 108 | |
stupid | 0:aaf22a04f350 | 109 | volatile uint8_t duty = DEFAULT_INITIAL_DUTY; |
stupid | 0:aaf22a04f350 | 110 | volatile float temperature = 0.0; |
stupid | 0:aaf22a04f350 | 111 | unsigned long start_time = 0L; |
stupid | 0:aaf22a04f350 | 112 | unsigned long current_time = 0L; |
stupid | 0:aaf22a04f350 | 113 | bool connected = false; |
stupid | 0:aaf22a04f350 | 114 | volatile uint32_t millis = 0; |
stupid | 0:aaf22a04f350 | 115 | |
stupid | 0:aaf22a04f350 | 116 | void loop(void); |
stupid | 0:aaf22a04f350 | 117 | void calibrate(bool first); |
stupid | 0:aaf22a04f350 | 118 | void interpret(char parameter, int value); |
stupid | 0:aaf22a04f350 | 119 | void spin_lights(bool first); |
stupid | 0:aaf22a04f350 | 120 | |
stupid | 1:ccb26dd9845a | 121 | //INTERRUPT - increment this every ms since the normal mbed timer returns an int and we need an unsigned type |
stupid | 0:aaf22a04f350 | 122 | void tick(void) {millis++;} |
stupid | 0:aaf22a04f350 | 123 | |
stupid | 0:aaf22a04f350 | 124 | uint32_t get_time(void){ |
stupid | 0:aaf22a04f350 | 125 | uint32_t copy = 0; |
stupid | 0:aaf22a04f350 | 126 | __disable_irq(); |
stupid | 0:aaf22a04f350 | 127 | copy = millis; |
stupid | 0:aaf22a04f350 | 128 | __enable_irq(); |
stupid | 0:aaf22a04f350 | 129 | return copy; |
stupid | 0:aaf22a04f350 | 130 | } |
stupid | 0:aaf22a04f350 | 131 | |
stupid | 0:aaf22a04f350 | 132 | uint8_t get_duty(void){ |
stupid | 0:aaf22a04f350 | 133 | __disable_irq(); |
stupid | 0:aaf22a04f350 | 134 | uint8_t duty_copy = duty; |
stupid | 0:aaf22a04f350 | 135 | __enable_irq(); |
stupid | 0:aaf22a04f350 | 136 | return duty_copy; |
stupid | 0:aaf22a04f350 | 137 | } |
stupid | 0:aaf22a04f350 | 138 | |
stupid | 0:aaf22a04f350 | 139 | void set_duty(uint8_t new_duty){ |
stupid | 0:aaf22a04f350 | 140 | __disable_irq(); |
stupid | 0:aaf22a04f350 | 141 | duty = new_duty; |
stupid | 0:aaf22a04f350 | 142 | __enable_irq(); |
stupid | 0:aaf22a04f350 | 143 | } |
stupid | 0:aaf22a04f350 | 144 | |
stupid | 0:aaf22a04f350 | 145 | float get_temperature(void){ |
stupid | 0:aaf22a04f350 | 146 | __disable_irq(); |
stupid | 0:aaf22a04f350 | 147 | float temperature_copy = temperature; |
stupid | 0:aaf22a04f350 | 148 | __enable_irq(); |
stupid | 0:aaf22a04f350 | 149 | return temperature_copy; |
stupid | 0:aaf22a04f350 | 150 | } |
stupid | 0:aaf22a04f350 | 151 | |
stupid | 0:aaf22a04f350 | 152 | //pull the settings saved to flash into memory |
stupid | 0:aaf22a04f350 | 153 | void read_settings(void){ |
stupid | 0:aaf22a04f350 | 154 | uint8_t address = BASE_ADDRESS; |
stupid | 0:aaf22a04f350 | 155 | uint16_t filter_temp = 0; |
stupid | 0:aaf22a04f350 | 156 | |
stupid | 0:aaf22a04f350 | 157 | IAP iap; |
stupid | 0:aaf22a04f350 | 158 | |
stupid | 0:aaf22a04f350 | 159 | iap.read_eeprom((char*)address, (char*)&filter_temp, sizeof(filter_temp)); |
stupid | 0:aaf22a04f350 | 160 | address += sizeof(filter_temp); |
stupid | 0:aaf22a04f350 | 161 | filter = (float)filter_temp/100; |
stupid | 0:aaf22a04f350 | 162 | iap.read_eeprom((char*)address, (char*)&initial_duty, sizeof(initial_duty)); |
stupid | 0:aaf22a04f350 | 163 | address += sizeof(initial_duty); |
stupid | 0:aaf22a04f350 | 164 | iap.read_eeprom((char*)address, (char*)&setpoint, sizeof(setpoint)); |
stupid | 0:aaf22a04f350 | 165 | address += sizeof(setpoint); |
stupid | 0:aaf22a04f350 | 166 | iap.read_eeprom((char*)address, (char*)&tolerance, sizeof(tolerance)); |
stupid | 0:aaf22a04f350 | 167 | address += sizeof(tolerance); |
stupid | 0:aaf22a04f350 | 168 | iap.read_eeprom((char*)address, (char*)&duty_too_large, sizeof(duty_too_large)); |
stupid | 0:aaf22a04f350 | 169 | address += sizeof(duty_too_large); |
stupid | 0:aaf22a04f350 | 170 | iap.read_eeprom((char*)address, (char*)&temp_limit_lower, sizeof(temp_limit_lower)); |
stupid | 0:aaf22a04f350 | 171 | address += sizeof(temp_limit_lower); |
stupid | 0:aaf22a04f350 | 172 | iap.read_eeprom((char*)address, (char*)&temp_limit_upper, sizeof(temp_limit_upper)); |
stupid | 0:aaf22a04f350 | 173 | address += sizeof(temp_limit_upper); |
stupid | 0:aaf22a04f350 | 174 | iap.read_eeprom((char*)address, (char*)&nominal_duty, sizeof(nominal_duty)); |
stupid | 0:aaf22a04f350 | 175 | address += sizeof(nominal_duty); |
stupid | 0:aaf22a04f350 | 176 | } |
stupid | 0:aaf22a04f350 | 177 | |
stupid | 0:aaf22a04f350 | 178 | //write settings to persistent memory |
stupid | 0:aaf22a04f350 | 179 | void write_settings(void){ |
stupid | 0:aaf22a04f350 | 180 | IAP iap; |
stupid | 0:aaf22a04f350 | 181 | uint8_t address = 1; //BASE_ADDRESS; |
stupid | 0:aaf22a04f350 | 182 | uint16_t filter_temp = 0; |
stupid | 0:aaf22a04f350 | 183 | |
stupid | 0:aaf22a04f350 | 184 | filter_temp = (int)(filter*100); |
stupid | 0:aaf22a04f350 | 185 | |
stupid | 0:aaf22a04f350 | 186 | iap.write_eeprom((char*)&filter_temp, (char*)address, sizeof(filter_temp)); |
stupid | 0:aaf22a04f350 | 187 | address += sizeof(filter_temp); |
stupid | 0:aaf22a04f350 | 188 | iap.write_eeprom((char*)&initial_duty, (char*)address, sizeof(initial_duty)); |
stupid | 0:aaf22a04f350 | 189 | address += sizeof(initial_duty); |
stupid | 0:aaf22a04f350 | 190 | iap.write_eeprom((char*)&setpoint, (char*)address, sizeof(setpoint)); |
stupid | 0:aaf22a04f350 | 191 | address += sizeof(setpoint); |
stupid | 0:aaf22a04f350 | 192 | iap.write_eeprom((char*)&tolerance, (char*)address, sizeof(tolerance)); |
stupid | 0:aaf22a04f350 | 193 | address += sizeof(tolerance); |
stupid | 0:aaf22a04f350 | 194 | iap.write_eeprom((char*)&duty_too_large, (char*)address, sizeof(duty_too_large)); |
stupid | 0:aaf22a04f350 | 195 | address += sizeof(duty_too_large); |
stupid | 0:aaf22a04f350 | 196 | iap.write_eeprom((char*)&temp_limit_lower, (char*)address, sizeof(temp_limit_lower)); |
stupid | 0:aaf22a04f350 | 197 | address += sizeof(temp_limit_lower); |
stupid | 0:aaf22a04f350 | 198 | iap.write_eeprom((char*)&temp_limit_upper, (char*)address, sizeof(temp_limit_upper)); |
stupid | 0:aaf22a04f350 | 199 | address += sizeof(temp_limit_upper); |
stupid | 0:aaf22a04f350 | 200 | iap.write_eeprom((char*)&nominal_duty, (char*)address, sizeof(nominal_duty)); |
stupid | 0:aaf22a04f350 | 201 | address += sizeof(nominal_duty); |
stupid | 0:aaf22a04f350 | 202 | } |
stupid | 0:aaf22a04f350 | 203 | |
stupid | 0:aaf22a04f350 | 204 | //parse commands. commands take the form of a character followed by a number, delimited by "\r|\n|;" |
stupid | 0:aaf22a04f350 | 205 | void getInput(void){ |
stupid | 0:aaf22a04f350 | 206 | static int i = 0; |
stupid | 0:aaf22a04f350 | 207 | static char parameter = '_'; |
stupid | 0:aaf22a04f350 | 208 | static char buffer[MAX_COMMAND_LEN + 1]; |
stupid | 0:aaf22a04f350 | 209 | int value = 0; |
stupid | 0:aaf22a04f350 | 210 | //char *endp = NULL; |
stupid | 0:aaf22a04f350 | 211 | |
stupid | 0:aaf22a04f350 | 212 | if(!connected) return; |
stupid | 0:aaf22a04f350 | 213 | |
stupid | 0:aaf22a04f350 | 214 | // listen for commands coming in |
stupid | 0:aaf22a04f350 | 215 | #ifdef SERIAL |
stupid | 0:aaf22a04f350 | 216 | while (pc.readable()){ |
stupid | 0:aaf22a04f350 | 217 | char ch = pc.getc(); |
stupid | 0:aaf22a04f350 | 218 | #else |
stupid | 0:aaf22a04f350 | 219 | while (pc.available()){ |
stupid | 0:aaf22a04f350 | 220 | char ch = pc._getc(); |
stupid | 0:aaf22a04f350 | 221 | #endif |
stupid | 0:aaf22a04f350 | 222 | if((ch == '\r' || ch == ';' || ch == '\n') && parameter != '_'){ |
stupid | 0:aaf22a04f350 | 223 | if(i > 1){ |
stupid | 0:aaf22a04f350 | 224 | buffer[i-1] = 0; |
stupid | 0:aaf22a04f350 | 225 | value = atoi(buffer); |
stupid | 0:aaf22a04f350 | 226 | } |
stupid | 0:aaf22a04f350 | 227 | pc.printf("%c, %d", parameter, value); |
stupid | 0:aaf22a04f350 | 228 | //Serial.println("not _"); |
stupid | 0:aaf22a04f350 | 229 | interpret(parameter, value); |
stupid | 0:aaf22a04f350 | 230 | parameter = '_'; |
stupid | 0:aaf22a04f350 | 231 | buffer[0] = 0; |
stupid | 0:aaf22a04f350 | 232 | i=0; |
stupid | 0:aaf22a04f350 | 233 | break; |
stupid | 0:aaf22a04f350 | 234 | } |
stupid | 0:aaf22a04f350 | 235 | else{ |
stupid | 0:aaf22a04f350 | 236 | if(i==0) parameter = ch; |
stupid | 0:aaf22a04f350 | 237 | else buffer[i-1] = ch; |
stupid | 0:aaf22a04f350 | 238 | i++; |
stupid | 0:aaf22a04f350 | 239 | } |
stupid | 0:aaf22a04f350 | 240 | |
stupid | 0:aaf22a04f350 | 241 | if(ch == '_' || ch == '\r' || ch == ';' || ch == '\n'){ |
stupid | 0:aaf22a04f350 | 242 | parameter = '_'; |
stupid | 0:aaf22a04f350 | 243 | buffer[0] = 0; |
stupid | 0:aaf22a04f350 | 244 | i=0; |
stupid | 0:aaf22a04f350 | 245 | } |
stupid | 0:aaf22a04f350 | 246 | } |
stupid | 0:aaf22a04f350 | 247 | } |
stupid | 0:aaf22a04f350 | 248 | |
stupid | 0:aaf22a04f350 | 249 | //print usage info |
stupid | 0:aaf22a04f350 | 250 | void usage(void){ |
stupid | 0:aaf22a04f350 | 251 | if(!connected)return; |
stupid | 0:aaf22a04f350 | 252 | pc.printf("\r\nCommands are a character followed by a number.\r\n"); |
stupid | 0:aaf22a04f350 | 253 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 254 | pc.printf("Available commands are:\r\n"); |
stupid | 0:aaf22a04f350 | 255 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 256 | pc.printf("'c': duty cap [1-100]\r\n"); |
stupid | 0:aaf22a04f350 | 257 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 258 | pc.printf("'d': set the initial duty used on startup [1-100]\r\n"); |
stupid | 0:aaf22a04f350 | 259 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 260 | pc.printf("'f': set the smoothing filter for the temperature sensor."); |
stupid | 0:aaf22a04f350 | 261 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 262 | pc.printf(" smaller is more smoothing. [1-100]\r\n"); |
stupid | 0:aaf22a04f350 | 263 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 264 | pc.printf("'l': lower temperature limit. arbitrary units. [1-1000]\r\n"); |
stupid | 0:aaf22a04f350 | 265 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 266 | pc.printf("'r': reset all parameters to default values.\r\n"); |
stupid | 0:aaf22a04f350 | 267 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 268 | pc.printf("'n': set the nominal duty used on control cycle start [1-100]\r\n"); |
stupid | 0:aaf22a04f350 | 269 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 270 | pc.printf("'s': setpoint. same units as upper and lower temperature"); |
stupid | 0:aaf22a04f350 | 271 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 272 | pc.printf(" limit [1-1000]\r\n"); |
stupid | 0:aaf22a04f350 | 273 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 274 | pc.printf("'t': tolerance. no control action within this band. same "); |
stupid | 0:aaf22a04f350 | 275 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 276 | pc.printf("units as upper and lower temperature limit [1-1000]\r\n"); |
stupid | 0:aaf22a04f350 | 277 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 278 | pc.printf("'u': upper temperature limit. arbitrary units. [1-1000]\r\n"); |
stupid | 0:aaf22a04f350 | 279 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 280 | pc.printf("'w': write the current control parameters to permanent memory\r\n"); |
stupid | 0:aaf22a04f350 | 281 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 282 | pc.printf("\r\n\r\n"); |
stupid | 0:aaf22a04f350 | 283 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 284 | |
stupid | 0:aaf22a04f350 | 285 | pc.printf("Values can be modified by entering a "); |
stupid | 0:aaf22a04f350 | 286 | pc.printf("command followed by a number."); |
stupid | 0:aaf22a04f350 | 287 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 288 | pc.printf(" For example, entering 'c50' <enter> would limit the duty"); |
stupid | 0:aaf22a04f350 | 289 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 290 | pc.printf(" to 50%\r\n\r\n"); |
stupid | 0:aaf22a04f350 | 291 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 292 | |
stupid | 0:aaf22a04f350 | 293 | pc.printf("Status of individual variables can be queried by entering "); |
stupid | 0:aaf22a04f350 | 294 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 295 | pc.printf("that command name (no number afterwards), or typing any "); |
stupid | 0:aaf22a04f350 | 296 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 297 | pc.printf("unrecognised command (which prints this message).\r\n\r\n"); |
stupid | 0:aaf22a04f350 | 298 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 299 | } |
stupid | 0:aaf22a04f350 | 300 | |
stupid | 0:aaf22a04f350 | 301 | void print_active_settings(void){ |
stupid | 0:aaf22a04f350 | 302 | if(!connected)return; |
stupid | 0:aaf22a04f350 | 303 | pc.printf("Duty capped at: %u%\r\n", duty_too_large); |
stupid | 0:aaf22a04f350 | 304 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 305 | pc.printf("Initial duty is: %u\r\n", initial_duty); |
stupid | 0:aaf22a04f350 | 306 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 307 | pc.printf("Nominal duty is: %u\r\n", nominal_duty); |
stupid | 0:aaf22a04f350 | 308 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 309 | pc.printf("Temperature filter is: %d\r\n", (int)(filter * 100)); |
stupid | 0:aaf22a04f350 | 310 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 311 | pc.printf("Lower temperature limit is: %u\r\n", temp_limit_lower); |
stupid | 0:aaf22a04f350 | 312 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 313 | pc.printf("Upper temperature limit is: %u\r\n", temp_limit_upper); |
stupid | 0:aaf22a04f350 | 314 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 315 | pc.printf("Setpoint is: %u\r\n", setpoint); |
stupid | 0:aaf22a04f350 | 316 | wait_ms(1); |
stupid | 0:aaf22a04f350 | 317 | pc.printf("Tolerance is %u\r\n\r\n", tolerance); |
stupid | 0:aaf22a04f350 | 318 | wait_ms(1); |
stupid | 1:ccb26dd9845a | 319 | pc.printf("Spot treatment time is %l\r\n\r\n", TIP_FLASH_INTERVAL_S); |
stupid | 0:aaf22a04f350 | 320 | } |
stupid | 0:aaf22a04f350 | 321 | |
stupid | 0:aaf22a04f350 | 322 | //interpret a user command |
stupid | 0:aaf22a04f350 | 323 | void interpret(char parameter, int value){ |
stupid | 0:aaf22a04f350 | 324 | switch(parameter){ |
stupid | 0:aaf22a04f350 | 325 | case 'c': |
stupid | 0:aaf22a04f350 | 326 | if(value != 0) duty_too_large = value; |
stupid | 0:aaf22a04f350 | 327 | pc.printf("Duty cap is %u\r\n", duty_too_large); |
stupid | 0:aaf22a04f350 | 328 | break; |
stupid | 0:aaf22a04f350 | 329 | case 'd': |
stupid | 0:aaf22a04f350 | 330 | if(value != 0) initial_duty = value; |
stupid | 0:aaf22a04f350 | 331 | pc.printf("Initial duty is %u\r\n", initial_duty); |
stupid | 0:aaf22a04f350 | 332 | break; |
stupid | 0:aaf22a04f350 | 333 | case 'f': |
stupid | 0:aaf22a04f350 | 334 | if(value != 0) filter = ((float)value) / 100.0; |
stupid | 0:aaf22a04f350 | 335 | pc.printf("Filter is %d\r\n", (int)(filter * 100)); |
stupid | 0:aaf22a04f350 | 336 | break; |
stupid | 0:aaf22a04f350 | 337 | case 'r': |
stupid | 0:aaf22a04f350 | 338 | filter = DEFAULT_FILTER; |
stupid | 0:aaf22a04f350 | 339 | initial_duty = DEFAULT_INITIAL_DUTY; |
stupid | 0:aaf22a04f350 | 340 | nominal_duty = DEFAULT_NOMINAL_DUTY; |
stupid | 0:aaf22a04f350 | 341 | setpoint = DEFAULT_SETPOINT; |
stupid | 0:aaf22a04f350 | 342 | tolerance = DEFAULT_TOLERANCE; |
stupid | 0:aaf22a04f350 | 343 | duty_too_large = DEFAULT_DUTY_TOO_LARGE; |
stupid | 0:aaf22a04f350 | 344 | temp_limit_lower = DEFAULT_TEMP_LIMIT_LOWER; |
stupid | 0:aaf22a04f350 | 345 | temp_limit_upper = DEFAULT_TEMP_LIMIT_UPPER; |
stupid | 0:aaf22a04f350 | 346 | write_settings(); |
stupid | 0:aaf22a04f350 | 347 | pc.printf("All parameters reset to default values:\r\n"); |
stupid | 0:aaf22a04f350 | 348 | print_active_settings(); |
stupid | 0:aaf22a04f350 | 349 | break; |
stupid | 0:aaf22a04f350 | 350 | case 'l': |
stupid | 0:aaf22a04f350 | 351 | if(value != 0) temp_limit_lower = value; |
stupid | 0:aaf22a04f350 | 352 | pc.printf("Lower temperature limit is %u\r\n", temp_limit_lower); |
stupid | 0:aaf22a04f350 | 353 | break; |
stupid | 0:aaf22a04f350 | 354 | case 'n': |
stupid | 0:aaf22a04f350 | 355 | if(value != 0) nominal_duty = value; |
stupid | 0:aaf22a04f350 | 356 | pc.printf("Nominal duty is %u\r\n", nominal_duty); |
stupid | 0:aaf22a04f350 | 357 | break; |
stupid | 0:aaf22a04f350 | 358 | case 's': |
stupid | 0:aaf22a04f350 | 359 | if(value != 0) setpoint = value; |
stupid | 0:aaf22a04f350 | 360 | pc.printf("Setpoint is %u\r\n", setpoint); |
stupid | 0:aaf22a04f350 | 361 | break; |
stupid | 0:aaf22a04f350 | 362 | case 't': |
stupid | 0:aaf22a04f350 | 363 | if(value != 0) tolerance = value; |
stupid | 0:aaf22a04f350 | 364 | pc.printf("Tolerance is %u\r\n", tolerance); |
stupid | 0:aaf22a04f350 | 365 | break; |
stupid | 0:aaf22a04f350 | 366 | case 'u': |
stupid | 0:aaf22a04f350 | 367 | if(value != 0) temp_limit_upper = value; |
stupid | 0:aaf22a04f350 | 368 | pc.printf("Upper temperature limit is %u\r\n", temp_limit_upper); |
stupid | 0:aaf22a04f350 | 369 | break; |
stupid | 0:aaf22a04f350 | 370 | case 'w': |
stupid | 0:aaf22a04f350 | 371 | write_settings(); |
stupid | 0:aaf22a04f350 | 372 | pc.printf("Wrote the current control parameters to memory.\r\n"); |
stupid | 0:aaf22a04f350 | 373 | break; |
stupid | 0:aaf22a04f350 | 374 | |
stupid | 0:aaf22a04f350 | 375 | |
stupid | 0:aaf22a04f350 | 376 | default: |
stupid | 0:aaf22a04f350 | 377 | usage(); |
stupid | 0:aaf22a04f350 | 378 | print_active_settings(); |
stupid | 0:aaf22a04f350 | 379 | break; |
stupid | 0:aaf22a04f350 | 380 | } |
stupid | 0:aaf22a04f350 | 381 | } |
stupid | 0:aaf22a04f350 | 382 | |
stupid | 0:aaf22a04f350 | 383 | //put everything into a low power/off state. control loop will be unaffected by this command, so that will also need to be disabled before the heater will stay off |
stupid | 0:aaf22a04f350 | 384 | void all_off(){ |
stupid | 0:aaf22a04f350 | 385 | heater_pin = 0; |
stupid | 0:aaf22a04f350 | 386 | heater = OFF; //need to treat this as volatile |
stupid | 0:aaf22a04f350 | 387 | fan = 0; |
stupid | 0:aaf22a04f350 | 388 | empty_led.input(); // |
stupid | 0:aaf22a04f350 | 389 | fuel_gage_1.input(); // = 1; |
stupid | 0:aaf22a04f350 | 390 | fuel_gage_2.input(); // = 1; |
stupid | 0:aaf22a04f350 | 391 | fuel_gage_3.input(); // = 1; |
stupid | 0:aaf22a04f350 | 392 | fuel_gage_4.input(); // = 1; |
stupid | 0:aaf22a04f350 | 393 | tip_light = 0; |
stupid | 0:aaf22a04f350 | 394 | } |
stupid | 0:aaf22a04f350 | 395 | |
stupid | 0:aaf22a04f350 | 396 | // run this to manually check the hardware works |
stupid | 0:aaf22a04f350 | 397 | // probably best to disable the heater on the first try |
stupid | 0:aaf22a04f350 | 398 | void functional_check(void){ |
stupid | 1:ccb26dd9845a | 399 | all_off(); |
stupid | 0:aaf22a04f350 | 400 | if(connected)pc.printf("Tip light\r\n"); |
stupid | 0:aaf22a04f350 | 401 | tip_light = 1; |
stupid | 0:aaf22a04f350 | 402 | wait_ms(1000); |
stupid | 0:aaf22a04f350 | 403 | all_off(); |
stupid | 0:aaf22a04f350 | 404 | if(connected)pc.printf("Empty\r\n"); |
stupid | 0:aaf22a04f350 | 405 | empty_led.output(); |
stupid | 0:aaf22a04f350 | 406 | empty_led = 0; |
stupid | 0:aaf22a04f350 | 407 | wait_ms(1000); |
stupid | 0:aaf22a04f350 | 408 | all_off(); |
stupid | 0:aaf22a04f350 | 409 | if(connected)pc.printf("Fuel Gage 1\r\n"); |
stupid | 0:aaf22a04f350 | 410 | fuel_gage_1.output(); |
stupid | 0:aaf22a04f350 | 411 | fuel_gage_1 = 0; |
stupid | 0:aaf22a04f350 | 412 | wait_ms(1000); |
stupid | 0:aaf22a04f350 | 413 | all_off(); |
stupid | 0:aaf22a04f350 | 414 | if(connected)pc.printf("Fuel Gage 2\r\n"); |
stupid | 0:aaf22a04f350 | 415 | fuel_gage_2.output(); |
stupid | 0:aaf22a04f350 | 416 | fuel_gage_2 = 0; |
stupid | 0:aaf22a04f350 | 417 | wait_ms(1000); |
stupid | 0:aaf22a04f350 | 418 | all_off(); |
stupid | 0:aaf22a04f350 | 419 | if(connected)pc.printf("Fuel Gage 3\r\n"); |
stupid | 0:aaf22a04f350 | 420 | fuel_gage_3.output(); |
stupid | 0:aaf22a04f350 | 421 | fuel_gage_3 = 0; |
stupid | 0:aaf22a04f350 | 422 | wait_ms(1000); |
stupid | 0:aaf22a04f350 | 423 | all_off(); |
stupid | 0:aaf22a04f350 | 424 | if(connected)pc.printf("Fuel Gage 4\r\n"); |
stupid | 0:aaf22a04f350 | 425 | fuel_gage_4.output(); |
stupid | 0:aaf22a04f350 | 426 | fuel_gage_4 = 0; |
stupid | 0:aaf22a04f350 | 427 | wait_ms(1000); |
stupid | 0:aaf22a04f350 | 428 | all_off(); |
stupid | 0:aaf22a04f350 | 429 | if(connected)pc.printf("Fan\r\n"); |
stupid | 0:aaf22a04f350 | 430 | fan = 1; |
stupid | 0:aaf22a04f350 | 431 | wait_ms(5000); |
stupid | 0:aaf22a04f350 | 432 | if(connected)pc.printf("Heater\r\n"); |
stupid | 0:aaf22a04f350 | 433 | heater_pin = 1; |
stupid | 0:aaf22a04f350 | 434 | |
stupid | 0:aaf22a04f350 | 435 | while(1){ |
stupid | 0:aaf22a04f350 | 436 | if(connected)pc.printf("Temp: %u\r\n", temp_sense.read_u16()>>6); |
stupid | 0:aaf22a04f350 | 437 | wait_ms(50); |
stupid | 0:aaf22a04f350 | 438 | tip_light = 1; |
stupid | 0:aaf22a04f350 | 439 | wait_ms(50); |
stupid | 0:aaf22a04f350 | 440 | tip_light = 0; |
stupid | 0:aaf22a04f350 | 441 | } |
stupid | 0:aaf22a04f350 | 442 | } |
stupid | 0:aaf22a04f350 | 443 | |
stupid | 0:aaf22a04f350 | 444 | // INTERRUPT - called every 4ms, samples the ADC and filters the value with a low pass first order digital filter |
stupid | 0:aaf22a04f350 | 445 | void get_temp(void){ |
stupid | 0:aaf22a04f350 | 446 | // not bothering with units, this means we need to keep the update constant at once every 4ms or we will need to set the filter again |
stupid | 0:aaf22a04f350 | 447 | //temperature = filter * (temp_sense.read_u16()>>6) + (1 - filter) * temperature; |
stupid | 0:aaf22a04f350 | 448 | // temperature is now in degrees C (value is at sensor, not at tips) |
stupid | 0:aaf22a04f350 | 449 | temperature = filter * (51.282 * (temp_sense.read()*3.3 - 0.4)) + (1 - filter) * temperature; |
stupid | 0:aaf22a04f350 | 450 | } |
stupid | 0:aaf22a04f350 | 451 | |
stupid | 0:aaf22a04f350 | 452 | // INTERRUPT - called every millisecond to handle maintaining the on/off state of the triac |
stupid | 0:aaf22a04f350 | 453 | void heater_control(void){ |
stupid | 0:aaf22a04f350 | 454 | static uint8_t count = 0; |
stupid | 0:aaf22a04f350 | 455 | |
stupid | 0:aaf22a04f350 | 456 | // count up once per interrupt. |
stupid | 0:aaf22a04f350 | 457 | // safety: check to make sure we haven't exceeded MAX_DUTY safety limit |
stupid | 0:aaf22a04f350 | 458 | // after duty is reached for this control period, turn the heat off |
stupid | 0:aaf22a04f350 | 459 | count++; |
stupid | 0:aaf22a04f350 | 460 | |
stupid | 0:aaf22a04f350 | 461 | if(heater == ON && fan.read()){ |
stupid | 0:aaf22a04f350 | 462 | if(count > MAX_DUTY){ |
stupid | 0:aaf22a04f350 | 463 | count = 0; |
stupid | 0:aaf22a04f350 | 464 | heater_pin = 1; |
stupid | 0:aaf22a04f350 | 465 | } |
stupid | 0:aaf22a04f350 | 466 | if(count > duty)heater_pin = 0; |
stupid | 0:aaf22a04f350 | 467 | } |
stupid | 0:aaf22a04f350 | 468 | else heater_pin = 0; |
stupid | 0:aaf22a04f350 | 469 | } |
stupid | 0:aaf22a04f350 | 470 | |
stupid | 0:aaf22a04f350 | 471 | // bail, something is wrong |
stupid | 0:aaf22a04f350 | 472 | void abort(bool error){ |
stupid | 0:aaf22a04f350 | 473 | uint16_t period = 1000; |
stupid | 0:aaf22a04f350 | 474 | if(error) period = 250; |
stupid | 0:aaf22a04f350 | 475 | // turn everything off, leave the fan on for a few seconds and flash the red LED |
stupid | 0:aaf22a04f350 | 476 | control_interrupt.detach(); |
stupid | 0:aaf22a04f350 | 477 | all_off(); |
stupid | 0:aaf22a04f350 | 478 | empty_led.input(); |
stupid | 0:aaf22a04f350 | 479 | fan = 1; |
stupid | 0:aaf22a04f350 | 480 | wait_ms(3000); |
stupid | 0:aaf22a04f350 | 481 | fan = 0; |
stupid | 0:aaf22a04f350 | 482 | while(1){ |
stupid | 0:aaf22a04f350 | 483 | empty_led.output(); |
stupid | 0:aaf22a04f350 | 484 | empty_led = 0; |
stupid | 0:aaf22a04f350 | 485 | heater_pin = 0; |
stupid | 0:aaf22a04f350 | 486 | wait_ms(period); |
stupid | 0:aaf22a04f350 | 487 | heater_pin = 0; |
stupid | 0:aaf22a04f350 | 488 | empty_led.input(); |
stupid | 0:aaf22a04f350 | 489 | heater_pin = 0; |
stupid | 0:aaf22a04f350 | 490 | wait_ms(period); |
stupid | 0:aaf22a04f350 | 491 | } |
stupid | 0:aaf22a04f350 | 492 | } |
stupid | 0:aaf22a04f350 | 493 | |
stupid | 0:aaf22a04f350 | 494 | // INTERRUPT - monitor stuff that might indicate an error condition |
stupid | 0:aaf22a04f350 | 495 | void check_limits(void){ |
stupid | 0:aaf22a04f350 | 496 | // need to move printing to the main loop |
stupid | 0:aaf22a04f350 | 497 | if(duty >= duty_too_large){ |
stupid | 0:aaf22a04f350 | 498 | if(connected){ |
stupid | 0:aaf22a04f350 | 499 | pc.printf("Error!!! Duty cycle has become unreasonably "); |
stupid | 0:aaf22a04f350 | 500 | pc.printf("large, Aborting.\r\n"); |
stupid | 0:aaf22a04f350 | 501 | } |
stupid | 0:aaf22a04f350 | 502 | abort(true); |
stupid | 0:aaf22a04f350 | 503 | } |
stupid | 0:aaf22a04f350 | 504 | |
stupid | 0:aaf22a04f350 | 505 | if(get_temperature() > temp_limit_upper){ |
stupid | 0:aaf22a04f350 | 506 | if(connected)pc.printf("Error!!! Temperature is too high, Aborting.\r\n"); |
stupid | 0:aaf22a04f350 | 507 | abort(true); |
stupid | 0:aaf22a04f350 | 508 | } |
stupid | 0:aaf22a04f350 | 509 | |
stupid | 0:aaf22a04f350 | 510 | if((state == ACTIVE || state == INITIAL_RAMP) && (get_temperature() < temp_limit_lower)){ |
stupid | 0:aaf22a04f350 | 511 | if(connected){ |
stupid | 0:aaf22a04f350 | 512 | pc.printf("%f\r\n", get_temperature()); |
stupid | 0:aaf22a04f350 | 513 | pc.printf("Error!!! Abnormally low temperature detected. "); |
stupid | 0:aaf22a04f350 | 514 | pc.printf("Please check the sensor, Aborting.\r\n"); |
stupid | 0:aaf22a04f350 | 515 | } |
stupid | 0:aaf22a04f350 | 516 | abort(true); |
stupid | 0:aaf22a04f350 | 517 | } |
stupid | 0:aaf22a04f350 | 518 | } |
stupid | 0:aaf22a04f350 | 519 | |
stupid | 0:aaf22a04f350 | 520 | // values pulled from the MCP9701T-E/LT datasheet |
stupid | 0:aaf22a04f350 | 521 | // 19.5mV/deg-C, 400mV @ 0C |
stupid | 0:aaf22a04f350 | 522 | float adc_to_temp(float adc_value){ |
stupid | 0:aaf22a04f350 | 523 | //return 0.195 * adc_value - |
stupid | 0:aaf22a04f350 | 524 | return 0.196 * adc_value - 31.322; |
stupid | 0:aaf22a04f350 | 525 | } |
stupid | 0:aaf22a04f350 | 526 | |
stupid | 0:aaf22a04f350 | 527 | void init(void){ |
stupid | 0:aaf22a04f350 | 528 | #ifdef SERIAL |
stupid | 0:aaf22a04f350 | 529 | pc.baud(115200); |
stupid | 0:aaf22a04f350 | 530 | connected = true; |
stupid | 0:aaf22a04f350 | 531 | #else |
stupid | 0:aaf22a04f350 | 532 | pc.connect(); |
stupid | 0:aaf22a04f350 | 533 | connected = pc.vbusDetected(); |
stupid | 0:aaf22a04f350 | 534 | #endif |
stupid | 0:aaf22a04f350 | 535 | |
stupid | 0:aaf22a04f350 | 536 | if(connected)pc.printf("hello\r\n"); |
stupid | 0:aaf22a04f350 | 537 | |
stupid | 0:aaf22a04f350 | 538 | tick_interrupt.attach(&tick, 0.001); |
stupid | 0:aaf22a04f350 | 539 | control_interrupt.attach(&heater_control, 0.001); |
stupid | 0:aaf22a04f350 | 540 | temperature_interrupt.attach(&get_temp, 0.004); |
stupid | 0:aaf22a04f350 | 541 | if(!CALIBRATE)check_limits_interrupt.attach(&check_limits, 0.5); |
stupid | 0:aaf22a04f350 | 542 | |
stupid | 0:aaf22a04f350 | 543 | read_settings(); |
stupid | 0:aaf22a04f350 | 544 | set_duty(initial_duty); |
stupid | 0:aaf22a04f350 | 545 | all_off(); |
stupid | 0:aaf22a04f350 | 546 | } |
stupid | 0:aaf22a04f350 | 547 | |
stupid | 1:ccb26dd9845a | 548 | void check_on_off(void){ |
stupid | 1:ccb26dd9845a | 549 | static uint32_t count = 0; |
stupid | 1:ccb26dd9845a | 550 | |
stupid | 1:ccb26dd9845a | 551 | // debounce |
stupid | 1:ccb26dd9845a | 552 | if(on_off){ |
stupid | 1:ccb26dd9845a | 553 | count++; |
stupid | 1:ccb26dd9845a | 554 | if(count > ON_OFF_DEBOUNCE){ |
stupid | 1:ccb26dd9845a | 555 | all_off(); |
stupid | 1:ccb26dd9845a | 556 | state = IDLE; |
stupid | 1:ccb26dd9845a | 557 | } |
stupid | 1:ccb26dd9845a | 558 | } |
stupid | 1:ccb26dd9845a | 559 | else count = 0; |
stupid | 1:ccb26dd9845a | 560 | } |
stupid | 1:ccb26dd9845a | 561 | |
stupid | 1:ccb26dd9845a | 562 | void do_idle(bool first){ |
stupid | 1:ccb26dd9845a | 563 | if(!on_off) state = WAIT_FOR_TIP; |
stupid | 1:ccb26dd9845a | 564 | } |
stupid | 1:ccb26dd9845a | 565 | |
stupid | 0:aaf22a04f350 | 566 | // tip neeeds to be present before we can start the cycle |
stupid | 1:ccb26dd9845a | 567 | // later we should also abort the cycle if the tip is removed |
stupid | 0:aaf22a04f350 | 568 | void do_wait_for_tip(bool first){ |
stupid | 0:aaf22a04f350 | 569 | unsigned long time = get_time(); |
stupid | 0:aaf22a04f350 | 570 | unsigned long time_increment = time % 1800; |
stupid | 0:aaf22a04f350 | 571 | |
stupid | 0:aaf22a04f350 | 572 | if(first){ |
stupid | 0:aaf22a04f350 | 573 | if(connected)pc.printf("Looking for tip\r\n"); |
stupid | 0:aaf22a04f350 | 574 | } |
stupid | 0:aaf22a04f350 | 575 | if(!tip_sensor){ //tip present is low == present |
stupid | 0:aaf22a04f350 | 576 | tip_light = 1; |
stupid | 0:aaf22a04f350 | 577 | fuel_gage_1.output(); |
stupid | 0:aaf22a04f350 | 578 | fuel_gage_1 = 0; |
stupid | 0:aaf22a04f350 | 579 | fuel_gage_2.output(); |
stupid | 0:aaf22a04f350 | 580 | fuel_gage_2 = 0; |
stupid | 0:aaf22a04f350 | 581 | fuel_gage_3.output(); |
stupid | 0:aaf22a04f350 | 582 | fuel_gage_3 = 0; |
stupid | 0:aaf22a04f350 | 583 | fuel_gage_4.output(); |
stupid | 0:aaf22a04f350 | 584 | fuel_gage_4 = 0; |
stupid | 0:aaf22a04f350 | 585 | empty_led.input(); |
stupid | 0:aaf22a04f350 | 586 | state = INITIAL_RAMP; |
stupid | 0:aaf22a04f350 | 587 | if(connected)pc.printf("Found the tip\r\n"); |
stupid | 0:aaf22a04f350 | 588 | return; |
stupid | 0:aaf22a04f350 | 589 | } |
stupid | 0:aaf22a04f350 | 590 | |
stupid | 0:aaf22a04f350 | 591 | if(time_increment < 300){ |
stupid | 0:aaf22a04f350 | 592 | fuel_gage_1.input(); // = 1; |
stupid | 0:aaf22a04f350 | 593 | fuel_gage_2.input(); // = 1; |
stupid | 0:aaf22a04f350 | 594 | fuel_gage_3.input(); // = 1; |
stupid | 0:aaf22a04f350 | 595 | fuel_gage_4.input(); // = 1; |
stupid | 0:aaf22a04f350 | 596 | } |
stupid | 0:aaf22a04f350 | 597 | if(time_increment > 600){ |
stupid | 0:aaf22a04f350 | 598 | fuel_gage_1.output(); |
stupid | 0:aaf22a04f350 | 599 | fuel_gage_1 = 0; |
stupid | 0:aaf22a04f350 | 600 | } |
stupid | 0:aaf22a04f350 | 601 | if(time_increment > 900){ |
stupid | 0:aaf22a04f350 | 602 | fuel_gage_2.output(); |
stupid | 0:aaf22a04f350 | 603 | fuel_gage_2 = 0; |
stupid | 0:aaf22a04f350 | 604 | } |
stupid | 0:aaf22a04f350 | 605 | if(time_increment > 1200){ |
stupid | 0:aaf22a04f350 | 606 | fuel_gage_3.output(); |
stupid | 0:aaf22a04f350 | 607 | fuel_gage_3 = 0; |
stupid | 0:aaf22a04f350 | 608 | } |
stupid | 0:aaf22a04f350 | 609 | if(time_increment > 1500){ |
stupid | 0:aaf22a04f350 | 610 | fuel_gage_4.output(); |
stupid | 0:aaf22a04f350 | 611 | fuel_gage_4 = 0; |
stupid | 0:aaf22a04f350 | 612 | } |
stupid | 0:aaf22a04f350 | 613 | } |
stupid | 0:aaf22a04f350 | 614 | |
stupid | 0:aaf22a04f350 | 615 | //This should quickly take us up from ambient to the setpoint. |
stupid | 0:aaf22a04f350 | 616 | void do_initial_ramp(bool first){ |
stupid | 0:aaf22a04f350 | 617 | // set duty to initial_duty and wait to reach the setpoint to break out |
stupid | 0:aaf22a04f350 | 618 | static uint32_t start_time = 0; |
stupid | 0:aaf22a04f350 | 619 | static uint32_t last_print = get_time(); |
stupid | 0:aaf22a04f350 | 620 | |
stupid | 0:aaf22a04f350 | 621 | if(first){ |
stupid | 1:ccb26dd9845a | 622 | print_active_settings(); |
stupid | 0:aaf22a04f350 | 623 | start_time = get_time(); |
stupid | 0:aaf22a04f350 | 624 | fan = 1; |
stupid | 0:aaf22a04f350 | 625 | set_duty(initial_duty); |
stupid | 0:aaf22a04f350 | 626 | heater = ON; |
stupid | 0:aaf22a04f350 | 627 | if(connected)pc.printf("Initial ramp up. Duty will be held constant until setpoint is reached.\r\n"); |
stupid | 0:aaf22a04f350 | 628 | } |
stupid | 0:aaf22a04f350 | 629 | |
stupid | 0:aaf22a04f350 | 630 | if(get_time() - start_time > 60000){ |
stupid | 0:aaf22a04f350 | 631 | if(connected)pc.printf("Took too long to reach setpoint, aborting.\r\n"); |
stupid | 0:aaf22a04f350 | 632 | abort(true); |
stupid | 0:aaf22a04f350 | 633 | } |
stupid | 0:aaf22a04f350 | 634 | |
stupid | 0:aaf22a04f350 | 635 | if(get_time() - last_print > 5000){ |
stupid | 1:ccb26dd9845a | 636 | if(connected)pc.printf("Duty: %u, Temp: %.2f, Time: %.2fs\r\n", get_duty(), get_temperature(), (float)get_time()/1000); |
stupid | 0:aaf22a04f350 | 637 | last_print = get_time(); |
stupid | 0:aaf22a04f350 | 638 | } |
stupid | 0:aaf22a04f350 | 639 | |
stupid | 0:aaf22a04f350 | 640 | if(get_temperature() > setpoint - tolerance){ |
stupid | 0:aaf22a04f350 | 641 | //now we are roughly up to temperature |
stupid | 0:aaf22a04f350 | 642 | set_duty(nominal_duty); |
stupid | 0:aaf22a04f350 | 643 | state = ACTIVE; |
stupid | 0:aaf22a04f350 | 644 | return; |
stupid | 0:aaf22a04f350 | 645 | } |
stupid | 0:aaf22a04f350 | 646 | } |
stupid | 0:aaf22a04f350 | 647 | |
stupid | 0:aaf22a04f350 | 648 | void do_treatment_cycle(bool first){ |
stupid | 0:aaf22a04f350 | 649 | static uint32_t start_time = 0; |
stupid | 0:aaf22a04f350 | 650 | static uint32_t control_timer = 0; |
stupid | 0:aaf22a04f350 | 651 | uint8_t duty_copy; |
stupid | 0:aaf22a04f350 | 652 | float temperature_copy; |
stupid | 0:aaf22a04f350 | 653 | |
stupid | 0:aaf22a04f350 | 654 | if(first){ |
stupid | 0:aaf22a04f350 | 655 | start_time = get_time(); |
stupid | 0:aaf22a04f350 | 656 | control_timer = start_time; |
stupid | 0:aaf22a04f350 | 657 | } |
stupid | 0:aaf22a04f350 | 658 | |
stupid | 0:aaf22a04f350 | 659 | uint32_t current_time = get_time() - start_time; |
stupid | 0:aaf22a04f350 | 660 | |
stupid | 0:aaf22a04f350 | 661 | // check if we're done |
stupid | 0:aaf22a04f350 | 662 | if(current_time >= ON_TIME_S * 1000L){ |
stupid | 0:aaf22a04f350 | 663 | if(connected)pc.printf("Done!\r\n"); |
stupid | 1:ccb26dd9845a | 664 | //abort(false); |
stupid | 1:ccb26dd9845a | 665 | set_duty(0); |
stupid | 1:ccb26dd9845a | 666 | fan = 0; |
stupid | 1:ccb26dd9845a | 667 | state = DONE; |
stupid | 0:aaf22a04f350 | 668 | } |
stupid | 0:aaf22a04f350 | 669 | |
stupid | 0:aaf22a04f350 | 670 | //if(!tip->in_place())abort(false); |
stupid | 0:aaf22a04f350 | 671 | |
stupid | 0:aaf22a04f350 | 672 | if(current_time - control_timer > 5000){ // run the control loop every 5 seconds |
stupid | 0:aaf22a04f350 | 673 | control_timer = current_time; |
stupid | 0:aaf22a04f350 | 674 | duty_copy = get_duty(); |
stupid | 0:aaf22a04f350 | 675 | temperature_copy = get_temperature(); |
stupid | 0:aaf22a04f350 | 676 | if(temperature_copy > setpoint + tolerance) duty_copy--; |
stupid | 0:aaf22a04f350 | 677 | if(temperature_copy < setpoint - tolerance) duty_copy++; |
stupid | 0:aaf22a04f350 | 678 | set_duty(duty_copy); |
stupid | 0:aaf22a04f350 | 679 | |
stupid | 1:ccb26dd9845a | 680 | if(connected)pc.printf("Duty: %u, Temp: %.2f, Time: %.2fs\r\n", get_duty(), get_temperature(), ((float)get_time() - (float)start_time)/1000); |
stupid | 1:ccb26dd9845a | 681 | } |
stupid | 1:ccb26dd9845a | 682 | } |
stupid | 1:ccb26dd9845a | 683 | |
stupid | 1:ccb26dd9845a | 684 | void do_done(bool first){ |
stupid | 1:ccb26dd9845a | 685 | static uint32_t start_time = 0; |
stupid | 1:ccb26dd9845a | 686 | |
stupid | 1:ccb26dd9845a | 687 | if(first){ |
stupid | 1:ccb26dd9845a | 688 | start_time = get_time(); |
stupid | 1:ccb26dd9845a | 689 | //control_interrupt.detach(); |
stupid | 1:ccb26dd9845a | 690 | all_off(); |
stupid | 1:ccb26dd9845a | 691 | if(connected)pc.printf("Done!\r\n"); |
stupid | 1:ccb26dd9845a | 692 | } |
stupid | 1:ccb26dd9845a | 693 | |
stupid | 1:ccb26dd9845a | 694 | heater_pin = 0; |
stupid | 1:ccb26dd9845a | 695 | uint32_t current_time = get_time() - start_time; |
stupid | 1:ccb26dd9845a | 696 | |
stupid | 1:ccb26dd9845a | 697 | if(current_time % 2000 > 1000){ |
stupid | 1:ccb26dd9845a | 698 | empty_led.input(); |
stupid | 1:ccb26dd9845a | 699 | } |
stupid | 1:ccb26dd9845a | 700 | else{ |
stupid | 1:ccb26dd9845a | 701 | empty_led.output(); |
stupid | 1:ccb26dd9845a | 702 | empty_led = 0; |
stupid | 0:aaf22a04f350 | 703 | } |
stupid | 0:aaf22a04f350 | 704 | } |
stupid | 0:aaf22a04f350 | 705 | |
stupid | 0:aaf22a04f350 | 706 | void print_state(void){ |
stupid | 0:aaf22a04f350 | 707 | if(!connected)return; |
stupid | 1:ccb26dd9845a | 708 | printf("State:\t"); |
stupid | 0:aaf22a04f350 | 709 | switch(state){ |
stupid | 0:aaf22a04f350 | 710 | case IDLE: |
stupid | 0:aaf22a04f350 | 711 | printf("IDLE\r\n"); |
stupid | 0:aaf22a04f350 | 712 | break; |
stupid | 0:aaf22a04f350 | 713 | case WAIT_FOR_TIP: |
stupid | 0:aaf22a04f350 | 714 | printf("WAIT_FOR_TIP\r\n"); |
stupid | 0:aaf22a04f350 | 715 | break; |
stupid | 0:aaf22a04f350 | 716 | case INITIAL_RAMP: |
stupid | 0:aaf22a04f350 | 717 | printf("INITIAL_RAMP\r\n"); |
stupid | 0:aaf22a04f350 | 718 | break; |
stupid | 0:aaf22a04f350 | 719 | case ACTIVE: |
stupid | 0:aaf22a04f350 | 720 | printf("ACTIVE\r\n"); |
stupid | 0:aaf22a04f350 | 721 | break; |
stupid | 1:ccb26dd9845a | 722 | case DONE: |
stupid | 1:ccb26dd9845a | 723 | printf("DONE\r\n"); |
stupid | 1:ccb26dd9845a | 724 | break; |
stupid | 0:aaf22a04f350 | 725 | case ERROR: |
stupid | 0:aaf22a04f350 | 726 | printf("ERROR\r\n"); |
stupid | 0:aaf22a04f350 | 727 | break; |
stupid | 0:aaf22a04f350 | 728 | default: break; |
stupid | 0:aaf22a04f350 | 729 | } |
stupid | 0:aaf22a04f350 | 730 | } |
stupid | 0:aaf22a04f350 | 731 | |
stupid | 0:aaf22a04f350 | 732 | int main(){ |
stupid | 0:aaf22a04f350 | 733 | static State last_state = IDLE; |
stupid | 0:aaf22a04f350 | 734 | init(); |
stupid | 1:ccb26dd9845a | 735 | if(FUNCTION_CHECK) functional_check(); |
stupid | 0:aaf22a04f350 | 736 | if(CALIBRATE){ |
stupid | 0:aaf22a04f350 | 737 | calibrate(true); |
stupid | 0:aaf22a04f350 | 738 | while(1)calibrate(false); |
stupid | 0:aaf22a04f350 | 739 | } |
stupid | 0:aaf22a04f350 | 740 | |
stupid | 0:aaf22a04f350 | 741 | while(1){ |
stupid | 1:ccb26dd9845a | 742 | getInput(); |
stupid | 1:ccb26dd9845a | 743 | |
stupid | 1:ccb26dd9845a | 744 | check_on_off(); |
stupid | 0:aaf22a04f350 | 745 | |
stupid | 0:aaf22a04f350 | 746 | bool state_change = false; |
stupid | 0:aaf22a04f350 | 747 | if(state != last_state){ |
stupid | 0:aaf22a04f350 | 748 | state_change = true; |
stupid | 0:aaf22a04f350 | 749 | last_state = state; |
stupid | 0:aaf22a04f350 | 750 | print_state(); |
stupid | 0:aaf22a04f350 | 751 | } |
stupid | 0:aaf22a04f350 | 752 | |
stupid | 0:aaf22a04f350 | 753 | switch(state){ |
stupid | 0:aaf22a04f350 | 754 | case IDLE: |
stupid | 1:ccb26dd9845a | 755 | do_idle(state_change); |
stupid | 0:aaf22a04f350 | 756 | break; |
stupid | 0:aaf22a04f350 | 757 | case WAIT_FOR_TIP: |
stupid | 0:aaf22a04f350 | 758 | do_wait_for_tip(state_change); |
stupid | 0:aaf22a04f350 | 759 | break; |
stupid | 0:aaf22a04f350 | 760 | case INITIAL_RAMP: |
stupid | 0:aaf22a04f350 | 761 | do_initial_ramp(state_change); |
stupid | 0:aaf22a04f350 | 762 | spin_lights(state_change); |
stupid | 0:aaf22a04f350 | 763 | break; |
stupid | 0:aaf22a04f350 | 764 | case ACTIVE: |
stupid | 0:aaf22a04f350 | 765 | do_treatment_cycle(state_change); |
stupid | 0:aaf22a04f350 | 766 | spin_lights(false); |
stupid | 0:aaf22a04f350 | 767 | break; |
stupid | 1:ccb26dd9845a | 768 | case DONE: |
stupid | 1:ccb26dd9845a | 769 | do_done(state_change); |
stupid | 1:ccb26dd9845a | 770 | break; |
stupid | 0:aaf22a04f350 | 771 | case ERROR: |
stupid | 0:aaf22a04f350 | 772 | abort(true); |
stupid | 0:aaf22a04f350 | 773 | break; |
stupid | 0:aaf22a04f350 | 774 | default: break; |
stupid | 0:aaf22a04f350 | 775 | } |
stupid | 0:aaf22a04f350 | 776 | } |
stupid | 0:aaf22a04f350 | 777 | } |
stupid | 0:aaf22a04f350 | 778 | |
stupid | 0:aaf22a04f350 | 779 | void spin_lights(bool first){ |
stupid | 0:aaf22a04f350 | 780 | static uint32_t start_time = 0; |
stupid | 0:aaf22a04f350 | 781 | |
stupid | 0:aaf22a04f350 | 782 | if(first) start_time = get_time(); |
stupid | 0:aaf22a04f350 | 783 | uint32_t current_time = get_time() - start_time; |
stupid | 0:aaf22a04f350 | 784 | |
stupid | 1:ccb26dd9845a | 785 | // tip should be solid for TIP_FLASH_INTERVAL_S seconds, then flash for 3 seconds |
stupid | 1:ccb26dd9845a | 786 | uint32_t tip_time = current_time % (TIP_FLASH_INTERVAL_S * 1000 + 3000); |
stupid | 1:ccb26dd9845a | 787 | if(tip_time < (TIP_FLASH_INTERVAL_S * 1000)) tip_light = 1; |
stupid | 0:aaf22a04f350 | 788 | else tip_light = (tip_time % 100 < 50)?1:0; |
stupid | 0:aaf22a04f350 | 789 | |
stupid | 1:ccb26dd9845a | 790 | // handle fuel gage LEDs |
stupid | 0:aaf22a04f350 | 791 | // this should be more directly linked to the treatment stop condition |
stupid | 0:aaf22a04f350 | 792 | uint32_t step = (ON_TIME_S - RED_LED_ON_TIME_S)/5; |
stupid | 0:aaf22a04f350 | 793 | step *= 1000; |
stupid | 0:aaf22a04f350 | 794 | |
stupid | 0:aaf22a04f350 | 795 | if(current_time > step) fuel_gage_4.input(); |
stupid | 0:aaf22a04f350 | 796 | else{ |
stupid | 0:aaf22a04f350 | 797 | fuel_gage_4.output(); |
stupid | 0:aaf22a04f350 | 798 | fuel_gage_4 = 0; |
stupid | 0:aaf22a04f350 | 799 | } |
stupid | 0:aaf22a04f350 | 800 | if(current_time > 2*step) fuel_gage_3.input(); |
stupid | 0:aaf22a04f350 | 801 | else{ |
stupid | 0:aaf22a04f350 | 802 | fuel_gage_3.output(); |
stupid | 0:aaf22a04f350 | 803 | fuel_gage_3 = 0; |
stupid | 0:aaf22a04f350 | 804 | } |
stupid | 0:aaf22a04f350 | 805 | if(current_time > 3*step) fuel_gage_2.input(); |
stupid | 0:aaf22a04f350 | 806 | else{ |
stupid | 0:aaf22a04f350 | 807 | fuel_gage_2.output(); |
stupid | 0:aaf22a04f350 | 808 | fuel_gage_2 = 0; |
stupid | 0:aaf22a04f350 | 809 | } |
stupid | 0:aaf22a04f350 | 810 | if(current_time > 4*step) fuel_gage_1.input(); |
stupid | 0:aaf22a04f350 | 811 | else{ |
stupid | 0:aaf22a04f350 | 812 | fuel_gage_1.output(); |
stupid | 0:aaf22a04f350 | 813 | fuel_gage_1 = 0; |
stupid | 0:aaf22a04f350 | 814 | } |
stupid | 0:aaf22a04f350 | 815 | if(current_time > 5*step){ |
stupid | 0:aaf22a04f350 | 816 | empty_led.output(); |
stupid | 0:aaf22a04f350 | 817 | empty_led = 0; |
stupid | 0:aaf22a04f350 | 818 | } |
stupid | 0:aaf22a04f350 | 819 | else empty_led.input(); |
stupid | 0:aaf22a04f350 | 820 | } |
stupid | 0:aaf22a04f350 | 821 | |
stupid | 0:aaf22a04f350 | 822 | void calibrate(bool first){ |
stupid | 0:aaf22a04f350 | 823 | static uint32_t start_time = 0; |
stupid | 0:aaf22a04f350 | 824 | static uint32_t control_timer = 0; |
stupid | 0:aaf22a04f350 | 825 | uint8_t duty_copy; |
stupid | 0:aaf22a04f350 | 826 | |
stupid | 0:aaf22a04f350 | 827 | if(first){ |
stupid | 0:aaf22a04f350 | 828 | start_time = get_time(); |
stupid | 0:aaf22a04f350 | 829 | control_timer = start_time; |
stupid | 0:aaf22a04f350 | 830 | fan = 1; |
stupid | 0:aaf22a04f350 | 831 | set_duty(5); |
stupid | 0:aaf22a04f350 | 832 | heater = ON; |
stupid | 0:aaf22a04f350 | 833 | } |
stupid | 0:aaf22a04f350 | 834 | |
stupid | 0:aaf22a04f350 | 835 | uint32_t current_time = get_time() - start_time; |
stupid | 0:aaf22a04f350 | 836 | |
stupid | 0:aaf22a04f350 | 837 | if(current_time - control_timer > 15000){ // increase the duty by 5% every 15 seconds |
stupid | 0:aaf22a04f350 | 838 | if(connected)pc.printf("Duty: %u, Temp: %f, Time: %.2fs\r\n", get_duty(), get_temperature(), ((float)get_time() - (float)start_time)/1000); |
stupid | 0:aaf22a04f350 | 839 | control_timer = current_time; |
stupid | 0:aaf22a04f350 | 840 | duty_copy = get_duty(); |
stupid | 0:aaf22a04f350 | 841 | duty_copy += 5; |
stupid | 0:aaf22a04f350 | 842 | // check if we're done |
stupid | 0:aaf22a04f350 | 843 | if(duty > 75 && connected){ |
stupid | 0:aaf22a04f350 | 844 | set_duty(1); |
stupid | 0:aaf22a04f350 | 845 | pc.printf("Done!\r\n"); |
stupid | 0:aaf22a04f350 | 846 | abort(false); |
stupid | 0:aaf22a04f350 | 847 | } |
stupid | 0:aaf22a04f350 | 848 | set_duty(duty_copy); |
stupid | 0:aaf22a04f350 | 849 | } |
stupid | 0:aaf22a04f350 | 850 | } |
stupid | 0:aaf22a04f350 | 851 | |
stupid | 0:aaf22a04f350 | 852 | /* |
stupid | 0:aaf22a04f350 | 853 | void calibrate(void){ |
stupid | 0:aaf22a04f350 | 854 | // this is really not necessary because all we care about is the temperature we need to hold the sensor at, |
stupid | 0:aaf22a04f350 | 855 | // which we are assuming directly correlates to output air temp. |
stupid | 0:aaf22a04f350 | 856 | // in reality it will probably be affected by ambient temperature, |
stupid | 0:aaf22a04f350 | 857 | // humidity, air flow rate, elevation (air density), and other factors |
stupid | 0:aaf22a04f350 | 858 | static uint16_t count = 0; |
stupid | 0:aaf22a04f350 | 859 | static uint8_t duty_copy = 5; //inital duty |
stupid | 0:aaf22a04f350 | 860 | float temperature_copy; |
stupid | 0:aaf22a04f350 | 861 | static int tester_count = 0; |
stupid | 0:aaf22a04f350 | 862 | |
stupid | 0:aaf22a04f350 | 863 | current_time = get_time(); |
stupid | 0:aaf22a04f350 | 864 | count++; |
stupid | 0:aaf22a04f350 | 865 | |
stupid | 0:aaf22a04f350 | 866 | check_limits(); |
stupid | 0:aaf22a04f350 | 867 | |
stupid | 0:aaf22a04f350 | 868 | if(count > 200){ // run the control loop every second |
stupid | 0:aaf22a04f350 | 869 | count = 0; |
stupid | 0:aaf22a04f350 | 870 | tester_count++; |
stupid | 0:aaf22a04f350 | 871 | if(tester_count % 30 == 0){ //30 seconds each duty cycle |
stupid | 0:aaf22a04f350 | 872 | duty_copy += 5; |
stupid | 0:aaf22a04f350 | 873 | if(duty > 85)abort(false); |
stupid | 0:aaf22a04f350 | 874 | if(connected)pc.printf("Duty: %u\r\nTemps:\r\n", duty_copy); |
stupid | 0:aaf22a04f350 | 875 | } |
stupid | 0:aaf22a04f350 | 876 | __disable_irq(); |
stupid | 0:aaf22a04f350 | 877 | duty = duty_copy; |
stupid | 0:aaf22a04f350 | 878 | temperature_copy = temperature; |
stupid | 0:aaf22a04f350 | 879 | __enable_irq(); |
stupid | 0:aaf22a04f350 | 880 | |
stupid | 1:ccb26dd9845a | 881 | if(connected && (tester_count % 30) > 24)pc.printf("\t%f\t%u\t%f\r\n", temperature_copy, temp_sense.read_u16(), temp_sense.read()); |
stupid | 0:aaf22a04f350 | 882 | } |
stupid | 0:aaf22a04f350 | 883 | }*/ |