int main()
{
LCD_Configuration();
LCD_Init();
Lcd_Clear(WHITE);
RCC_Configuration();
GPIO_Configuration();
USART_Configuration();
NVIC_Configuration();
ADC_Configuration();
DMA_Configuration();
DAC_Configuration();
set_point=75; //设置给定值
p_gain=(float)(3.5);//设值比例系数
i_gain=(float)(2.2);//设置积分系数
d_gain=(float)(1.5);//设置微分系数
dead_band=2;//设置死区
pid = &warm;
integral_val=(float)(0.01);
pid_tune(&warm,p_gain,i_gain,d_gain,dead_band);// 设置PID的各个参数
while(1)
{
// DataValue=ADC_GetConversionValue(ADC1);
DAC_SetChannel1Data(DAC_Align_12b_R, 0xfff);
i=DigitFilter(DataValue,16); //滤波;
i=100*(i*1.0)/4096;
sendchar(i);
process_point=i;
pid_init(&warm,process_point,set_point); // PID参数的初始化设置测量值和给定值
pid_bumpless(&warm); // 设置最终的偏差值
if (i<set_point-10)
Escalator8bit=255;
else
Escalator8bit=(int)pid_calc(&warm);//经过PID运算后的结果
// if ((i<G-2)||(i>G+2 ))
// Escalator8bit=(int)pid_calc(&warm);//经过PID运算后的结果
// else variety(G);
// Escalator8bit=135;
// variety(set_point);
sendchar(Escalator8bit);
LCD_PutString(60,100,"给定值:",BLACK,WHITE);
LCD_PutString(60,120,"反馈值:",BLACK,WHITE);
LCD_PutString(60,140,"输出值:",BLACK,WHITE);
display(set_point,120,100);
display(i,120,120);
display(Escalator8bit,120,140);
}
}
main函数的while 循环 |