基于STM32的医用控温毯控制系统的设计-源代码

合集下载

基于STM32和增量PID算法的温度控制系统设计说明书

基于STM32和增量PID算法的温度控制系统设计说明书

5th International Conference on Advanced Materials and Computer Science (ICAMCS 2016)The constant temperature control system design based on STM32 andPID algorithmZhao Xuyang1,a and Yang Hao2,b1School of Zhao Xuyang,,China Jiliang University,Hangzhou 310000,China2School of Yang Hao,China Jiliang University,Hangzhou 310000,Chinaa ,b****************.cnKeywords: PID Algorithm;STM32;semiconductor temperature regulator;constant temperatureAbstract. Time—varying, nonlinear and multivariable coupling are characteristics of temperature. In the temperature control process, the detected temperature is often lags behind the regulation of temperature, which will cause the phenomenon such as the temperature of the controlling system overshoot and temperature oscillation. Temperature control is proposed based on incremental PID algorithm model in this paper, the system uses low-power STM32 as the main chip, DS18B20 digital temperature sensor and semiconductor temperature regulator. Experimental results show that the system can effectively maintain the temperature of the system constant.IntroductionIn natural environment, the system will generate a heat exchange which is difficult to control with the outside world, and produce unpredictable interference.During this situation it will be difficult to achieve in precise temperature controlling. When performing high-precision temperature control, temperature tends to produce overshoot phenomenon [1].Temperature control system with a lag, nonlinear and time-varying characteristics, can not establish a precise mathematical model, therefore, the use of conventional linear control theory can not achieve satisfactory control effect. semiconductor temperature controller working condition have a relationship with heat conditions and the environment factors. its work process is a non-steady state process, it needs to be addressed precisely controlled .PID control theory has a characteristic of convenient parameter setting, flexible structural change, robust and easy to implement [1,2]. the system design using incremental PID algorithm can not only solve the above problems, but also in the unsupervised, for a long time temperature will be automatically collected, automatic controlling of the semiconductor temperature controller achieves heating or cooling function, the system temperature will always be maintained constantly.Using a master chip STM32 and digital temperature sensor DS18B20 design a constant temperature system, the advantages consist of anti-interference digital signal, high sensitivity, fast response, and reasonable controlling of semiconductor temperature regulator,through the whole system design can effectively realize a special case temperature stable. within the setting temperature model of a small area in the design of a system with the column a special case. the result shows that the temperature controlling system of constant small area with very good results after analysis.System hardware designHardware System features modular designDS18B20 digital temperature sensor is placed on both sides of a special case, the datas are directly send to the master chip STM32 so that microchip could obtain temperature value, According to the requirements of the system setting temperature judgment mainly adopts the cooling method in the operation of the semiconductor temperature regulator in regulating or adjust temperature with heating methods . adjusting the way through the PID control algorithm of thetemperature read by the line processing, while the master semiconductor chip STM32 control thermostat-off, so that a special case temperature maintained at a stetted temperature. this system without manual monitoring, and data can be collected via the RS232 serial port and then the observed system temperature curve plotted, by autonomous control system effectively maintained aThe hardware system module functional designSystem functional hardware modules include temperature acquisition module, data display and export module, fan power switch module, semiconductor temperature controller module five modules.Temperature acquisition moduleTemperature acquisition module uses a digital temperature sensor DS18B20, the sensor has high measurement accuracy, the output signal is digital with anti-jamming performance, no front-end data processing module, direct access to the STM32's I / O port , the master chip can directly read data.Data display and export moduleTaking the versatility of the system into account, used in the design is one of the communication interfaces RS232 computer data communication channel, data communication is actually using a USB data format. In this communication stepper can get higher data transfer speeds, true plug and play, it can also make it easy to connect the communication between different devices.When data is displayed using USB to serial cable to the PC, using serial debugging assistant can easily read the temperature data acquisition, and also can import the data into a computer terminal for data storage. Therefore, the use of a standard interface technology can effectively solve the problem of inconsistent communication protocols [4].Fan power switch moduleWhen the semiconductor thermostat is in the cooling operation state, it is important to timely dissipate the heat, otherwise it will make semiconductor refrigeration unnormal. According to the determination of the fan work condition, by the cathode of high and low level control fan switch, the anode is normal power supply connection.This module is controlled by the master chip I / O port output level to control the fan switch purposes.Semiconductor temperature regulator moduleThe core of the temperature control system is semiconductor temperature regulator. The semiconductor temperature regulator reliability is relatively high, while the power supply terminal through the access of different polarity power supply, it can absorb heat and release heat so as to achieve the effect of refrigeration and heating. using this module is characterized by the use of a device can replace separate heating and cooling systems. precise temperature control thermostat semiconductor characteristics to facilitate the composition of automated control systems [1,2]. Figure 2 is a semiconductor temperature control circuit diagram of a switching regulator.Figure 2 Diagram of semiconductor thermostat switch control circuitSoftware system and algorithm designThe system software design process includes temperature digital signal acquisition, temperature display、PID algorithm temperature control 、temperature feedback components. The main part of the PID control algorithm is changing the value of the ambient temperature and after the feedback the temperature regulation value, it ultimately achieve the effect of Steady-State accuracy.PID algorithm designPID algorithm has a simple structure, the robust performance is good, high reliability, easy parameter setting features .P, I, D control law have their own separate areas, performing linear combination constitutes control amount, then the control amount will control objects [5,6].In the control system, a system based on real-time temperature and the set threshold value increment controls semiconductor temperature regulator operation. Therefore, the output portion of the controller is required to control the amount of incremental, in the design of the system is used incremental PID algorithm [7,8]. equation for the incremental PID algorithm is as follows.△u = A • e (k) + B •e (k-1) + C • e (k-2) (1) Where: △u increment control quantity; ratio of A, B, C as PID control, differentiation, integration coefficients; e (k), e (k-1), e (k-2) before and after the three measurements the temperature difference .Precision of the digital temperature sensor DS18B20 can reach ± 0.5 ℃, when setting the thermostat system temperature threshold, typically the change of temperature thermostat system is set within ± 0.5 ℃, partly because the system itself and the temperature sensor error performance limits; on the other hand with a time-varying temperature, constant temperature control need to constantly switch control semiconductor thermostat and fan control to a large extent, this will reduce the life of the instrument, and even burn the instrument.The main process of PID algorithm controller is parameter tuning, tuning in essence is through changing the regulator parameters to match the characteristics of properties and processes in order to improve the dynamic and static index system, so as to achieve the best control effect parameters. in tuning process, the first controller is as a pure proportional controller, form a closed loop, changing the coefficients, so that the coefficient corresponding to the input reaches a critical state (oscillation amplitude). Last in turn introduced differential and integral parameters according to attenuation 1 / 4 obtained, this attenuation can take into account the stability and rapidity.The result of the experiment and analysisReal entire test system shown in Figure 3, including the serial communication section, column oven, control panel and temperature control systems DS18B20, fans, and other semiconductor temperature regulator.Figure 3 System schematic diagramFirst obtaining room temperature, setting the thermostat system defined temperature less than room temperature, then connecting to the PC serial display interface, running the system, it will be observed that the fan is running, the positive power semiconductor thermostat is in cooling state, when the temperature is close to the serial display system the lower limit set temperature, the fan and the temperature of the semiconductor regulators are turned off, followed by heat exchange with the outside of the system will cause the temperature to rise, when the temperature rises to the set temperature limit, the fan is turning and positive power semiconductor in the temperature regulator cooling state, repeating the cooling state maintains the temperature at the set range. Column Compartment closed box is a small area, gathering room temperature is 25.4 ℃, the set temperature for the system is 20 ℃, when the permissible error set upper and lower threshold values were 20.5 ℃ and 19.5 ℃, the temperature control results shown in Figure 4Figure 4 Diagram of temperature controlling effectThe collected data of constant temperature system threshold below room temperature is as table 1. Table 1 Thermostatic system threshold below room temperature data collection formTime Left of box Middle of box Right of box0min 25.2℃ 25.4℃ 25.4℃5min 21.3℃ 20.6℃ 20.9℃10min 19.8℃ 20.1℃ 19.6℃ 20.3℃ 19.8℃ 20.1℃column oven PowersupplyDS18B20theoretical temperature, the blue curve represents the set temperature threshold. The data of Table 1 is collected at the different parts of the column oven temperature on a fixed time interval ,by this set of data can provide data support for the precise control of various parts of the column oven . variation tendency from the red curve show the actual temperature drop is divided into stages and temperature stabilization phase, after 225 seconds the system enter into the temperature stabilization phase. under the control of the incremental PID algorithm, the value of a small area of the temperature and the temperature of the theory has a good agreement, because of the exchange principle of the temperature of the nature result that the actual temperature are some errors in the data, but in the end the system could be stabilized, error is within a controllable range .by the ratio of the critical ratio method tuning PID proportion P, the integral I, differential D parameters, ideal set of data is debugged within surplus overshoot, it will be saw that the overshoot of the actual temperature curve is reduced to 17.5 % .this control process reduces the overshoot and maintain a constant temperature system efficiently and quickly.SummarySmall regional integrated climate control system is made up of a dual data collection, synchronous dual refrigeration heating control systems and incremental PID control algorithm. The algorithm combined with semiconductor temperature controller provides a set of high-precision temperature control system. solutions can effectively reduce outside interference, maintaining the temperature of the entire area of constant temperature changes in real-time monitoring system. this system temperature control effect is obvious, the structure has small size, and is suitable for most stringent temperature requirements systems, as well as the instrument cooling system, can effectively improve the instrument of practical life.AcknowledgmentsThanks to the teacher's guidance and let me join the related projects include science and technology plan projects in Zhejiang province (2015C33009), science and technology plan projects in Jiaxing (2015 AY11008)References[1] Wang Hongjie,Du Jialian,Chen Jincan,Optimization on the Performa-nce Characteristics of a Semiconductor Refrigeration System, J. R-efrigeration,1999,18(4):54-58.[2]Fan Hanbai,Xie hanhua,Semiconductor Refrigerator Temperature Con-trol System with High-precision Based on Thyristor Phase-shifted Control, J. Instrument Technique and Sensor,2012,5:103-105.[3] Cai Jinping,Li Li,The Small Area Temperature Control Model Based on Improved PID Algorithm Simulat, J. Computer Simulation,2015,32(6) :237-240.[4] Ge Leijiao,Mao Yizhi,Li Qi et al,RS232 Serial Interface Communic-ation with the C Language, J. Journal of Hebei University of Tech-nology,2008,37(6):11-16.[5] Xiao Wenjian,Li yongke,Design of Intelligent Vehicle Based on In-cremental PID Control Algorithm, J. Information technology,2012, 10:125-127.[6] Yan Xiaozhao,Zhang Xingguo,Application of Increasing PID Contro-lling Method in Temperature Controlling System, J. Journal of Nan-tong University,2006,5(4):48-51.[7] Wang Shuyan,Shi Yu,Feng Zhongxu et al ,A Method for Controlling a Loading System Based on a Fuzzy PID Controller, J. Mechanical S-cience and Technology for Aerospace Engineering,2011,30(1):166-169.[8] LI Fengman.,The Research of Controlling Arithmetic for Figure PID, J. Journal of Liaoning University,2005,32(4):367-370.。

基于stm32的远程网络温度控制系统的设计ppt

基于stm32的远程网络温度控制系统的设计ppt
③ 类R-F温度测量电路
1. 系统硬件设计
④ JTAG调试接口电路
1. 系统硬件设计
⑤ E2PROM存储电路
⑥ LCD显示电路
1. 系统硬件设计
1. 系统硬件设计
⑦ 按键与LED指示电路
1. 系统硬件设计
(3) 基嵌入式Web服务器硬件电路设计 ① 以太网控制器电路
1. 系统硬件设计
② ENC28J60与RJ45的接口电路
45℃下降 至25℃时
间(分)
25℃下降 至10℃的 超调量
(℃)
3`20 2`30
2`45
±0.4
30℃下降 至15℃的 超调量
(℃)
±0.25
15℃上升 至30℃的 超调量
(℃)
±0.5
标准值
3`00
3`00
3`00
3`00
±2
±2
±2
三. 总结与展望
总结
本文设计了一种基于STM32的远程温度控制系统,实现对远 程设备的监控,主要完成了以下内容: 1.STM32温度控制器的硬件和软件设计:以Cortex-M3内 核的STM32 为主处理器,采用增量式PID控制算法,实现对恒温培养箱内温 度的控制。 2.STM32嵌入式Web服务器硬件和软件设计:以ST公司的Cortex-M3 内核的STM32微处理器作为主处理器,扩展以太网等外围接口电 路。在移植嵌入式实时操作系统Rt-Thread和嵌入式TCP/IP协议 栈Lwip的基础上,开发了数据处理程序和通信程序。 3.增量式PID算法的研究。 4.系统调试和功能验证。

KP

ek
ek 1
T Ti
ek
Td
ek
2ek1 T

基于STM32单片机的恒温箱系统设计

基于STM32单片机的恒温箱系统设计

基于STM32单片机的恒温箱系统设计王桔;洪梅【摘要】By taking STM32F103VET single chip microcomputer( MCU) as the control processor of the system, the temperature sensor PT1000, STRVE TFT (400×240) colored LCD screen, PTC heating plate, semiconductor chilling plate, fan, the status indicator lamp and a sound and light alarm circuit are used in this design.PID control algorithm is used to control temperature in the system, when the temperature inside the box is lower then preset value, the heating piece begins to heat, when the temperature inside the box is higher than preset value, chilling plate starts to work.%设计以STM32F103VET单片机作为系统控制处理器,设计过程中使用温度传感器PT1000,STRVE TFT(400 ×240)彩色液晶显示屏,PTC加热片,半导体制冷片,风扇,状态指示灯及声光报警电路. 系统采用PID控制算法进行温度控制,当箱体内气温低于设定值时,加热片开始加热,当箱内温度高于设定值时制冷片开始工作.【期刊名称】《长春大学学报(自然科学版)》【年(卷),期】2015(025)004【总页数】5页(P13-16,21)【关键词】STM32F103VET;PT1000;半导体制冷片;温度控制【作者】王桔;洪梅【作者单位】长春大学电子信息工程学院,长春130022;长春大学电子信息工程学院,长春130022【正文语种】中文【中图分类】TP368.10 引言恒温箱是航空、汽车、家电、科研等领域必备的测试设备,用于测试和确定电工、电子及其他产品及材料进行高温试验的温度环境变化后的参数及性能,是用来在一定的温度下饲养或培养生物或生物的一部分(细胞等)的箱型器具[1]。

基于STM32单片机的恒温箱系统设计

基于STM32单片机的恒温箱系统设计
盐水 的加 温等 。
1 系统 设 计 方 案
本 系统包 括 S T M3 2 F 1 0 3核 心板 、 P T 1 0 0 0温 度传 感 器 、 放 大 电路 、 4 x 4矩 阵键 盘 、 声 光 报 警 电路 、 液 晶 显 示屏 、 驱 动 电路 、 继 电器 控制 电路 、 半导 体 制冷 片及 P T C加 热片 , 如图 1 所示 。
行 温 度控 制 , 当 箱体 内气 温低 于设 定值 时 , 加 热 片开 始 加 热 , 当 箱 内温度 高 于 设 定 值 时 制 冷 片 开 始 工 作 。 关键 词 : S T M3 2 F 1 0 3 V E T ; P T I O 0 0 ; 半导体制冷 片; 温 度 控 制
中图分类号 : T P 3 6 8 . 1
P T 1 0 0 0温 度传 感器 输 出电压 经放 大 电路 放 大后 送 到 S T M3 2 F 1 0 3核 心 板 的模 数转 换 接 V I , 转 化 成 数 字
量后 经 S T M3 2 F 1 0 3单 片机 处理 得到 相应 的温度 信 息 。在 某 一 时刻 箱 内如 果低 于 设 置 温度 则 通 过继 电器 控 制 电路使 P T C加 热 片开始 加热 , 经 H桥 驱 动 电路 正 向驱动 制冷 片使 半导 体制 冷 片开始 加热 箱体 。 当箱 内温
度 高于设 置温 度 时 , S T M3 2 F 1 0 3 单 片机 发 出控 制 指令 , 经驱 动 电路 反 向驱 动制 冷 片 使 半 导体 制 冷 片 开 始 制
冷 。在液 晶显 示屏 上显 示箱 内实 际温度 和设 置 温度 。通过 4 x 4矩 阵键 盘 输入 设 置温 度 , 也 可 以在 触摸 屏 上

【强烈推荐】基于stm32的温度控制毕业论文设计

【强烈推荐】基于stm32的温度控制毕业论文设计

摘要当前快速成形(RP)技术领域,基于喷射技术的“新一代RP技术”已经取代基于激光技术的“传统的RP技术”成为了主流;快速制造的概念已经提出并得到了广泛地使用。

熔融沉积成型(FDM)就是当前使用最广泛的一种基于喷射技术的RP技术。

本文主要对FDM温度控制系统进行了深入的分析和研究。

温度测控在食品卫生、医疗化工等工业领域具有广泛的应用。

随着传感器技术、微电子技术、单片机技术的不断发展,为智能温度测控系统测控功能的完善、测控精度的提高和抗干扰能力的增强等提供了条件。

本系统采用的STM32F103C8T6单片机是一高性能的32位机,具有丰富的硬件资源和非常强的抗干扰能力,特别适合构成智能测控仪表和工业测控系统。

本系统对STM32F103C8T6单片机硬件资源进行了开发,采用K型热敏电阻实现对温度信号的检测,充分利用单片机的硬件资源,以非常小的硬件投入,实现了对温度信号的精确检测与控制。

文中首先阐述了温度控制的必要性,温度是工业对象中的主要被控参数之一,在冶金、化工、机械、食品等各类工业中,广泛使用各种加热炉、烘箱、恒温箱等,它们均需对温度进行控制,成型室及喷头温度对成型件精度都有很大影响。

然后详细讲解了所设计的可控硅调功温度控制系统,系统采用STM32F103C8T6单片机作微控制器构建数字温度控制器,调节双向可控硅的导通角,控制电压波形,实现负载两端有效电压可变,以控制加热棒的加热功率,使温度保持在设定值。

系统主要包括:数据的采集,处理,输出,系统和上位机的通讯,人机交互部分。

该系统成本低,精度高,实现方便。

1该系统加热器温度控制采用模糊PID控制。

模糊PID控制的采用能够在控制过程中根据预先设定好的控制规律不停地自动调整控制量以使被控系统朝着设定的平衡状态过渡。

关键词:熔融沉积成型(FDM);STM32;温度控制;TCA785AbstractIn the present field of Rapid Prototyping,the "New RP Technology" based on jetting technology is replacing the "Conventional RP Technology" based on laser technology as the mainstream of the Rapid Prototyping Technology.Fused Deposition Modeling(FDM) is the most popular Rapid Prototyping technology based on jetting technology.This paper mainly does research deeply on the temperature control system of FDM system.Temperature controlling is widely to food,sanitation,medical treatment,chemistry and industry.Along with the development of sensor technology,micro-electronicstechnology and singlechip technolog,brainpower temperature controlling system is perfected,precision of measurement and controlling is enhanced and the ability of anti-jamming is swelled.Singlechip STM32F103C8T6 in this paper is a this paper.The tool of temperature test is thermocouple of K style.This system realizes precise measurement and controlling of temperature signal with a little controlparameter in industrial object.Various calefaction stoves,ovens and constant temperature boxes which all need control temperature are widely used in many industry such as metallurgy,chemistry,mechanism and foodstuff.Moulding room and spout temperatureawfully affect the precision of moulding pieces.Then the temperature control systemusing controllable silicon is explain in detail.This system adopts singlechip STM32F103C8T6 which acts as microcontroller.It can regulate the angle of double-direction controllable silicon and control voltage wave shape.So the virtual voltage of load can be changed and the calefaction power of calefaction stick can be controlled.Therefore the temperature canretain the enactment value.This system mainly consists of collection of data,disposal,output,communication of system and computer and communication of and machine.This system andconvenience realization.This system adopts blury PID control.The adoption of blury PID control canceaselessly autoregulates basing initialized controlrule,thus the controlled system willmove to the initialized balance state.Key words:Fused Deposition Modeling, STM32, temperature control, TCA785毕业设计(论文)原创性声明和使用授权说明原创性声明本人郑重承诺:所呈交的毕业设计(论文),是我个人在指导教师的指导下进行的研究工作及取得的成果。

基于stm32的温度控制

基于stm32的温度控制

摘要当前快速成形(RP)技术领域,基于喷射技术的“新一代RP技术”已经取代基于激光技术的“传统的RP技术”成为了主流;快速制造的概念已经提出并得到了广泛地使用。

熔融沉积成型(FDM)就是当前使用最广泛的一种基于喷射技术的RP 技术。

本文主要对FDM温度控制系统进行了深入的分析和研究。

温度测控在食品卫生、医疗化工等工业领域具有广泛的应用。

随着传感器技术、微电子技术、单片机技术的不断发展,为智能温度测控系统测控功能的完善、测控精度的提高和抗干扰能力的增强等提供了条件。

本系统采用的STM32F103C8T6单片机是一高性能的32位机,具有丰富的硬件资源和非常强的抗干扰能力,特别适合构成智能测控仪表和工业测控系统。

本系统对STM32F103C8T6单片机硬件资源进行了开发,采用K型热敏电阻实现对温度信号的检测,充分利用单片机的硬件资源,以非常小的硬件投入,实现了对温度信号的精确检测与控制。

文中首先阐述了温度控制的必要性,温度是工业对象中的主要被控参数之一,在冶金、化工、机械、食品等各类工业中,广泛使用各种加热炉、烘箱、恒温箱等,它们均需对温度进行控制,成型室及喷头温度对成型件精度都有很大影响。

然后详细讲解了所设计的可控硅调功温度控制系统,系统采用STM32F103C8T6单片机作微控制器构建数字温度控制器,调节双向可控硅的导通角,控制电压波形,实现负载两端有效电压可变,以控制加热棒的加热功率,使温度保持在设定值。

系统主要包括:数据的采集,处理,输出,系统和上位机的通讯,人机交互部分。

该系统成本低,精度高,实现方便。

该系统加热器温度控制采用模糊PID控制。

模糊PID控制的采用能够在控制过程中根据预先设定好的控制规律不停地自动调整控制量以使被控系统朝着设定的平衡状态过渡。

关键词:熔融沉积成型(FDM);STM32;温度控制;TCA785AbstractIn the present field of Rapid Prototyping,the "New RP Technology" based on jetting technology is replacing the "Conventional RP Technology" based on laser technology as the mainstream of the Rapid Prototyping Technology.Fused Deposition Modeling(FDM) is the most popular Rapid Prototyping technology based on jetting technology.This paper mainly does research deeply on the temperature control system of FDM system.Temperature controlling is widely to food,sanitation,medical treatment,chemistry and industry.Along with the development of sensor technology,micro-electronics technology and singlechip technolog,brainpower temperature controlling system is perfected,precision of measurement and controlling is enhanced and the ability of anti-jamming is swelled.Singlechip STM32F103C8T6 in this paper is a high-powered 32-bit chip.It has plenty of hardware resource and strong ability foranti-jamming.It is specially suitable for making brainpower measurement instrumentand industry controlling system.The hardware resource of singlechip STM32F103C8T6 is fully exploited in this paper.The tool of temperature test is thermocouple of K style.This system realizes precise measurement and controlling of temperature signal with a little hardware resource.First,the need of temperature control is expounded.Temperature is a main controlparameter in industrial object.Various calefaction stoves,ovens and constant temperature boxes which all need control temperature are widely used in many industry such as metallurgy,chemistry,mechanism and foodstuff.Moulding room and spout temperatureawfully affect the precision of moulding pieces.Then the temperature control systemusing controllable silicon is explain in detail.This system adopts singlechip STM32F103C8T6 which acts as microcontroller.It can regulate the angle of double-direction controllable silicon and control voltage wave shape.So the virtual voltage of load can be changed and the calefaction power of calefaction stick can be controlled.Therefore the temperature canretain the enactment value.This system mainly consists of collection of data,disposal,output,communication of system and computer and communication of human and machine.This system has some advantages such as low cost,high precision andconvenience realization.This system adopts blury PID control.The adoption of blury PID control canceaselessly autoregulates basing initialized control rule,thus the controlled system willmove to the initialized balance state.Key words:Fused Deposition Modeling, STM32, temperature control, TCA785目录摘要.................................................................................................................................. Abstract (I)1 绪论 01.1 FDM工艺原理及应用 01.2 FDM国内外基本研究概况 (1)1.3 课题目的及意义 (2)2 温度控制系统方案分析 (4)2.1 温度控制的必要性 (4)2.2 温度控制系统的理论构成 (4)2.3 STM32和ADC (6)2.4温度控制系统的实现 (8)3 温度控制电路各部分的实现 (10)3.1温度检测电路 (10)3.2加热部分 (16)3.3键盘显示部分 (20)3.4软件部分 (20)3.5通讯总线的研究 (21)4 总结与展望 (23)4.1全文总结 (23)4.2研究展望 (23)致谢 (26)参考文献 (27)1 绪论1.1 FDM工艺原理及应用1.1.1 熔丝沉积技术原理早在十九世纪80年代末,美国学者Scott Crump博士第一次提出一种新的思想,该思想就是熔丝沉积技术的原型。

基于STM32单片机PID温控学习系统设计

基于STM32单片机PID温控学习系统设计

• 155•本设计采用STM32F103单片机为主控芯片,采用数字型温度传感器DS18B20为温度检测器,采用3.5寸触摸液晶屏显示温度变化曲线以及PID相关参数设置,采用半导体制冷片对散热片加热,散热风扇对散热片散热,系统会根据所设参数控制半导体制冷片和散热风扇的运作。

前言:在工程实际中,应用最为广泛的调节器控制规律为比例、积分、微分控制,简称PID 控制,又称PID 调节。

它以其结构简单、稳定性好、工作可靠、调整方便而成为工业控制的主要技术之一。

温度控制在生活以及工业制造中都发挥着必不可少的作用,工业需要温度测控系统来监控温度,生活中也离不开温度测控系统为我们及时提供温度信息。

虽然只是一个简单的温度控制,却包含了许多知识的运用。

PID 实指“比例proportional ”、“积分integral ”、“微分derivative ”,这三项构成PID 基本要素。

P 代表控制系统的响应速度,越大,响应越快;I 用来积累过去时间内的误差,修正P 无法达到的期望姿态值(静差);D 加强对机体变化的快速响应。

对P 有抑制作用。

PID 各参数的整定需要综合考虑控制系统的各个方面,才能达到最佳效果。

1.总体方案设计图1 系统总体功能框图系统主要功能:(1)触摸液晶屏一方面用于温度恒定值、散热系数、PID 相关参数、温度曲线显示精度的输入;另一方面用于显示所设置的参数、被加热元件散热片的温度随时间变化曲线、当前时间等。

(2)单片机根据设置的参数通过12V 驱动模块控制半导体制冷片实际功率,达到控制半导体制冷片散热片的加热快慢。

(3)单片机根据设置的散热系数通过12V 驱动模块控制散热风扇转速,从而模拟不同情形的降温速度。

(4)单片机通过串口实时发送温度、半导体制冷片加热系数、散热风扇转速。

便于上位机对数据保存和处理。

2.硬件部分2.1 主控芯片单片机作为整个系统的核心部件,决定整个系统的性能。

单片机需要完成的主要功能有:(1)读取温度传感器所采集的温度值。

基于STM32的温度控制实验设计

基于STM32的温度控制实验设计

基于STM32的温度控制实验设计摘要:设计一种基于STM32单片机的高精度温度控制实验系统,调温范围为15~130 ℃。

系统包括测温、控制、人机交互和加热器等模块,使用DS18B20温度传感器测量温度,采用搭载ARM Cortex?M内核的STM32F429单片机作为控制核心,人机交互部分采用TFT显示屏实时显示温度,通过PWM脉冲宽度调制波驱动加热器。

该系统可以实现温度的测量变送、控制、数据存储和分析功能。

采用自适应性强的模糊PID算法,实现三个控制参数的在线修正。

不需要建立被控对象精确模型就能保证加热器功率的实时控制要求,实现较快和较稳的动态性能。

实验测试结果证明了该方法的实用性和有效性。

关键词:温度控制;温度实时显示;脉冲宽度调制;模糊PID中图分类号:TN876?34 文献标识码: A 文章编号:1004?373X(2016)12?0037?04Abstract: A high?precision temperature control experimental system based on microcontroller STM32 was designed,whose temperature range is from 15 ℃to 130 ℃. The system contains four modules of temperaturemeasurement,control,man?machine interaction and heater. DS18B20 temperature sensor is used to detect temperature. single?chip microcomputer STM32F429 with ARM Cortex?M kernel is taken as the key control unit. TFT screen is adopted in the human?computer interaction part to realize temperature real?time display. The heater is driven by pulse width modulation (PWM)wave. The system can implement the functions of transmission,control,data storage and analysis of detected temperature. The adaptive fuzzy PID algorithm is adopted to realize the on?line correction of three control parameters. It is unnecessary to establish accurate model forthe controlled object to guarantee the power control requirements of the heater,realize the fast?response and stable dynamic performance. The experimental results has proved the practicability and validity of the method.Keywords:temperature control;real?time display of temperature;PWM;fuzzy PID自控原理实验中温度控制是较复杂的非线性问题,实验教学课堂效率低,过程缓慢,误差大,较难满足教学需求[1?2]。

基于stm32的温度测量系统毕业设计

基于stm32的温度测量系统毕业设计

基于stm32的温度测量系统毕业设计目录摘要.............................................................................................................. 错误!未定义书签。

Abstract ............................................................................................................ 错误!未定义书签。

1 绪论 (1)2 系统分析 (3)2.1 STM32芯片 (3)2.2 DS18B20 (5)2.3 TFTLCD (6)2.4 ATK-HC05蓝牙串口 (7)3 硬件设计 (8)3.1 MCU (8)3.2 JTAG设计 (9)3.3 TFTLCD电路设计 (9)4 软件设计 (10)4.1 系统初始化 (10)4.1.1 时钟的初始化 (10)4.1.2 I/O初始化 (11)4.1.3 串口初始化 (13)4.1.4 DMA初始化 (15)4.1.5 中断初始化 (17)4.2 模块功能设计 (18)4.2.1 DS18B20温度模块 (18)4.2.2 TFTLCD模块设计 (21)4.2.3 ATK-HC05蓝牙模块 (24)5 结果与总结 (26)参考文献 (30)致谢.................................................................................................................. 错误!未定义书签。

1 绪论随着现代工业的不断发展,生产技术的不断进步,对于产品的精度要求也不断提高,而温度是人们生产生活中十分关注的参数,对温度的测量以及监控就显得十分重要。

基于STM32的医用控温毯控制系统的设计—设计文档

基于STM32的医用控温毯控制系统的设计—设计文档

软件设计说明书目录摘要 (3)1详细设计 (3)1 .1软件简述 (3)1 .2软件功能描述 (3)1 .3温度检测及显示模块设计 (5)1 .4热释电红外传感模块 (7)1 .5GSM短信报警模块 (8)1 .6PWM脉冲发射控制 ................................................................... 错误!未定义书签。

2编程协定 (12)2 .1操作系统 (12)2 .2调试工具 (12)2 .3编译链接工具 (12)摘要在临床医学上,往往需要对患者的全身或局部进行物理降温或升温治疗。

物理降温治疗中较为常见的是被广泛应用在神经外科、ICU、神经内科等临床科室的亚低温治疗;国际上将人体低温划分成三个范围,分别是:轻度低温(33~35℃),中度低温(17~27℃),超深低温(2~16℃),其中将轻中度低温(28~35℃)统称为亚低温[11。

研究发现,由于外部温度对脑组织细胞中与能量代谢相关的酶促反应的影响比较明显,在亚低温状态时酶促反应变慢,其能量代谢能够较正常状态减弱60%,使得脑组织能更好的耐受血氧不足的状态,这一特点使得亚低温治疗方法在治疗中重型颅脑损伤等方面有着先天优势,大量的临床应用也表明亚低温治疗脑组织损伤患者成功率更高,且尚未发现有严重的并发症发生,具有令人满意的安全性,目前国内外将亚低温治疗应用在重型和特重型颅脑损伤患者、广泛性脑挫裂伤脑水肿、原发性和继发性脑干伤、难以控制的颅内高压、中枢性高热与各种原因导致的心跳骤停等临床病症。

物理升温治疗主要应用在医疗手术及康复治疗过程中,临床研究表明,手术中或手术后会有较大的可能出现体温过低的现象,引起如心律失常、呼吸系统损坏、肾功能衰竭等并发症,对于全身麻醉时间较长的手术,需要做好相应的保温或升温措施以保证手术过程中患者的体温正常。

以往在对病人进行物理降温时常采用温水、酒精擦浴,冰袋冷敷等方式,虽然操作简单,迅速达到显著的降温效果,但是其温度控制困难,难以维持,而且需要定时更换,加重医护人员的工作量危险。

外文翻译---基于STM32的恒温箱温度控制系统

外文翻译---基于STM32的恒温箱温度控制系统

Thermo Tank Temperature Control System Based On STM32Biao QIU(····) , Shi-guang LI(····), Zheng-zhong GAO(····), Xu ZHANG(····), Yu RUI(····)(School of Information and Electrical Engineering, Shandong University of Science and Technology, Qingdao 266510, China)Abstract-this paper introduced a thermo tank temperature control system based on STM32, Firstly, the temperature acquisition is realized by the high-precision electrical bridge based on constant current source. Then the augmented PID algorithm realized by software is adopted Butterworth filter is used to convert the output PWM of STM32 to current signal which is used to control the semiconductor control rectifier to adjust the temperature. Calibration check and practical application both indicated that the system was reliable, high-precision, practicable and could meet reality needs.Key words-STM32; thermo tank; temperature acquisition; PIDManuscriptNumber:1674-8042(2011)01-0064-03Dio: 10.3969/j.issn.1674-8042.2011.01.161 introductionThermo tank can be divided into low temperature thermo tank and high temperature thermo tank according to temperature range. Heating control thermo tank is one kind of high temperature thermo tank and has a wide range of applications in industrial, medical and scientific areas. As some special thermo tank control system require high precision in temperature acquisition and control, the system designed in this paper can measure temperatures from 16℃to 80℃and its precision is superior to ±0.05℃. As ARM is gradually occupying the microelectronics market for its powerful function and low cost, it is of important practical significance and value to design a temperature control system based on ARM with high precision, simple structure and low cost. 2 Basic control principles of thermo tankIn this system, temperature acquisition of the inner thermo tank is realized by using platinum resistance as temperature sensor and bridge circuit based on constant current source. Then compare the actual temperature with the temperature set by touch screen. By using augmented PID algorithm to adjust, STM32 outputs 16-bit PWM signals. Then convert PWM signal to voltage signal to control the conduction angle of Semiconductor Control Rectifier(SCR) which controls the heating tubes. System control principle is shown in Fig.1.Considering the system accuracy and stability requirements, features of this system include: powerful and high speed ARM STM32F103 as the controller, augmented PID algorithm, and full use of on-chip resources of microcomputer such as ADC, USART and16-bit PWM output for great control accuracy.Fig 1 System control principle3 hardware designThis system includes temperature acquisition bridge circuit, STM32F103, color LCD touch screen control circuit, filtering circuit and SCR. In addition, the system has a good man-machine interaction function and can realize real-time monitoring and control by using 5.6 inches color LCD and touch screen. Temperature control system structure is shown in Fig.2.Fig 2 System structure3.1 temperature acquisition and A/D conversionAmong the thermal resistance temperature sensors, platinum resistance, with advantage as high precision, stable performance, corrosion resistance and easy to use, is the ideal temperature acquisition component widely used in industrial environments and control systems. As the temperature acquisition range is 16℃to 80℃, Pt1000 is chosen as temperature sensor, which resistance changes with temperature according to certain rules and has good high precision and stable performance.Unbalanced bridge measurement is typical in detect circuits using platinum resistance as temperature sensors[1]. However, the nonlinearity between platinum resistance and temperature and nonlinearity of unbalanced bridge lead to acquisition error, thus we improved the temperature acquisition bridge circuit. Use constant current source to power the bridge, connect the two bridge arms with precise operational amplifier that is low noise and low temperature drift, use 4DH2 to constitute constant current source circuit which outputs 0.5 A current, thus the current in platinum resistance is equal to constant current source.The ADC of STM32F103 is used to convert analog voltage of temperature into digital signal. The 12-bit ADC is a successive approximation analog-to-digital converter and has the function of self-calibration. D/D conversion of each channel can be performed in single, continuous, scan or discontinuous mode, and in this system we use continuous mode. The result of ADC is stored in right-aligned 16-bit data register which improves the conversion speed. In addition, the analog watchdog feature allows the application to detect if the input voltage goes outside the user-defined high or low thresholds.3.2 TM32F103 on-chip resourcesTM32F103 can work in -40℃~105℃and this meets the requirements of industrial environment. It incorporate the high performance ARM Cortex-M3 32-bits RISC core operating at a 72 MHz frequency, high speed embedded memories (Flash memory up to 128Kbytes and SRAM up to 20Kbytes) to store data and program, and an extensive range of enhanced I/Os, most of which have alternate functions and peripherals connected to two APB buses. It has three general purpose 16-bit timers plus two watchdogs, as well as standard and advanced communication interface USART used to communicate with LCD[2]. More importantly, it offers two 12-bit ADCs with 1μs conversion speed which make it suit for fast acquisition and fast processing. It is one of the important reasons for this system to choose TM32F103 as the core controller.3.3 Filtering and conversion circuitsIn order to realize the convention from PWM signal to analog output, we use the second order low pass filter to filter out the high frequency components and keep DC component and changing duty cycle of PWM signal so that the analog voltage output is got then. Fig.3 shows the designed Butterworth filter. After filtering, convert P WM signal to 0~2.5 V to control thyristor conduction angle[3]. Thus we realized the precise control of heating temperature.Fig 3 Butterworth filter4 Software design4.1PID control algorithmThis system uses PID control algorithm which is a basic control method widely used in industrial process control method widely used in industrial process control. Augmented PID control algorithm[4] isu k - u k- 1 = K P ( e k - e k- 1 ) + K 1 e k + K D ( e k - 2e k- 1 + e k- 2 ) .However, if this algorithm was used directly, it could generate a lare overshoot and cause integral saturation easily when starup, stop or adjust substantially. In order to inhibit the emergence of this phenomenon, we use integral separation as an improvement.Integral separation won't work until actual temperature is approaching the settings. When it works, it can eliminate static error and improve precision[5]. Block diagram of integral separation PID is shown in Fig.4.Fig 4 Integral separate PID algorithm block diagram4.2 Touch screen software designIt makes human-computer interface much more friendly, more convenient and faster by using touch screen. Use dedicated control chip ADS7843 to connect AMT9532, four-wire resistive touch screen, withSTM32F103, process the touch screen signals[6]. Touch screen's software design flow chart is shown in Fig.5.Fig 5 Touch screen flow chartUse standard thermometer with 0.001℃precision as calibration to check the experimental results. Specific methods: set different temperatures within the appropriate range though touch screen, wait until the temperatures shown in the LCD are stable, then calculate the errors based on the actual temperature of standard thermometer with formula:Error=|set-actual|/set.The check results are shown in Tab.1.Tab.1 Calibration results6 conclusionBy using 16-bit PWM output, simple filtering circuit conversion circuit, software design and floating-point operations, this system realized 16-bit D/A. Conversion which is very hard for common MCU to realize.The system temperature range is 6℃~80℃and the resolution of 16-bit control signal could reach to 10‰. The experimentalresults show that the system definitely can reach the control requirement that temperature accuracy is better than ±0.05℃. The application shows that this system has the real-time, flexible, stable high-precision, and low cost advantages, and can meet the industrial requirements of high accuracy, high stability and reliability.References[1] Zhaojun Li, Ping Ji, Xiangguang Lou, 2007, Design of high precision temperature control system. Electronic Measurement Technology. (2): 146-148.[2] ST Microelectronics Corporation, 2007. STM32F103XX Data sheet.[3] Dayong Xia, Xiaohui Zhou, Zeng Zhao, Bofeng Chen, Endian Hu,2007. Temperature control system of single-chip of model MCS-51. Industrial Instrumentation & Automation, (1):43-47.[4] Lin Wu, Enping Lou, Dongqing Hou, Liang Xu, 2006, Wireless temperature and humidity control system based on PID arithmetic. Chinese Journal of Scientific Instrument, 27(21):619-620.[5] Yan Zhao, Guangzhi Yang, 2006. Automatic measuring system in constant temperature for oxygen content based on singlechip. Chinese Journal of Scientific Instrument, s1.[6] Songmei Zhang, Junkai Liang, Longji Liu, 2008. Deign of thermo tank temperature control system based on C8051F. Electronic Measurement Technology, 31(9): 147-149.基于STM32的恒温箱温度控制系统摘要—这篇文章介绍了一个基于STM32的恒温箱温度控制系统,首先,由基于常流源的高精度电桥获取温度,然后,由软件实现的扩充型PID算法在这里得到应用,使用巴特沃兹滤波器(最平坦滤波器)将STM32输出的PWM转换成电流信号来控制半导体整流器从而调节温度,校准检测和实际应用都表明这个系统可靠、精度高、可行性好,并且能够满足现实需要。

基于PID的STM32恒温控制系统设计

基于PID的STM32恒温控制系统设计

成绩评定基于PID的STM32恒温控制系统设计摘要研究基于STM32单片机和温湿度传感器的恒温智能控制系统。

温度具有时变性、非线性和多变量耦合的特点。

在温度控制过程中,温度的检测往往滞后于温度的调控,从而会引起温度控制系统的温度出现超调、温度振荡的现象。

在设计中提出了基于增量式PID算法控制温度的模型,系统采用低功耗的STM32作为主控芯片、DHT11数字式温度传感器和半导体温度调节器。

实验结果表明,该系统能够有效地维持系统地恒温状态。

通过将数字PID算法和STM32单片机结合使用,整个控制系统的溫度控制精度也提高了,不仅仅满足了对温度控制的要求,而且还可以应用到对其他变量的控制过程中。

所以,在该温度控制系统的设计中,运用单片机STM32进行数字PID运算能充分发挥软件系统的灵活性,具有控制方便、简单和灵活性大等优点。

关键词:STM32,PID算法,恒温控制,DHT111绪论温度控制系统具有滞后性,时变性和非线性的特点。

无法建立精准的数学模型,因此使用常规的线性控制理论无法达到满意的控制效果。

在嵌入式温度控制系统中的关键是温度的测量、温度的控制和温度的保持,温度是工业控制对象中主要的被控参数之一。

因此,嵌入式要对温度的测量则是对温度进行有效及准确的测量,并且能够在工业生产中得广泛的应用,尤其在机械制造、电力工程化工生产、冶金工业等重要工业领域中,担负着重要的测量任务。

在日常工作和生活中,也被广泛应用于空调器、电加热器等各种室温测量及工业设备的温度测量。

但温度是一个模拟量,需要采用适当的技术和元件,将模拟的温度量转化为数字量,才生使用计算机进行相应的处理。

2 设计方案为了对于交流负载做到温度精确,升温采用控制双向可控硅导通角度进行升温控制。

降温采用PWM电压控制,因为当前降温采用制冷片,风扇等降温手段,采用直流电压供电方式,选用PWM控制使降温更加精确。

温度采集选用温度传感器DHT11,好处为可做到高精度,整体框图如图1所示。

基于STM32的高精度恒温控制系统设计

基于STM32的高精度恒温控制系统设计

基于STM32的高精度恒温控制系统设计黄琦;韩广源;吴瑞东;刘毅;杨世强;张明江;张建忠【摘要】针对分布式光纤拉曼测温系统中定标光纤和雪崩光电二极管(APD)的温控要求,设计了一套基于STM32的高精度恒温控制系统.系统采用上下位机结构,上位机负责设定温度值和显示温度数据,下位机根据上位机的设定值利用P ID算法对恒温箱的温度进行控制.实验结果表明:在22℃的室温下,定标光纤温度稳定在(10±0.1)℃,APD温度稳定在(5±0.005)℃,上位机可准确反映温度的数值和变化趋势.整套恒温系统能够满足分布式光纤拉曼测温系统的温控要求.%Aiming at the temperature requirements of the calibrating fiber and avalanche photo diode ( APD) in distributed optical fiber Raman temperature sensing system, a constant temperature control system with high precision was designed based on STM32. This system adopted upper and lower computers. The upper computer can set the temperature value and display tempera?ture, meanwhile, the lower computer can control the incubator temperature with the PID algorithm according to the instruction from the upper computer. The experiment results show that the calibrating fiber and the APD can stabilize at(10±0.1)℃ and(5± 0. 005)℃ at room temperature of 22 ℃.respectively, Besides, the upper computer can accurately reflect the temperature value and its variation trend. It is reasonably believed that the complete set of thermostatic device can meet the temperature demands in distributed optical fiber Raman temperature sensing system.【期刊名称】《仪表技术与传感器》【年(卷),期】2017(000)005【总页数】4页(P71-74)【关键词】STM32;高精度;温度;STemwin;PID算法【作者】黄琦;韩广源;吴瑞东;刘毅;杨世强;张明江;张建忠【作者单位】太原理工大学新型传感器与智能控制教育部与山西省重点实验室,山西太原 030024;太原理工大学物理与光电工程学院,光电工程研究所,山西太原030024;太原世诺科技有限责任公司,山西太原 030024;太原理工大学新型传感器与智能控制教育部与山西省重点实验室,山西太原 030024;太原理工大学物理与光电工程学院,光电工程研究所,山西太原 030024;太原理工大学新型传感器与智能控制教育部与山西省重点实验室,山西太原 030024;太原理工大学物理与光电工程学院,光电工程研究所,山西太原 030024;太原世诺科技有限责任公司,山西太原030024;太原理工大学新型传感器与智能控制教育部与山西省重点实验室,山西太原030024;太原理工大学物理与光电工程学院,光电工程研究所,山西太原 030024;太原理工大学新型传感器与智能控制教育部与山西省重点实验室,山西太原 030024;太原理工大学物理与光电工程学院,光电工程研究所,山西太原 030024【正文语种】中文【中图分类】TP273分布式光纤拉曼测温系统是利用后向拉曼散射光的温度效应进行温度探测的新型传感系统[1]。

基于ARM的医用控温毯的控制系统的设计

基于ARM的医用控温毯的控制系统的设计

基于ARM的医用控温毯控制系统的设计目录摘要 (I)Abstract (II)第1章绪论 (3)1.1 国内外研究现状及研究背景 (3)1.2 研究意义及目标 (4)第2章系统总体方案设计 (5)2.1 研究方案选择 (5)2.1.1 温度控制方案选择 (3)2.1.2 PWM脉冲控制原理 (4)2.2 系统总体软设计方案 (4)第3章硬件及电路设计 (6)3.1 主控电路设计 (6)3.1.1 中央处理器简介 (8)3.1.2 主控电路 (7)3.2 信号采集电路设计 (8)3.3直流斩波电路 (9)3.4 液晶接口电路设计 (10)3.5 其他电路设计 (11)3.5.1 温度报警电路 (11)3.5.2 电源电路 (11)第4章系统软件设计 (13)4.1 控制界面设计 (13)4.1.1 界面开发 (13)4.1.2 串口屏任务设计 (14)4.2 信号采集与控制任务设计 (14)4.3 时钟任务与报警任务设计 (15)第5章系统测试 (17)5.1 硬件连接测试 (17)5.2 串口屏测试 (17)5.3 传感器及报警任务测试 (18)结语 (20)参考文献 (20)附录: (22)致谢................................................................................................................ 错误!未定义书签。

摘要随着医疗科技的发展,能够进行物理控温的医疗器械控温毯的发明,解决各临床科室对于一些特殊患者的治疗难题。

但调查发现大部分医用控温毯不能够精确地进行温度控制且安全方便也有所欠缺,为了改善这些不足,本设计在参考国内外医用控温产品功能与设计的基础上,充分利用嵌入式开发及数字传感技术,提出了基于ARM芯片的医用控温毯控制系统的开发思路。

以STM32F103RC芯片为核心处理器,采用可触摸液晶屏显示实现人机交互,通过传感器釆集患者的体温、半导体制冷模块的实际温度等其他数据,控制输出不同占空比的脉冲调制信号,并利用对应的电路设计来控制温控模块使其按照操控完成温度的变化;本设计所利用的是嵌入式开发技术,使得系统可根据不同的需求进行相应的拓展与升级;为满足更高的工作性能与稳定性要求,控制系统软件设计釆用嵌入式实时操作系统uC/OS-II进行设计;采用触控操作使得系统的控制更加的人性化。

相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

void LED_GPIO_Init(void){/* 定义IO硬件初始化结构体变量*/GPIO_InitTypeDef GPIO_InitStruct;/* 使能(开启)LED引脚对应IO端口时钟*/LED1_RCC_CLK_ENABLE();LED2_RCC_CLK_ENABLE();/* 配置LED1引脚输出电压*/HAL_GPIO_WritePin(LED1_GPIO, LED1_GPIO_PIN, GPIO_PIN_RESET);/* 配置LED2引脚输出电压*/HAL_GPIO_WritePin(LED2_GPIO, LED2_GPIO_PIN, GPIO_PIN_RESET);/* 设定LED1对应引脚IO编号*/GPIO_InitStruct.Pin = LED1_GPIO_PIN;/* 设定LED1对应引脚IO为输出模式*/GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;/* 设定LED1对应引脚IO操作速度*/GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;/* 初始化LED1对应引脚IO */HAL_GPIO_Init(LED1_GPIO, &GPIO_InitStruct);/* 设定LED2对应引脚IO编号*/GPIO_InitStruct.Pin = LED2_GPIO_PIN;/* 设定LED2对应引脚IO为输出模式*/GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;/* 设定LED2对应引脚IO操作速度*/GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;/* 初始化LED2对应引脚IO */HAL_GPIO_Init(LED2_GPIO, &GPIO_InitStruct);}/*** 函数功能: 设置板载LED灯的状态* 输入参数: LEDx:其中x可甚至为(1,2,3)用来选择对应的LED灯* 输入参数:state:设置LED灯的输出状态。

* 可选值:LED_OFF:LED灯灭;* LED_ON:LED灯亮。

* LED_TOGGLE:反转LED* 返回值: 无* 说明:该函数使用类似标准库函数的编程方法,方便理解标准库函数编程思想。

*/void LEDx_StateSet(uint8_t LEDx,LEDState_TypeDef state){/* 检查输入参数是否合法*/assert_param(IS_LED_TYPEDEF(LEDx));assert_param(IS_LED_STATE(state));/* 判断设置的LED灯状态,如果设置为LED灯灭*/if(state==LED_OFF){if(LEDx & LED1)LED1_OFF;/* LED1灭*/if(LEDx & LED2)LED2_OFF;/* LED2灭*/}else if(state==LED_ON) /* 设置LED灯为亮*/{if(LEDx & LED1)LED1_ON;/* LED1亮*/if(LEDx & LED2)LED2_ON;/* LED2亮*/}else{if(LEDx & LED1)LED1_TOGGLE;/* 设置引脚输出反转*/if(LEDx & LED2)LED2_TOGGLE;/* 设置引脚输出反转*/}}void HAL_UART_MspInit(UART_HandleTypeDef* huart){GPIO_InitTypeDef GPIO_InitStruct;if(huart->Instance==DEBUG_USARTx){/* 串口外设时钟使能*/DEBUG_USART_RCC_CLK_ENABLE();/* 串口外设功能GPIO配置*/GPIO_InitStruct.Pin = DEBUG_USARTx_Tx_GPIO_PIN;GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;HAL_GPIO_Init(DEBUG_USARTx_Tx_GPIO, &GPIO_InitStruct);GPIO_InitStruct.Pin = DEBUG_USARTx_Rx_GPIO_PIN;GPIO_InitStruct.Mode = GPIO_MODE_INPUT;GPIO_InitStruct.Pull = GPIO_NOPULL;HAL_GPIO_Init(DEBUG_USARTx_Rx_GPIO, &GPIO_InitStruct); }}/*** 函数功能: 串口硬件反初始化配置* 输入参数: huart:串口句柄类型指针* 返回值: 无* 说明: 该函数被HAL库内部调用*/void HAL_UART_MspDeInit(UART_HandleTypeDef* huart){if(huart->Instance==DEBUG_USARTx){/* 串口外设时钟禁用*/DEBUG_USART_RCC_CLK_DISABLE();/* 串口外设功能GPIO配置*/HAL_GPIO_DeInit(DEBUG_USARTx_Tx_GPIO, DEBUG_USARTx_Tx_GPIO_PIN);HAL_GPIO_DeInit(DEBUG_USARTx_Rx_GPIO, DEBUG_USARTx_Rx_GPIO_PIN);/* 串口中断禁用*/HAL_NVIC_DisableIRQ(DEBUG_USART_IRQn);}}/*** 函数功能: 串口参数配置.* 输入参数: 无* 返回值: 无* 说明:无*/void MX_DEBUG_USART_Init(void){/* 使能串口功能引脚GPIO时钟*/DEBUG_USARTx_GPIO_ClK_ENABLE();husart_debug.Instance = DEBUG_USARTx;husart_debug.Init.BaudRate = DEBUG_USARTx_BAUDRATE;husart_debug.Init.WordLength = UART_WORDLENGTH_9B;husart_debug.Init.StopBits = UART_STOPBITS_1;husart_debug.Init.Parity = UART_PARITY_EVEN;husart_debug.Init.Mode = UART_MODE_TX_RX;husart_debug.Init.HwFlowCtl = UART_HWCONTROL_NONE;husart_debug.Init.OverSampling = UART_OVERSAMPLING_16;HAL_UART_Init(&husart_debug);}/*** 函数功能: 重定向c库函数printf到DEBUG_USARTx* 输入参数: 无* 返回值: 无* 说明:无*/int fputc(int ch, FILE *f){HAL_UART_Transmit(&husart_debug, (uint8_t *)&ch, 1, 0xffff);return ch;}/*** 函数功能: 重定向c库函数getchar,scanf到DEBUG_USARTx* 输入参数: 无* 返回值: 无* 说明:无*/int fgetc(FILE * f){uint8_t ch = 0;HAL_UART_Receive(&husart_debug,&ch, 1, 0xffff);return ch;}static void Show_Message(void){printf("\r\n 这是一个通过串口通信指令控制LED灯实验\n");printf("使用USART1 参数为:%d 9-E-1 \n",DEBUG_USARTx_BAUDRATE); printf("指令对应如下:\n");printf(" 指令------ 状态\n");printf(" 1 ------ LED1翻转\n");printf(" 2 ------ LED2翻转\n");}/*** 函数功能: 主函数.* 输入参数: 无* 返回值: 无* 说明: 无*/int main(void){uint8_t ch;/* 复位所有外设,初始化Flash接口和系统滴答定时器*/HAL_Init();/* 配置系统时钟*/SystemClock_Config();/* 初始化串口并配置串口中断优先级*/MX_DEBUG_USART_Init();/* 板载LED初始化*/LED_GPIO_Init();/* 打印指令输入提示信息*/Show_Message();/* 无限循环*/while (1){/* 获取字符指令*/ch=getchar();printf("接收到字符:%c\n",ch);/* 根据字符指令控制RGB彩灯颜色*/switch(ch){case '1':LED1_TOGGLE; //LED1翻转break;case '2':LED2_TOGGLE; //LED2翻转break;default:/* 如果不是指定指令字符,打印提示信息*/Show_Message();break;}}}/*** 函数功能: 系统时钟配置* 输入参数: 无* 返回值: 无* 说明: 无*/void SystemClock_Config(void){RCC_OscInitTypeDef RCC_OscInitStruct;RCC_ClkInitTypeDef RCC_ClkInitStruct;RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; // 外部晶振,8MHz RCC_OscInitStruct.HSEState = RCC_HSE_ON;RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; // 9倍频,得到72MHz主时钟HAL_RCC_OscConfig(&RCC_OscInitStruct);RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; // 系统时钟:72MHzRCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; // AHB时钟:72MHzRCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; // APB1时钟:36MHzRCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; // APB2时钟:72MHzHAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);// HAL_RCC_GetHCLKFreq()/1000 1ms中断一次// HAL_RCC_GetHCLKFreq()/100000 10us中断一次// HAL_RCC_GetHCLKFreq()/1000000 1us中断一次HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); // 配置并启动系统滴答定时器/* 系统滴答定时器时钟源*/HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);/* 系统滴答定时器中断优先级配置*/HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);}/********************************************************************************* File Name : stm32f1xx_hal_msp.c* Description : This file provides code for the MSP Initialization* and de-Initialization codes.****************************************************************************** ******************************************************************************* *//* Includes ------------------------------------------------------------------*/#include "stm32f1xx_hal.h"/* USER CODE BEGIN 0 *//* USER CODE END 0 *//*** Initializes the Global MSP.*/void HAL_MspInit(void){/* USER CODE BEGIN MspInit 0 *//* USER CODE END MspInit 0 */__HAL_RCC_AFIO_CLK_ENABLE();HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);/* System interrupt init*//* MemoryManagement_IRQn interrupt configuration */HAL_NVIC_SetPriority(MemoryManagement_IRQn, 0, 0);/* BusFault_IRQn interrupt configuration */HAL_NVIC_SetPriority(BusFault_IRQn, 0, 0);/* UsageFault_IRQn interrupt configuration */HAL_NVIC_SetPriority(UsageFault_IRQn, 0, 0);/* DebugMonitor_IRQn interrupt configuration */HAL_NVIC_SetPriority(DebugMonitor_IRQn, 0, 0);/* SysTick_IRQn interrupt configuration */HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);/* USER CODE BEGIN MspInit 1 *//* USER CODE END MspInit 1 */}/* USER CODE BEGIN 1 *//* USER CODE END 1 *//*** @}*//*** @}*//*** 函数功能: 板载按键IO引脚初始化.* 输入参数: 无* 返回值: 无* 说明:使用宏定义方法代替具体引脚号,方便程序移植,只要简单修改bsp_key.h * 文件相关宏定义就可以方便修改引脚。

相关文档
最新文档