在目标温度切换超过3度时,重新进行pid初始化。并且重新设置合理的压缩机速度范围

check
Zeng wei (曾威) 2 years ago
parent 56f7acb7bd
commit a9032af5bb

@ -1,6 +1,7 @@
{ {
"files.associations": { "files.associations": {
"w25q128_ins.h": "c", "w25q128_ins.h": "c",
"usart.h": "c" "usart.h": "c",
"myfreertos.h": "c"
} }
} }

@ -12,16 +12,31 @@ extern u8 gpio_state;
extern int T; extern int T;
unsigned int num = 0; unsigned int num = 0;
PID pid; PID pid;
int min_speed_count = 1500; int min_speed_count = 2000;
int max_speed_count = 6000; int max_speed_count = 4800;
/**
* PID init
*/
void PID_Init() void PID_Init()
{ {
// if flash have not a vaild value, just set a default value // // if flash have not a vaild value, just set a default value
if (pid.Kp < 1e-7) { pid.Kp = 9.6; } // if (pid.Kp < 1e-7) { pid.Kp = 9.6; }
if (pid.Ki < 1e-7) { pid.Ki = 0.01; } // if (pid.Ki < 1e-7) { pid.Ki = 0.01; }
if (pid.Kd < 1e-7) { pid.Kd = 340; } // if (pid.Kd < 1e-7) { pid.Kd = 340; }
if (pid.tem_threshold < 0.0001) { pid.tem_threshold = 0.2; } // if (pid.tem_threshold < 0.0001) { pid.tem_threshold = 0.2; }
pid.Ek = 0;
pid.Ek_prev = 0;
pid.SEk = 0;
pid.Pout = 0;
pid.Iout = 0;
pid.Dout = 0;
pid.OUT = 0;
pid.OUT0 = 0;
pid.h_percent = 0;
pid.c_speed = 0;
pid.t = 1000; // PID calc period pid.t = 1000; // PID calc period
// pid.Ti=5000000;// integral time // pid.Ti=5000000;// integral time
@ -42,13 +57,11 @@ void PID_Init()
pid.hd_l = 0; pid.hd_l = 0;
pid.h_base_l = 53; pid.h_base_l = 53;
pid.cp = 3.6; pid.cp = 9.6;
pid.ci = 0; pid.ci = 0;
pid.cd = 0; pid.cd = 0;
pid.c_base = 37; pid.c_base = 37;
pid.h_percent = 0;
pid.c_speed = 0;
} }
/** /**
@ -57,8 +70,8 @@ void PID_Init()
*/ */
void set_compressor_power(int speed) { void set_compressor_power(int speed) {
u8 data[8] = {0x01, 0x06, 0x60, 0x00, 0x00, 0x09, 0xBB, 0xAA}; // speed control for compressor controller u8 data[8] = {0x01, 0x06, 0x60, 0x00, 0x00, 0x09, 0xBB, 0xAA}; // speed control for compressor controller
if (speed > 6000) { if (speed > max_speed_count) {
speed = 6000; speed = max_speed_count;
} }
if (speed < 0) { if (speed < 0) {
speed = 0; speed = 0;
@ -141,8 +154,8 @@ int calc_compressor_speed(int percent, int v_min, int v_max) {
void PID_Calc() // pid calc void PID_Calc() // pid calc
{ {
int min_speed_count = 1800; // int min_speed_count = 1800;
int max_speed_count = 4800; // int max_speed_count = 4800;
float DelEk; // The difference between the last two deviations float DelEk; // The difference between the last two deviations
// float td; // float td;
float out; float out;
@ -191,9 +204,9 @@ void PID_Calc() // pid calc
pid.SEk = 0; pid.SEk = 0;
} }
// SEk limit, updated func // SEk limit, updated func, remain a little heater power when the compressor is running in full state
if (pid.SEk < - h_base / hi) { if (pid.SEk < - (h_base - 10) / hi) {
pid.SEk = - h_base / hi; pid.SEk = - (h_base - 10) / hi;
} }
if (pid.c_speed == max_speed_count) { if (pid.c_speed == max_speed_count) {
pid.SEk = 0; pid.SEk = 0;

File diff suppressed because one or more lines are too long

@ -10,9 +10,9 @@
<aExt>*.s*; *.src; *.a*</aExt> <aExt>*.s*; *.src; *.a*</aExt>
<oExt>*.obj; *.o</oExt> <oExt>*.obj; *.o</oExt>
<lExt>*.lib</lExt> <lExt>*.lib</lExt>
<tExt>*.txt; *.h; *.inc; *.md</tExt> <tExt>*.txt; *.h; *.inc</tExt>
<pExt>*.plm</pExt> <pExt>*.plm</pExt>
<CppX>*.cpp; *.cc; *.cxx</CppX> <CppX>*.cpp</CppX>
<nMigrate>0</nMigrate> <nMigrate>0</nMigrate>
</Extensions> </Extensions>
@ -115,11 +115,6 @@
<pMon>STLink\ST-LINKIII-KEIL_SWO.dll</pMon> <pMon>STLink\ST-LINKIII-KEIL_SWO.dll</pMon>
</DebugOpt> </DebugOpt>
<TargetDriverDllRegistry> <TargetDriverDllRegistry>
<SetRegEntry>
<Number>0</Number>
<Key>ST-LINKIII-KEIL_SWO</Key>
<Name>-U16004A002933353739303541 -O239 -S0 -C0 -A0 -N00("ARM CoreSight SW-DP") -D00(1BA01477) -L00(0) -TO19 -TC10000000 -TP21 -TDS8004 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103C8$Flash\STM32F10x_128.FLM)</Name>
</SetRegEntry>
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
<Key>UL2CM3</Key> <Key>UL2CM3</Key>
@ -1464,7 +1459,7 @@
<Group> <Group>
<GroupName>HARDWARE</GroupName> <GroupName>HARDWARE</GroupName>
<tvExp>0</tvExp> <tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel> <cbSel>0</cbSel>
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>

@ -276,7 +276,7 @@ void Sensor_Communication_task(void *pvParameters)
u8 c = 0; u8 c = 0;
RS485_RX_CNT = 0; RS485_RX_CNT = 0;
while (isAllZeros(RS485_RX_BUF_COPY, 128) == 0) while (isAllZeros(RS485_RX_BUF_COPY, 128) == 0)
{ {
if (RS485_RX_BUF_COPY[0] == INNER_SENSOR_ADDRESS && RS485_RX_BUF_COPY[1] == 0x03 && CRC16_check(RS485_RX_BUF_COPY, 21) == 1) if (RS485_RX_BUF_COPY[0] == INNER_SENSOR_ADDRESS && RS485_RX_BUF_COPY[1] == 0x03 && CRC16_check(RS485_RX_BUF_COPY, 21) == 1)
{ {
c++; c++;
@ -468,7 +468,10 @@ void process_inner_sensor_data(u8 *data) {
gpio_state &= 0xFE; gpio_state &= 0xFE;
ALARM = 0; ALARM = 0;
} }
// check current set temp and perv set temp, if diff is greater then 3degree, then reInit pid
if (abs(pid.set_tem - tem / 10.0) > 3) {
PID_Init();
}
pid.set_tem = tem / 10.0; pid.set_tem = tem / 10.0;
pid.now_tem = T / 10.0; pid.now_tem = T / 10.0;
// PID_Calc(); // PID_Calc();

@ -1,6 +1,8 @@
#ifndef _MYFREERTOS_H #ifndef _MYFREERTOS_H
#define _MYFREERTOS_H #define _MYFREERTOS_H
#include <math.h>
#include <stdlib.h>
#include "FreeRTOS.h" #include "FreeRTOS.h"
#include "task.h" #include "task.h"
#include "SysTick.h" #include "SysTick.h"

Loading…
Cancel
Save