From 203b1e60f60205331082e2e2e98f6b062fe54f21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zeng=20wei=20=28=E6=9B=BE=E5=A8=81=29?= Date: Tue, 16 Apr 2024 11:50:50 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=BA=8C=E6=AC=A1=E8=B0=83=E8=8A=82?= =?UTF-8?q?=EF=BC=8C=E5=A5=BD=E5=83=8F=E6=9C=89=E4=BA=9B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HARDWARE/PID.c | 41 +++++++++++++++++++------------ HARDWARE/PID.h | 6 +++++ HARDWARE/rs485.c | 41 ++++++++++++++++++------------- USER/control.uvguix.Administrator | 10 ++++---- myfreertos/myfreertos.c | 6 +++-- 5 files changed, 64 insertions(+), 40 deletions(-) diff --git a/HARDWARE/PID.c b/HARDWARE/PID.c index b621730..58fb6ff 100644 --- a/HARDWARE/PID.c +++ b/HARDWARE/PID.c @@ -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; diff --git a/HARDWARE/PID.h b/HARDWARE/PID.h index a3900d9..7d2fd5b 100644 --- a/HARDWARE/PID.h +++ b/HARDWARE/PID.h @@ -27,6 +27,12 @@ typedef struct Pid float hi_l; float hd_l; int h_base_l; // base power percent in l mode + + + float hp; + float hi; + float hd; + int h_base; int h_percent; diff --git a/HARDWARE/rs485.c b/HARDWARE/rs485.c index 158d760..19c2648 100644 --- a/HARDWARE/rs485.c +++ b/HARDWARE/rs485.c @@ -460,23 +460,30 @@ void RS485_1_Upload_Params(void) sendbuf[25] = 0; // ALARM state sendbuf[26] = ALARM; // ALARM state - if (pid.set_tem > pid.max_compressor_tem) { - // h mode - sendbuf[27] = (int)(pid.hp_h * 1000) / 256; // Kp 110 - sendbuf[28] = (int)(pid.hp_h * 1000) % 256; // Kp 110 - sendbuf[29] = ((int)(pid.hi_h * 100000)) / 256; // Ti 0.001 - sendbuf[30] = ((int)(pid.hi_h * 100000)) % 256; // Ti 0.001 - sendbuf[31] = (int)(pid.hd_h * 1000) / 256; // Td 340 - sendbuf[32] = (int)(pid.hd_h * 1000) % 256; // Td 340 - } else { - // l mode - sendbuf[27] = (int)(pid.hp_l * 1000) / 256; // Kp 110 - sendbuf[28] = (int)(pid.hp_l * 1000) % 256; // Kp 110 - sendbuf[29] = ((int)(pid.hi_l * 100000)) / 256; // Ti 0.001 - sendbuf[30] = ((int)(pid.hi_l * 100000)) % 256; // Ti 0.001 - sendbuf[31] = (int)(pid.hd_l * 1000) / 256; // Td 340 - sendbuf[32] = (int)(pid.hd_l * 1000) % 256; // Td 340 - } + // if (pid.set_tem > pid.max_compressor_tem) { + // // h mode + // sendbuf[27] = (int)(pid.hp_h * 1000) / 256; // Kp 110 + // sendbuf[28] = (int)(pid.hp_h * 1000) % 256; // Kp 110 + // sendbuf[29] = ((int)(pid.hi_h * 100000)) / 256; // Ti 0.001 + // sendbuf[30] = ((int)(pid.hi_h * 100000)) % 256; // Ti 0.001 + // sendbuf[31] = (int)(pid.hd_h * 1000) / 256; // Td 340 + // sendbuf[32] = (int)(pid.hd_h * 1000) % 256; // Td 340 + // } else { + // // l mode + // sendbuf[27] = (int)(pid.hp_l * 1000) / 256; // Kp 110 + // sendbuf[28] = (int)(pid.hp_l * 1000) % 256; // Kp 110 + // sendbuf[29] = ((int)(pid.hi_l * 100000)) / 256; // Ti 0.001 + // sendbuf[30] = ((int)(pid.hi_l * 100000)) % 256; // Ti 0.001 + // sendbuf[31] = (int)(pid.hd_l * 1000) / 256; // Td 340 + // sendbuf[32] = (int)(pid.hd_l * 1000) % 256; // Td 340 + // } + sendbuf[27] = (int)(pid.hp * 1000) / 256; + sendbuf[28] = (int)(pid.hp * 1000) % 256; + sendbuf[29] = ((int)(pid.hi * 100000)) / 256; + sendbuf[30] = ((int)(pid.hi * 100000)) % 256; + sendbuf[31] = (int)(pid.hd * 1000) / 256; + sendbuf[32] = (int)(pid.hd * 1000) % 256; + sendbuf[33] = pid.h_percent / 256; // h_percent sendbuf[34] = pid.h_percent % 256; // h_percent diff --git a/USER/control.uvguix.Administrator b/USER/control.uvguix.Administrator index e5387ec..fb6cf6c 100644 --- a/USER/control.uvguix.Administrator +++ b/USER/control.uvguix.Administrator @@ -77,8 +77,8 @@ 2 3 - -32000 - -32000 + -1 + -1 -1 @@ -1758,9 +1758,9 @@ ../HARDWARE/PID.c - 19 - 28 - 53 + 38 + 20 + 46 1 0 diff --git a/myfreertos/myfreertos.c b/myfreertos/myfreertos.c index 8dbf030..b12e52f 100644 --- a/myfreertos/myfreertos.c +++ b/myfreertos/myfreertos.c @@ -241,8 +241,10 @@ int hot = 0; void HotTestRequestTask(void *pvParameters) { while (1) { if (!(T == 0 && H == 0)) { - PID_Calc(); - RS485_1_Upload_Params(); + if (!(abs(pid.out_tem) < 1e-5 && abs(pid.out_humidity) < 1e-5)) { + PID_Calc(); + RS485_1_Upload_Params(); + } } vTaskDelay(5000); }