Joined: 30 Jul 2007 Posts: 112 Location: Moscow, Russia
Please, help me with making hysteresis!
Posted: Wed Aug 01, 2007 6:01 am
I need to implement hysteresis in termoregulator device. I have desired temp (Td), current temp (Tc) and Delta Td (hysteresis).
libor
Joined: 14 Dec 2004 Posts: 288 Location: Hungary
Posted: Wed Aug 01, 2007 9:46 am
Do you read current temp as an analog input using the A/D ? I suppose you want the hysteresis done in software, and you are controlling a digital port.
You can define the two levels for the switching and use the according level depending on the current state (ON or OFF) of the state machine.
Code:
#define OFF 0
#define ON 1
int state;
...
lowerlimit=Td-delta;
upperlimit=Td+delta;
...
if (state == ON) {
if (Tc>upperlimit) {
state = OFF;
//... turn off heating
}
}
if (state == OFF) {
if (Tc<lowerlimit) {
state = ON;
// ...turn on heating
}
}
if you are controling an analogue output like a PWM output I would rather suggest to use a PID algorythm instead calculating the error and acting upon it.
40inD
Joined: 30 Jul 2007 Posts: 112 Location: Moscow, Russia
Posted: Wed Aug 01, 2007 12:22 pm
Thanks! It works.
(I use DS18B20, but it's no matter)
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum