Thermostat Function Problem
Hello Everyone!
I have the problem with function below.
When I have a Hyst>0 function is working well.
Below Set Point, the function returns 0, and above SetPoint+Hyst the function returns 1.
Something similar as Thermostat is operating.
But when Hyst<0, the function do not work as planned to.
Above Set Point, the function returns 0, but when the Temperature just drops below Set Point, the function returns 1.
Idea was, that function returns 1 below SetPoint+Hyst (actually is SetPoint-Hyst, because Hyst<0).
When I put second part of function (Case Hyst<0) in the while loop all works fine.
I can't find where is my mistake hide.
Will be appreciate for any help
Iwan
uint8_t Thermostat(int Temperature, int SetPoint, int Hyst)
{
uint8_t Output,Start,Stop;
//+++++++++++++++++++++++++++++++++++++++++
//+++++_Case_Hyst>0_+++++++++++++++++++++++
if(Hyst>0)
{
if(Temperature>(SetPoint+Hyst))
{ Start=1;
Stop=0;
}
else if(Temperature<SetPoint)
{ Start=0;
Stop=1;
}
}
//+++++++++++++++++++++++++++++++++++++++++
//+++++_Case_Hyst<0_+++++++++++++++++++++++
if(Hyst<0)
{
if(Temperature<(SetPoint+Hyst))
{ Start=1;
Stop=0;
}
else if(Temperature>SetPoint)
{ Start=0;
Stop=1;
}
}
//+++++++++++++++++++++++++++++++++++++++++
//+++++_Send_the_Result_+++++++++++++++++++
Output=Start*(!Stop);
return Output;
}