/* * Reset command should stimulate an async reset response (some problem) */ void MWiFi::resetMCW() { setPowerOff(); digitalWrite(7,HIGH);delay(100); begin(); /* STARTUPBITS=0; sendShortMess(170); receiveMessWait(2000); //ACK while(STARTUPBITS==0) getAsyncWait(10000); //Async reset data if (STARTUPBITS==0) wdt_enable(WDTO_1S); */ }
static void heatControl(float setpoint) { static uint16_t stepCounter = 0; switch(stepCounter) { case ms2steps(250): setPowerOff(); break; case ms2steps(275): actitivityDetectionEnabled = 1; break; case ms2steps(300): updateTemp(); vram.PWM_Sp = PID(setpoint, (float)vram.CurrTemp / 10); if (vram.PWM_Sp > 0) { actitivityDetectionEnabled = 0; setPowerDuty(vram.PWM_Sp); } stepCounter = 0; break; } ++stepCounter; }
void controlStateMachine() { enum STATEStyp nextState = g_State; static uint32_t stepCounter = 0; switch(g_State) { case S_BOOTUP: setPowerOff(); resetOffTimer(); setString("boot", 4, 0, 0); // set initial temp setpoint vram.TempSP = nvram.Tsp; if ( stepCounter > ms2steps(1000) ) // after 1s we go to operation { if (setupMode) nextState = S_SETUP; else if (nvram.IsOpenLoop == 1) nextState = S_OPEN_LOOP; else nextState = S_OPERATION; } break; case S_SETUP: if (g_InitState) vram.TempSP = nvram.Tsp; updateTemp(); if (!setupMode) { if (nvram.IsOpenLoop == 1) nextState = S_OPEN_LOOP; else nextState = S_OPERATION; } break; case S_OPERATION: { if (g_InitState) { activateOperMenu(); } heatControl(vram.TempSP); // thermocouple absent detection if (vram.CurrTemp < OPENLOOP_TEMP_VALUE) ++loopDetectCntr; else loopDetectCntr = 0; if (loopDetectCntr > LOOP_DETECTION_TIME) { loopDetectCntr = 0; nvram.IsOpenLoop = 1; } if (nvram.IsOpenLoop == 1) nextState = S_OPEN_LOOP; if (--vram.OffCntDwn <= 0) nextState = S_OFF; break; } case S_OPEN_LOOP: if (g_InitState) { vram.PWM_Sp = 2; vram.CurrTemp = 0; activateManualMenu(); } if (vram.PWM_Sp < 0) vram.PWM_Sp = 0; setPowerDuty(vram.PWM_Sp); if (nvram.IsOpenLoop == 0) nextState = S_OPERATION; // go back to automatic operation if (--vram.OffCntDwn <= 0) nextState = S_OFF; break; case S_OFF: if (g_InitState) setPowerOff(); updateTemp(); if ( !(stepCounter % ms2steps(1000) ) ) setString("OFF", 3, 0, 0); if ( !(stepCounter % ms2steps(2000) ) ) { char buff[10]; sprintf(buff, "%hd*", vram.CurrTemp / 10); rightAlign(buff); setString(buff, strlen(buff), 0, 0); } if (vram.OffCntDwn > 0) nextState = nvram.IsOpenLoop ? S_OPEN_LOOP : S_OPERATION; break; case S_START_BL: break; } if (S_BOOTUP != g_State && S_OFF != g_State && !(stepCounter % ms2steps(100)) ) // we update display each 100 ms updateDisplay(); if (nextState != g_State) // we changed state this time { g_InitState = 1; g_State = nextState; } else g_InitState = 0; ++stepCounter; }