|
|
|
@ -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;
|
|
|
|
|