|
|
|
|
@ -22,6 +22,10 @@ int max_speed_count = 4800;
|
|
|
|
|
*/
|
|
|
|
|
void PID_Init()
|
|
|
|
|
{
|
|
|
|
|
if (abs(pid.out_tem) < 1e-5 && abs(pid.out_humidity) < 1e-5) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// // if flash have not a vaild value, just set a default value
|
|
|
|
|
// if (pid.Kp < 1e-7) { pid.Kp = 9.6; }
|
|
|
|
|
// if (pid.Ki < 1e-7) { pid.Ki = 0.01; }
|
|
|
|
|
@ -61,6 +65,11 @@ void PID_Init()
|
|
|
|
|
pid.hd_l = 0;
|
|
|
|
|
pid.h_base_l = 53;
|
|
|
|
|
|
|
|
|
|
pid.hp = 7.2;
|
|
|
|
|
pid.hi = 0.04;
|
|
|
|
|
pid.hd = 0;
|
|
|
|
|
pid.h_base = 53;
|
|
|
|
|
|
|
|
|
|
pid.cp = 4;
|
|
|
|
|
pid.ci = 0.01;
|
|
|
|
|
pid.cd = 0;
|
|
|
|
|
@ -174,25 +183,25 @@ void PID_Calc() // pid calc
|
|
|
|
|
|
|
|
|
|
float delta_t = pid.set_tem - pid.now_tem;
|
|
|
|
|
|
|
|
|
|
float hp = pid.hp_h;
|
|
|
|
|
float hi = pid.hi_h;
|
|
|
|
|
float hd = pid.hd_h;
|
|
|
|
|
int h_base = pid.h_base_h;
|
|
|
|
|
pid.hp = pid.hp_h;
|
|
|
|
|
pid.hi = pid.hi_h;
|
|
|
|
|
pid.hd = pid.hd_h;
|
|
|
|
|
pid.h_base = pid.h_base_h;
|
|
|
|
|
|
|
|
|
|
// if now temp is close to set temp, the heater will be less power
|
|
|
|
|
if (pid.set_tem - pid.now_tem < 3) {
|
|
|
|
|
hp = pid.hp_h * 0.6;
|
|
|
|
|
pid.hp = pid.hp_h * 0.6;
|
|
|
|
|
}
|
|
|
|
|
if (pid.set_tem - pid.now_tem < 1) {
|
|
|
|
|
hp = pid.hp_h * 0.3;
|
|
|
|
|
pid.hp = pid.hp_h * 0.3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// l mode
|
|
|
|
|
if (pid.set_tem <= pid.max_compressor_tem) {
|
|
|
|
|
hp = pid.hp_l;
|
|
|
|
|
hi = pid.hi_l;
|
|
|
|
|
hd = pid.hd_l;
|
|
|
|
|
h_base = pid.h_base_l;
|
|
|
|
|
pid.hp = pid.hp_l;
|
|
|
|
|
pid.hi = pid.hi_l;
|
|
|
|
|
pid.hd = pid.hd_l;
|
|
|
|
|
pid.h_base = pid.h_base_l;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pid.Ek = pid.set_tem - pid.now_tem;
|
|
|
|
|
@ -210,15 +219,15 @@ void PID_Calc() // pid calc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// SEk limit, updated func, remain a little heater power when the compressor is running in full state
|
|
|
|
|
if (pid.SEk < - (h_base / 2) / hi) {
|
|
|
|
|
pid.SEk = - (h_base / 2) / hi;
|
|
|
|
|
if (pid.SEk < - (pid.h_base / 2) / pid.hi) {
|
|
|
|
|
pid.SEk = - (pid.h_base / 2) / pid.hi;
|
|
|
|
|
}
|
|
|
|
|
if (pid.c_speed == max_speed_count) {
|
|
|
|
|
pid.SEk = 0;
|
|
|
|
|
}
|
|
|
|
|
float Error_calc = pid.SEk;
|
|
|
|
|
if (Error_calc < - (h_base + hp * delta_t) / hi) {
|
|
|
|
|
Error_calc = - (h_base + hp * delta_t) / hi;
|
|
|
|
|
if (Error_calc < - (pid.h_base + pid.hp * delta_t) / pid.hi) {
|
|
|
|
|
Error_calc = - (pid.h_base + pid.hp * delta_t) / pid.hi;
|
|
|
|
|
}
|
|
|
|
|
if (pid.c_speed == max_speed_count) {
|
|
|
|
|
Error_calc = 0;
|
|
|
|
|
@ -261,7 +270,7 @@ void PID_Calc() // pid calc
|
|
|
|
|
} else {
|
|
|
|
|
// if outer temp is got, we calc pid by outer temp
|
|
|
|
|
if (abs(pid.out_tem) > 1e-5) {
|
|
|
|
|
pid.cp = (pid.out_tem - pid.set_tem) * 0.26 + 0.3;
|
|
|
|
|
pid.cp = (pid.out_tem - pid.set_tem) * 0.28;
|
|
|
|
|
}
|
|
|
|
|
// use nagetive error and error diff when calc compressor power
|
|
|
|
|
int p_c = calc_cp(delta_t, - Error_calc, - DelEk, pid.c_base, pid.cp, pid.ci, pid.cd);
|
|
|
|
|
@ -269,7 +278,7 @@ void PID_Calc() // pid calc
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// heater percent
|
|
|
|
|
pid.h_percent = calc_hp(delta_t, Error_calc, DelEk, h_base, hp, hi, hd);
|
|
|
|
|
pid.h_percent = calc_hp(delta_t, Error_calc, DelEk, pid.h_base, pid.hp, pid.hi, pid.hd);
|
|
|
|
|
// close heater when compressor is running in full state
|
|
|
|
|
if (pid.c_speed == max_speed_count) {
|
|
|
|
|
pid.h_percent = 0;
|
|
|
|
|
|