資源簡介
采用stm系列單片機,根據溫度來實驗對風扇轉速的自動調節。

代碼片段和文件信息
#include?“control.h“
#include?“usart.h“
#include?“ds18b20.h“?
float?SpeedSet=2000;
float?Kp=1.2;
float?Ki=0.2;
float?Integral_MAX=230;
float?JIFEN_YUZHI=100;
float?SpeedControlOutMax=3500;
int?Encoder;
int?Moto1;
int?temperature;
int?z;
/*************************************************
??????????????????速度部分變量
*************************************************/
float?Real
??????I0
??????SpeedControlOut;
?int?real;
??/**************************************************************************
作者:平衡小車之家
我的淘寶小店:http://shop114407458.taobao.com/
**************************************************************************/
//int?Encoder;
//int?Moto1;
//int?Target_velocity;??//設定速度控制的目標速度為50個脈沖每10ms
//int?TIM2_IRQHandler(void)??
//{????
// if(TIM2->SR&0X0001)//10ms定時中斷
// {???
// ??TIM2->SR&=~(1<<0);???????????????????????????????????????//===清除定時器1中斷標志位 ?
// ??Encoder=Read_Encoder(4);?? //===讀取編碼器的值,M法測速,輸出為每10ms的脈沖數
// Encoder=Encoder*CAR_SPEED_CONSTANT;?????????????????????????????????????//===LED閃爍;指示單片機正常運行
//??? Xianfu_Pwm();????????????????????????????????????????????//===PWM限幅
// //Moto1=1000;
// ??Moto1=Incremental_PI(EncoderTarget_velocity);???????????//===速度PI控制器
//???? Set_Pwm(Moto1);??????????????????????????????????????????//===賦值給PWM寄存器??
// }???????
// ?return?0; ??
//}?
void?TIM2_IRQHandler(void)???//TIM3中斷
{
if?(TIM_GetITStatus(TIM2?TIM_IT_Update)?!=?RESET)?//檢查指定的TIM中斷發生與否:TIM?中斷源?
{
TIM_ClearITPendingBit(TIM2?TIM_IT_Update);??//清除TIMx的中斷待處理位:TIM?中斷?
Encoder=?Read_Encoder(4);
real=(int)(Encoder*(1500/334));
Moto1=(int)Incremental_PI(SpeedSet);???????????//===速度PI控制器???????????????????????????????????
TIM3->CCR2=Moto1*2;
temperature=(int)DS18B20_Get_Temp();
??????z++;
}
TIM_ClearITPendingBit(TIM2TIM_IT_Update);
}
/**************************************************************************
函數功能:賦值給PWM寄存器
入口參數:PWM
返回??值:無
**************************************************************************/
/**************************************************************************
函數功能:限制PWM賦值?
入口參數:無
返回??值:無
**************************************************************************/
/**************************************************************************
函數功能:絕對值函數
入口參數:int
返回??值:unsigned?int
**************************************************************************/
/**************************************************************************
函數功能:增量PI控制器
入口參數:編碼器測量值,目標速度
返回??值:電機PWM
根據增量式離散PID公式?
pwm+=Kp[e(k)-e(k-1)]+Ki*e(k)+Kd[e(k)-2e(k-1)+e(k-2)]
e(k)代表本次偏差?
e(k-1)代表上一次的偏差??以此類推?
pwm代表增量輸出
在我們的速度控制閉環系統里面,只使用PI控制
pwm+=Kp[e(k)-e(k-1)]+Ki*e(k)
**************************************************************************/
int?Incremental_PI?(int?Target)
{?
//???float?Kp=5Ki=1;
// ?float?PI;
?volatile?static?int?BiasLast_biasIntegral_bias;
???
?Bias=Target-real;????????????????//計算偏差
?
?if((Bias
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????3895??2019-01-02?16:38??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\CONTROL\control.c
?????文件????????486??2018-11-18?15:14??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\CONTROL\control.h
?????文件??????17273??2010-06-07?10:25??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\CORE\core_cm3.c
?????文件??????85714??2011-02-09?14:59??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\CORE\core_cm3.h
?????文件??????15503??2011-03-10?10:52??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\CORE\startup_stm32f10x_hd.s
?????文件???????3893??2015-03-13?20:05??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\HARDWARE\DS18B20\ds18b20.c
?????文件???????1208??2012-09-17?11:49??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\HARDWARE\DS18B20\ds18b20.h
?????文件???????2166??2018-12-02?12:25??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\HARDWARE\ENCODER\encoder.c
?????文件????????216??2018-11-17?10:12??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\HARDWARE\ENCODER\encoder.h
?????文件???????4731??2018-11-23?21:40??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\HARDWARE\HC05\hc05.c
?????文件????????972??2015-04-30?10:47??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\HARDWARE\HC05\hc05.h
?????文件???????1827??2018-11-24?17:11??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\HARDWARE\KEY\key.c
?????文件???????1186??2018-11-24?17:10??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\HARDWARE\KEY\key.h
?????文件???????2978??2018-11-27?19:01??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\HARDWARE\LCD\lcd1602.c
?????文件????????942??2018-11-24?22:52??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\HARDWARE\LCD\lcd1602.h
?????文件???????1298??2012-09-13?13:13??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\HARDWARE\LED\led.c
?????文件????????638??2012-09-13?09:45??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\HARDWARE\LED\led.h
?????文件????????380??2018-11-23?21:11??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\HARDWARE\MOTOR\motor.c
?????文件?????????80??2018-11-17?10:12??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\HARDWARE\MOTOR\motor.h
?????文件??????35016??2015-03-13?14:54??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\HARDWARE\TFT\font.h
?????文件??????85363??2015-04-24?11:50??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\HARDWARE\TFT\lcd.c
?????文件???????7529??2018-11-22?17:27??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\HARDWARE\TFT\lcd.h
?????文件???????7691??2018-11-27?19:12??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\HARDWARE\TIMER\timer.c
?????文件????????653??2018-11-18?20:09??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\HARDWARE\TIMER\timer.h
?????文件???????4263??2018-11-18?21:18??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\HARDWARE\USART3\usart3.c
?????文件???????1053??2015-04-30?10:47??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\HARDWARE\USART3\usart3.h
?????文件????????399??2011-04-23?10:24??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\keilkilll.bat
?????文件?????355495??2019-01-02?16:38??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\OBJ\control.crf
?????文件???????1876??2019-01-02?16:38??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\OBJ\control.d
?????文件?????391192??2019-01-02?16:38??test1?-?1602正常?1x4鍵盤?加減調速?加溫控\OBJ\control.o
............此處省略178個文件信息
評論
共有 條評論