Created
August 7, 2012 02:17
-
-
Save brooksware2000/3280748 to your computer and use it in GitHub Desktop.
Routines to compute PID value and regulate heater controls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'------------------------------------------------------------------------------- | |
' Regulates heater controls based on phase temperature parameters | |
'------------------------------------------------------------------------------- | |
PROCESS_PHASE: | |
GOSUB READ_TEMPERATURE | |
GOSUB COMPUTE_PID | |
WHILE (elapsedTime <> 0) | |
IF (SecondsChanged = 1) THEN | |
elapsedTime = elapsedTime - 1 | |
GOSUB READ_TEMPERATURE | |
GOSUB COMPUTE_PID | |
TimeOn = (cycleTime * OutVal)/100 | |
Tvar = Tvar + 1 | |
IF (Tvar >= outMax) THEN Tvar = outMin | |
IF (Tvar < TimeOn AND curTemp < setpoint) THEN | |
PORTPIN = 1 : PINSTATE = 1 : GOSUB SET_PIN | |
ELSE | |
PORTPIN = 1 : PINSTATE = 0 : GOSUB SET_PIN | |
ENDIF | |
GOSUB DISPLAY_STATUS | |
SecondsChanged = 0 | |
ENDIF | |
WEND | |
RETURN | |
'------------------------------------------------------------------------------- | |
' Computes the output drive from the individual PID components. | |
'------------------------------------------------------------------------------- | |
COMPUTE_PID: | |
errorCurrent = setpoint - curTemp | |
pTerm = Kp * errorCurrent | |
iTerm = iTerm + (Ki * errorCurrent) | |
IF (iterm > outMax) THEN iTerm = outMax | |
IF (iTerm < outMin) THEN iTerm = outMin | |
dTerm = (curTemp - lastMeasured) | |
OutVal = (pTerm + (iTerm - (Kd * dTerm))) | |
lastMeasured = curTemp | |
RETURN |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment