@@ -28,6 +28,7 @@ enum state {
STATE_SETP,
STATE_SETI,
STATE_SETD,
STATE_SETWINDUP,
STATE_PREHEAT_BREW,
STATE_MAINTAIN_BREW,
@@ -202,8 +203,9 @@ int32_t setpoint = 0;
uint16_t k_p = 1;
uint16_t k_i = 1;
uint16_t k_d = 1;
uint16_t windup_guard = 1;
int16_t ssr_output = 0; // Duty cycle of ssr, 0 to SSR_PERIOD
uint8_t pid_enabled = 0;
// Process things
void process()
@@ -221,10 +223,17 @@ void process()
// Every 200ms, set the SSR on unless output is 0
if((ticks - last_ssr_on > SSR_PERIOD))
{
// Get ssr output for next time
int16_t power_percent = update_pid(k_p, k_i, k_d, temp, temp_frac, setpoint);
//power-percent is 0-1000
ssr_output = power_percent; //(((uint32_t)SSR_PERIOD * (uint32_t)10 * (uint32_t)100) * power_percent) / (uint32_t)1000000;
if(pid_enabled)
}
else
ssr_output = 0;
// Only support heating (ssr_output > 0) right now
if(ssr_output > 0) {
@@ -292,11 +301,12 @@ void machine()
// Write text to OLED
// [ therm :: idle ]
ssd1306_DrawString("therm :: idle ", 0, 40);
pid_enabled = 0;
char tempstr[6];
itoa_fp(temp, temp_frac, tempstr);
ssd1306_DrawString("Temp: ", 3, 40);
ssd1306_DrawString(" ", 3, 70);
ssd1306_DrawString(" ", 3, 72);
ssd1306_DrawString(tempstr, 3, 72);
ssd1306_drawlogo();
@@ -309,12 +319,12 @@ void machine()
case 1:
ssd1306_DrawString("-> set P/I/D", 1, 40);
ssd1306_DrawString("-> setup ", 1, 40);
} break;
case 0:
ssd1306_DrawString("-> reset ", 1, 40);
@@ -328,7 +338,7 @@ void machine()
state = STATE_SETP;
break;
state = STATE_IDLE;
default:
state = STATE_PREHEAT_BREW;
@@ -430,7 +440,7 @@ void machine()
// Button handler
if(SW_BTN_PRESSED) {
state = STATE_SETWINDUP;
else if(!GPIO_ReadInputDataBit(SW_UP)) {
k_d++;
@@ -444,6 +454,41 @@ void machine()
case STATE_SETWINDUP:
// [ therm :: set windup ]
// [ g = 12 ]
ssd1306_DrawString("Windup Guard", 0, 40);
itoa(windup_guard, tempstr);
ssd1306_DrawString("G=", 1, 45);
ssd1306_DrawString(" ", 1, 57);
ssd1306_DrawString(tempstr, 1, 57);
ssd1306_DrawString("Press to accept", 3, 40);
windup_guard++;
else if(!GPIO_ReadInputDataBit(SW_DOWN) && windup_guard > 0) {
windup_guard--;
// Event Handler
// N/A
case STATE_PREHEAT_BREW:
@@ -452,6 +497,7 @@ void machine()
ssd1306_DrawString("Preheating...", 0, 40);
draw_setpoint();
pid_enabled = 1;
@@ -480,6 +526,7 @@ void machine()
ssd1306_DrawString("Ready to Brew!", 0, 40);
@@ -506,6 +553,7 @@ void machine()
@@ -534,6 +582,7 @@ void machine()
ssd1306_DrawString("Ready to Steam!", 0, 40);
@@ -556,6 +605,7 @@ void machine()
Status change: