Ok, I will start from the beginning... I have two similar projects -> both of them are based on:
-Wemos d1 mini pro,
-2 x db18s20,
-2 x SSR,
-2kW Heating element
-1kW Heating element.
Both are designed more or less for the same target -> precise temperature control (but in different environments).
I tested the normal level regulator with hysteresis 0.1 and 0... but because of the thermal inertia of the heater and poorly isolated environment, I am getting -4/+4 °C... which is not acceptable
I decided to make my own plugin based on the Arduino PID library, with temporary, test code below:
Code: Select all
case PLUGIN_ONCE_A_SECOND:
{
// we're checking a var from another task, so calculate that basevar
taskIndex_t TaskIndex = PCONFIG(0);
byte BaseVarIndex = TaskIndex * VARS_PER_TASK + PCONFIG(1);
// load var
float SetPoint = PCONFIG_FLOAT(0);
float kP = PCONFIG_FLOAT(1);
float kI = PCONFIG_FLOAT(2);
float kD = PCONFIG_FLOAT(3);
float Input = UserVar[BaseVarIndex] / SetPoint;
float lastInput = PCONFIG_FLOAT(4);
float Error = 1 - Input;
float dInput = Input - lastInput;
float outputSum = PCONFIG_FLOAT(5) + (kI * Error);
boolean pOnE = PCONFIG(2);
if(!pOnE) outputSum -= kP * dInput;
if(outputSum > 1) outputSum = 1;
else if(outputSum < 1) outputSum = 0;
float PID = 0;
if(pOnE) PID += kP * Error;
PID += outputSum - kD * dInput;
if(PID > 1) PID = 1;
else if(PID < 1) PID = 0;
float TimeNow = millis();
float TimeDiff = TimeNow - PCONFIG_FLOAT(6);
PCONFIG_FLOAT(4) = Input;
PCONFIG_FLOAT(5) = outputSum;
PCONFIG_FLOAT(6) = TimeNow;
UserVar[event->BaseVarIndex] = PID;
UserVar[event->BaseVarIndex + 1] = PID * 1000;
UserVar[event->BaseVarIndex + 2] = Input;
UserVar[event->BaseVarIndex + 3] = TimeDiff; //----------> here i am getting 970-1010 ms which is perfect.
//--------------------------------------------------------------------> here i want to trigger sth like Pulse,2,0,PID*1000 on SSR
sendData(event);
success = true;
break;
}
now, If I put sth like this in rules:
Code: Select all
on PID_C#event do
Pulse,2,0,[PID_C#SSR_ms] //-->only for test purpose... internal led
TaskValueSet,2,3,[Dummy#Time] //copy previous %unixtime%
TaskValueSet,2,2,%unixtime% //store new %unixtime%
endon
If there are any mistakes -> sorry, I wrote rules out of my head...
anyway, I am getting the difference around 2-3s... I can see it also on the internal LED.
Or maybe I am doing it wrong... could be also...
I know that SSR has some limitations but in that case should be sufficient. otherwise I can make SCR regulator with zero cross detection
but I wanted to avoid that