加热棒恒定加热50%测试

main
Zeng wei (曾威) 2 years ago
parent abae4240ab
commit 3ce081dbec

@ -49,103 +49,103 @@ void send_speed_signal(int speed) {
void PID_Calc() // pid calc void PID_Calc() // pid calc
{ {
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;
if (pid.C1ms < (pid.t)) // The calculation cycle has not yet arrived // if (pid.C1ms < (pid.t)) // The calculation cycle has not yet arrived
{
return;
}
// if (pid.set_tem > pid.now_tem)
// { // {
// pid.Ek = pid.set_tem - pid.now_tem; // return;
// }
// // if (pid.set_tem > pid.now_tem)
// // {
// // pid.Ek = pid.set_tem - pid.now_tem;
// // }
// // else
// // {
// // pid.Ek = pid.now_tem - pid.set_tem;
// // }
// pid.Ek = pid.now_tem - pid.set_tem;
// pid.Pout = pid.Kp * pid.Ek; // Proportional output
// pid.SEk += pid.Ek; // Total historical deviation
// DelEk = pid.Ek - pid.Ek_1; // The difference between the last two deviations
// // ti=pid.t/pid.Ti;
// // ki=ti*pid.Kp;
// pid.Iout = pid.Ki * pid.SEk; // integral output
// // td=pid.Td/pid.t;
// // kd=pid.Kp*td;
// pid.Dout = pid.Kd * DelEk; // difference output
// if (pid.Dout < 0)
// {
// pid.Dout = 0 - pid.Dout;
// }
// // out= pid.Pout+pid.Iout+ pid.Dout;
// out = pid.Pout;
// if (out > pid.pwmcycle)
// {
// pid.OUT = pid.pwmcycle;
// }
// else if (out <= 0)
// {
// pid.OUT = pid.OUT0;
// } // }
// else // else
// { // {
// pid.Ek = pid.now_tem - pid.set_tem; // pid.OUT = out;
// }
// pid.Ek_1 = pid.Ek; // udpate difference
// pid.C1ms = 0;
// // speed count
// int speed_count = pid.OUT / 200.0 * (max_speed_count - min_speed_count) + min_speed_count;
// if (speed_count > 6000) {
// speed_count = 6000;
// } // }
pid.Ek = pid.now_tem - pid.set_tem;
pid.Pout = pid.Kp * pid.Ek; // Proportional output
pid.SEk += pid.Ek; // Total historical deviation
DelEk = pid.Ek - pid.Ek_1; // The difference between the last two deviations
// ti=pid.t/pid.Ti;
// ki=ti*pid.Kp;
pid.Iout = pid.Ki * pid.SEk; // integral output
// td=pid.Td/pid.t;
// kd=pid.Kp*td;
pid.Dout = pid.Kd * DelEk; // difference output
if (pid.Dout < 0)
{
pid.Dout = 0 - pid.Dout;
}
// out= pid.Pout+pid.Iout+ pid.Dout;
out = pid.Pout;
if (out > pid.pwmcycle)
{
pid.OUT = pid.pwmcycle;
}
else if (out <= 0)
{
pid.OUT = pid.OUT0;
}
else
{
pid.OUT = out;
}
pid.Ek_1 = pid.Ek; // udpate difference
pid.C1ms = 0;
// speed count // if (pid.now_tem < pid.set_tem + pid.tem_offset - pid.tem_threshold)
int speed_count = pid.OUT / 200.0 * (max_speed_count - min_speed_count) + min_speed_count; // {
if (speed_count > 6000) { // // Obtain the current deviation value
speed_count = 6000; // // when the target temperature is 1 degree Celsius higher than the actual temperature, heat up
} // // close compressor open heater
// /*GPIO1->Alarm bell GPIO3->heater GPIO4->Fresh air fan GPIO5->humidifier GPIO6->compressor */
if (pid.now_tem < pid.set_tem + pid.tem_offset - pid.tem_threshold) // // HC595_Send_Byte(gpio_state &= 0xDF);//close compressor &=1101 1111 0xDF
{ // HC595_Send_Byte(gpio_state |= 0x04); // open heater |=0000 0100 0x04
// Obtain the current deviation value // speed_count = 1000; // close compressor
// when the target temperature is 1 degree Celsius higher than the actual temperature, heat up // hot_clod_flag = 2;
// close compressor open heater // pid.Iout = 0;
/*GPIO1->Alarm bell GPIO3->heater GPIO4->Fresh air fan GPIO5->humidifier GPIO6->compressor */ // } else if (pid.now_tem > pid.set_tem + pid.tem_offset - pid.tem_threshold && pid.now_tem < pid.set_tem + pid.tem_offset + pid.tem_threshold)
// HC595_Send_Byte(gpio_state &= 0xDF);//close compressor &=1101 1111 0xDF // {
HC595_Send_Byte(gpio_state |= 0x04); // open heater |=0000 0100 0x04 // HC595_Send_Byte(gpio_state &= 0xFB); // close heater &=1111 1011 0xFB
speed_count = 1000; // close compressor // speed_count = 1000; // close compressor
hot_clod_flag = 2;
pid.Iout = 0; // hot_clod_flag = 0;
} else if (pid.now_tem > pid.set_tem + pid.tem_offset - pid.tem_threshold && pid.now_tem < pid.set_tem + pid.tem_offset + pid.tem_threshold) // // pid.Iout=0;
{ // } else if (pid.now_tem > pid.set_tem + pid.tem_offset + pid.tem_threshold)
HC595_Send_Byte(gpio_state &= 0xFB); // close heater &=1111 1011 0xFB // {
speed_count = 1000; // close compressor // // Obtain the current deviation value
// // when the target temperature is lower than the actual temperature, refrigerate
hot_clod_flag = 0; // // open compressor close heater
// pid.Iout=0; // HC595_Send_Byte(gpio_state &= 0xFB); // close heater &=1111 1011 0xFB
} else if (pid.now_tem > pid.set_tem + pid.tem_offset + pid.tem_threshold)
{
// Obtain the current deviation value // // // 0-200 correspond 0-100%, if pid.out=50, percentage means 25% //num=50*400/200=100 100/400=25%
// when the target temperature is lower than the actual temperature, refrigerate // // num = (((pid.OUT * 400) / pid.pwmcycle) - 1); // Conversion of pid.OUT and PWM Duty Cycle Values
// open compressor close heater // // TIM_SetCompare3(TIM3, num / 4);
HC595_Send_Byte(gpio_state &= 0xFB); // close heater &=1111 1011 0xFB // // printf("%d\r\n",num);
// // HC595_Send_Byte(gpio_state|=0x20);//open compressor |=0010 0000
// hot_clod_flag = 1;
// // 0-200 correspond 0-100%, if pid.out=50, percentage means 25% //num=50*400/200=100 100/400=25% // // pid.Iout=0;
// num = (((pid.OUT * 400) / pid.pwmcycle) - 1); // Conversion of pid.OUT and PWM Duty Cycle Values // }
// TIM_SetCompare3(TIM3, num / 4);
// printf("%d\r\n",num);
// HC595_Send_Byte(gpio_state|=0x20);//open compressor |=0010 0000
hot_clod_flag = 1;
// pid.Iout=0;
}
// send_speed_signal(speed_count); // send_speed_signal(speed_count);
send_speed_signal(1500); send_speed_signal(1000);
// if (hot_clod_flag == 1 && T <= tem - 3) // During the refrigeration process, the actual temperature drops by 0.3 degrees Celsius below the set temperature // if (hot_clod_flag == 1 && T <= tem - 3) // During the refrigeration process, the actual temperature drops by 0.3 degrees Celsius below the set temperature
// { // {

File diff suppressed because it is too large Load Diff

@ -208,9 +208,11 @@ void HotTestRequestTask(void *pvParameters) {
while (1) { while (1) {
if (T >= 350) { if (T >= 350) {
hot = 0; hot = 0;
hot_clod_flag = 0;
} else { } else {
hot = 0; hot = 50;
hot_clod_flag = 2;
// hot += 10; // hot += 10;
// if (hot > 100) { // if (hot > 100) {
// hot = 10; // hot = 10;
@ -231,7 +233,6 @@ void HotTestRequestTask(void *pvParameters) {
// HC595_Send_Byte(gpio_state |= 0x04); // open heater |=0000 0100 0x04 // HC595_Send_Byte(gpio_state |= 0x04); // open heater |=0000 0100 0x04
hot_clod_flag = 2;
// vTaskDelay(60000); // vTaskDelay(60000);

Loading…
Cancel
Save