




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、福州高校嵌入式系统设计课设报告书题 目: 基于28027的虚拟系统 姓 名: 学 号: 学 院: 电气工程与自动化学院 专 业: 电气工程与自动化 年 级: 起讫日期: 指导老师: 目 录1、课程设计目的12、课程设计题目和实现目标13、设计方案14、程序流程图15、程序代码16、调试总结17、设计心得体会18、参考文献11、课程设计目的嵌入式系统设计课设是与嵌入式系统设计课程相配套的实践教学环节。嵌入式系统设计是一门实践性很强的专业基础课,通过课程设计,达到进一步理解嵌入式芯片的硬件、软件和综合应用方面的学问,培育实践力量和综合应用力量,开拓学习乐观性、主动性,学会机敏运用已经学过的学问,并
2、能不断接受新的学问。培育大胆创造制造的设计理念,为今后就业打下良好的基础。通过课程设计,把握以下学问和技能:1 嵌入式应用系统的总体方案的设计;2 嵌入式应用系统的硬件设计;3 嵌入式应用系统的软件程序设计;4 嵌入式开发系统的应用和调试力量 2、 课程设计题目和实现目标 课程设计题目:基于28027的虚拟系统任务要求:A、 利用28027的片上温度传感器,检测当前温度;B、 通过PWM过零中断作为温度检测A/D的触发,在PWM中断时完成温度采样和下一周期PWM占空比的修正;PWM频率为1K;C、 利用按键作为温度给定;温度给定变化从10度到40度。D、 当检测温度超过给定时,PWM占空比增减
3、小(减小幅度自己设定);当检测温度小于给定时,PWM占空比增大(增大幅度自己设定);E、 把PWM输出接到捕获口,利用捕获口测量当前PWM的占空比;F、 把E测量的PWM占空比通过串口通信发送给上位机;3、 设计方案-介绍系统实现方案和系统原理图系统实现方案:任务A:利用ADC模块通道A5猎取当前环境温度。任务B:PWM过零触发ADC模块,在PWM中断服务函数中,将当前环境温度和按键设定温度进行比较,并依据任务D的要求修订PWM占空比。PWM频率为1K HZ:依据关系式:TBCLK=SYSCLKOUT/(HSPCLKDIV*CLKDIV)取SYSCLKOUT=60M HZ,HSPCLKDIV=
4、6,CLKDIV=1,求得TBCLK=10M HZ。将period设为10K,便得到1K HZ 的PWM波。任务C:用KEY模块的中断实现温度给定。任务D:在PWM的周期结束产生的中断中,通过转变比较点CMPA的位置来转变PWM占空比的大小。任务E:利用CAP模块设置3个捕获点捕获PWM的上升沿和下降沿,计算得到PWM波的占空比。任务F:利用SCI模块实现串口通信将温度和占空比上传到上位机。此外,各模块的配置都与GPIO模块有关。系统原理图:28027 C2000 Piccolo Launchpad原理图4、 程序流程-各个模块的流程图5、 程序代码/*app.c*/ the includes
5、#include "Application/app.h"/ */ the defines/ */ the globals/ */ the functions void delay(uint32_t time) while(time-); /延时函数/ end of file/*isr.c*/ the includes#include "Application/isr.h"/ */ the defines/ */ the globals/ */ the functionsinterrupt void LED_PWM_isr(void) /PWM的中断服务函
6、数if(MY_ADC<SET_TEMP) /环境检测温度小于设定温度时mycmp-=100*(SET_TEMP-MY_ADC); /PWM占空比增大elsemycmp+=100*(MY_ADC-SET_TEMP); /环境检测温度大于设定温度 / PWM占空比减小 PWM_setCmpA(myPwm1,mycmp); /设定CmpA值 PWM_clearIntFlag(myPwm1); /清零PWM中断标志位 PIE_clearInt(myPie,PIE_GroupNumber_3); /清零PIE中断标志位 mycmp=5000; /将比较点初值设为5000interrupt void
7、 MY_ADC_isr(void) /ADC中断服务函数 MY_ADC=ADC_readResult(myAdc,ADC_ResultNumber_0); /猎取ADC转换的数字量 MY_ADC= ADC_getTemperatureC(myAdc, MY_ADC);/将数字量转换为温度值ADC_clearIntFlag(myAdc, ADC_IntNumber_1);/清除中断标志位PIE_clearInt(myPie,PIE_GroupNumber_10);interrupt void KEY_xint1_isr(void) /按键中断服务函数SET_TEMP+;if(SET_TEMP&g
8、t;40)SET_TEMP=10;PIE_clearInt(myPie,PIE_GroupNumber_1);interrupt void MY_CAP_isr(void) /CAP中断服务函数uint32_t CapEvent1Count=0,CapEvent2Count=0,CapEvent3Count=0;float fPwmDuty=0.0; CapEvent1Count = CAP_getCap1(myCap); CapEvent2Count = CAP_getCap2(myCap); CapEvent3Count = CAP_getCap3(myCap); fPwmDuty = (
9、float)(CapEvent2Count - CapEvent1Count) / (CapEvent3Count - CapEvent1Count); /计算PWM占空比 fPwmDuty=fPwmDuty*100; NOW_PWM=(int)fPwmDuty; CAP_clearInt(myCap, CAP_Int_Type_CEVT3); CAP_clearInt(myCap, CAP_Int_Type_Global); / Acknowledge this interrupt to receive more interrupts from group 4 PIE_clearInt(my
10、Pie, PIE_GroupNumber_4);/redefined in Isr.h/ end of file/*F2802x_Device.h*/ #include "F2802x_Component/include/adc.h"#include "F2802x_Component/include/clk.h"#include "F2802x_Component/include/flash.h"#include "F2802x_Component/include/gpio.h"#include "F2
11、802x_Component/include/pie.h"#include "F2802x_Component/include/pll.h"#include "F2802x_Component/include/timer.h"#include "F2802x_Component/include/wdog.h"#include "F2802x_Component/include/sci.h"#include "F2802x_Component/include/cap.h"/*Key.c*
12、/ the includes#include "User_Component/Key/Key.h"/ */ the defines/ */ the globals/ */ the functions/ the function prototypes/! brief KEY initail/! paramin None/! paramout Nonevoid KEY_initial(void)/! brief KEY configure/! paramin None/! paramout Nonevoid KEY_config(void) /按键为GPIO12设置为输入口 /
13、1. modeGPIO_setMode(KEY_obj, KEY1, GPIO_12_Mode_GeneralPurpose);/2. directionGPIO_setDirection(KEY_obj, KEY1, GPIO_Direction_Input);/3. pullupGPIO_setPullUp(KEY_obj, KEY1, GPIO_PullUp_Disable);/4. qualificationGPIO_setQualification(KEY_obj, KEY1, GPIO_Qual_Sync); /! brief ScanKey API/! paramin key/!
14、 paramout the state of KEYuint16_t ScanKey(const GPIO_Number_e key)return GPIO_getData(KEY_obj, key);/! paramin None/! paramout Nonevoid KEY_INT_config(void) /(3). register PIR vectorPIE_registerPieIntHandler(myPie, PIE_GroupNumber_1, PIE_SubGroupNumber_4, (intVec_t) &KEY_xint1_isr);/(4). module
15、 interrupt configurePIE_setExtIntPolarity(myPie,CPU_ExtIntNumber_1, PIE_ExtIntPolarity_FallingEdge);GPIO_setExtInt(myGpio, GPIO_Number_12, CPU_ExtIntNumber_1);/(5). enable module IEPIE_enableExtInt(myPie, CPU_ExtIntNumber_1);/(6). enable PIEIERx.yPIE_enableInt(myPie, PIE_GroupNumber_1, PIE_Interrupt
16、Source_XINT_1);/(7) enable CPU IERxCPU_enableInt(myCpu, CPU_IntNumber_1);/! brief Interrupt Service Routine/! paramin None/! paramout NoneTARGET_EXT interrupt void KEY_xint1_isr(void); /redefined in Isr.h/ end of file/*Key.h*/#ifndef _KEY_H_#define _KEY_H_/ the includes#include <stdint.h>/ dri
17、ver#include "F2802x_Component/F2802x_Device.h"#include "User_Component/User_Mcu/User_System.h"#ifdef _cplusplusextern "C" #endif#ifndef TARGET_GLOBAL #define TARGET_EXT extern#else #define TARGET_EXT#endif/*- hardware description of the example module -*/ For example/ T
18、he module derived from GPIO#define KEY_obj myGpio /here myGpio is defined in System.h#define KEY1 GPIO_Number_12 /pinTARGET_EXT void KEY_initial(void);TARGET_EXT void KEY_config(void);TARGET_EXT void KEY_INT_config(void);TARGET_EXT interrupt void KEY_xint1_isr(void); /redefined in Isr.h/*-end of har
19、dware description -*/TARGET_EXT uint16_t ScanKey(const GPIO_Number_e key);/*-end of API description -*/#define KEYPressed 1/*- end of defines -*/#ifdef _cplusplus#endif / extern "C"#endif / end of _EXAMPLE_H_ definition/*LED_PWM.c*/ the includes#include "User_Component/LED_PWM/LED_PWM
20、.h"/ the functions void LED_PWM_initial(void) mycmp=0; void LED_PWM_config(void) /GPIO的配置 GPIO_setMode(myGpio,GPIO_Number_0,GPIO_0_Mode_EPWM1A); GPIO_setPullUp(myGpio,GPIO_Number_0,GPIO_PullUp_Disable); /PWM的配置 CLK_disableTbClockSync(myClk); /PWM模块使能 CLK_enablePwmClock(myClk,PWM_Number_1); /设置P
21、WM的时钟 /PWM_setClkDiv(myPwm1,PWM_ClkDiv_by_1); PWM_setHighSpeedClkDiv(myPwm1, PWM_HspClkDiv_by_6); /计数器的设置 PWM_setCounterMode(myPwm1,PWM_CounterMode_Up); /PWM周期设置 PWM_setPeriod(myPwm1,10000); /设置周期加载模式 PWM_setPeriodLoad(myPwm1,PWM_PeriodLoad_Shadow); /比较点的设置 PWM_setCmpA(myPwm1,5000); /PWM装载模式 PWM_set
22、LoadMode_CmpA(myPwm1,PWM_LoadMode_Period); /动作 PWM_setActionQual_CntUp_CmpA_PwmA(myPwm1,PWM_ActionQual_Set); PWM_setActionQual_Period_PwmA(myPwm1,PWM_ActionQual_Clear); /时钟同步 CLK_enableTbClockSync(myClk); void LED_PWM_INT_config(void) PIE_registerPieIntHandler(myPie,PIE_GroupNumber_3,PIE_SubGroupNum
23、ber_1,(intVec_t)&(LED_PWM_isr); /模块中断配置 PWM_setIntMode(myPwm1,PWM_IntMode_CounterEqualPeriod); PWM_setIntPeriod(myPwm1,PWM_IntPeriod_FirstEvent); /PWM中断使能 PWM_enableInt(myPwm1); /PIE开关的允许 PIE_enableInt(myPie, PIE_GroupNumber_3, PIE_InterruptSource_EPWM1); /CPU全局中断 CPU_enableInt(myCpu,CPU_IntNumb
24、er_3); / end of file/LED_PWM.h*/#ifndef _LED_PWM_H_#define _LED_PWM_H_/ the includes#include <stdint.h>/ driver#include "F2802x_Component/F2802x_Device.h"#include "User_Component/User_Mcu/User_System.h"#ifdef _cplusplusextern "C" #endif#ifndef TARGET_GLOBAL #defin
25、e TARGET_EXT extern#else #define TARGET_EXT#endif/*- hardware description of the example module -*/TARGET_EXT void LED_PWM_initial(void);TARGET_EXT void LED_PWM_config(void);TARGET_EXT void LED_PWM_INT_config(void);TARGET_EXT interrupt void LED_PWM_isr(void); /redefined in Isr.h/*-end of hardware de
26、scription -*/TARGET_EXT uint16_t mycmp;#ifdef _cplusplus#endif / extern "C"#endif / end of _EXAMPLE_H_ definition/*MY_ADC.c*/ the includes#include "User_Component/MY_ADC/MY_ADC.h"/ the functionsvoid MY_ADC_initial(void)SET_TEMP=30; /初始设定温度为30摄氏度void MY_ADC_config(void) /ADC时钟使能 C
27、LK_enableAdcClock(myClk);/初始化ADC模块 ADC_setVoltRefSrc(myAdc, ADC_VoltageRefSrc_Int); ADC_powerUp(myAdc); ADC_enableBandGap(myAdc); ADC_enableRefBuffers(myAdc); ADC_enable(myAdc); /温度转换使能 ADC_enableTempSensor(myAdc); /soc配置 ADC_setSocChanNumber(myAdc, ADC_SocNumber_0, ADC_SocChanNumber_A5); ADC_setSoc
28、SampleWindow(myAdc, ADC_SocNumber_0, ADC_SocSampleWindow_7_cycles); ADC_setSocTrigSrc(myAdc, ADC_SocNumber_0, ADC_SocTrigSrc_EPWM1_ADCSOCA); /PWM配置 PWM_setSocAPulseSrc(myPwm1,PWM_SocPulseSrc_CounterEqualZero); PWM_setSocAPeriod(myPwm1,PWM_SocPeriod_FirstEvent); PWM_enableSocAPulse(myPwm1);void MY_AD
29、C_INT_config(void)PIE_registerPieIntHandler(myPie,PIE_GroupNumber_10,PIE_SubGroupNumber_1,(intVec_t)&(MY_ADC_isr); /模块中断配置 ADC_setIntPulseGenMode(myAdc, ADC_IntPulseGenMode_Prior); ADC_setIntSrc(myAdc,ADC_IntNumber_1, ADC_IntSrc_EOC0); ADC_setIntMode(myAdc, ADC_IntNumber_1, ADC_IntMode_ClearFlag
30、); /ADC中断使能 ADC_enableInt(myAdc,ADC_IntNumber_1); /PIE开关的允许 PIE_enableInt(myPie, PIE_GroupNumber_10, PIE_InterruptSource_ADCINT_10_1); /CPU全局中断 CPU_enableInt(myCpu,CPU_IntNumber_10); / end of file/*MY_ADC.h*/#ifndef _MY_ADC_H_#define _MY_ADC_H_/ the includes#include <stdint.h>/ driver#include
31、"F2802x_Component/F2802x_Device.h"#include "User_Component/User_Mcu/User_System.h"#ifdef _cplusplusextern "C" #endif#ifndef TARGET_GLOBAL #define TARGET_EXT extern#else #define TARGET_EXT#endif/*- hardware description of the example module -*/TARGET_EXT void MY_ADC_init
32、ial(void);TARGET_EXT void MY_ADC_config(void);TARGET_EXT void MY_ADC_INT_config(void);TARGET_EXT interrupt void MY_ADC_isr(void); /redefined in Isr.h/*-end of hardware description -*/TARGET_EXT uint16_t MY_ADC;TARGET_EXT uint16_t SET_TEMP;/*- end of globals -*/#ifdef _cplusplus#endif / extern "
33、C"#endif / end of _EXAMPLE_H_ definition/*MY_CAP.c*/ the includes#include "User_Component/MY_CAP/MY_CAP.h"#include "User_Component/User_Mcu/User_System.h" void MY_CAP_initial(void)void MY_CAP_config(void)GPIO_setPullUp(myGpio, GPIO_Number_5, GPIO_PullUp_Enable);GPIO_setQuali
34、fication(myGpio, GPIO_Number_5, GPIO_Qual_Sync); GPIO_setMode(myGpio, GPIO_Number_5, GPIO_5_Mode_ECAP1); CLK_enableEcap1Clock(myClk); CAP_disableInt(myCap, CAP_Int_Type_All); / 禁止CAP中断 CAP_clearInt(myCap, CAP_Int_Type_All); / 清除CAP中断标志位 CAP_disableCaptureLoad(myCap); / Disable CAP1-CAP4 register loa
35、ds CAP_disableTimestampCounter(myCap); / Make sure the counter is stopped / Configure peripheral registers CAP_setCapContinuous(myCap); / continuous CAP_setStopWrap(myCap, CAP_Stop_Wrap_CEVT4);/ Stop at 3 events CAP_setCapEvtPolarity(myCap, CAP_Event_1, CAP_Polarity_Rising); / 捕获上升沿 CAP_setCapEvtPol
36、arity(myCap, CAP_Event_2, CAP_Polarity_Falling); / 捕获下降沿 CAP_setCapEvtPolarity(myCap, CAP_Event_3, CAP_Polarity_Rising); / 捕获上升沿 CAP_setCapEvtReset(myCap, CAP_Event_3, CAP_Reset_Enable); / 重置计数器确保计数器不会溢出 CAP_enableTimestampCounter(myCap); / 打开计数器 CAP_enableCaptureLoad(myCap); / Enable CAP1-CAP4 regi
37、ster loads /* CAP_enableInt(myCap, CAP_Int_Type_CEVT3); / 3个捕获点之后发生中断 / Register interrupt handlers in the PIE vector table PIE_registerPieIntHandler(myPie, PIE_GroupNumber_4, PIE_SubGroupNumber_1, (intVec_t)&ecap1_isr); / Enable CPU INT4 which is connected to ECAP1-4 INT:CPU_enableInt(myCpu, CP
38、U_IntNumber_4); / Enable eCAP INTn in the PIE: Group 3 interrupt 1-6 PIE_enableCaptureInt(myPie); CPU_enableGlobalInts(myCpu); */void MY_CAP_INT_config(void) CAP_enableInt(myCap, CAP_Int_Type_CEVT3); / 3 events = interrupt / Register interrupt handlers in the PIE vector table PIE_registerPieIntHandl
39、er(myPie, PIE_GroupNumber_4, PIE_SubGroupNumber_1, (intVec_t)&MY_CAP_isr); / Enable CPU INT4 which is connected to ECAP1-4 INT:CPU_enableInt(myCpu, CPU_IntNumber_4); / Enable eCAP INTn in the PIE: Group 3 interrupt 1-6 PIE_enableCaptureInt(myPie); CPU_enableGlobalInts(myCpu);/ end of file/*MY_CA
40、P.h*/#ifndef _MY_CAP_H_#define _MY_CAP_H_/ the includes#include <stdint.h>/ driver#include "F2802x_Component/F2802x_Device.h"#ifdef _cplusplusextern "C" #endif#ifndef TARGET_GLOBAL #define TARGET_EXT extern#else #define TARGET_EXT#endif/*- hardware description of the exampl
41、e module -*/TARGET_EXT void MY_CAP_initial(void);TARGET_EXT void MY_CAP_config(void);TARGET_EXT void MY_CAP_INT_config(void);TARGET_EXT interrupt void MY_CAP_isr(void); /redefined in Isr.h/*-end of hardware description -*/TARGET_EXT int NOW_PWM;#ifdef _cplusplus#endif / extern "C"#endif /
42、end of _EXAMPLE_H_ definition/*mySci.c*/ the includes#include "User_Component/mySci/mySci.h"/ the functions / the function prototypes/! brief SCI initail/! paramin None/! paramout Nonevoid SCI_initial(void)/! brief SCI configure/! paramin None/! paramout Nonevoid SCI_config(void) /1. GPIO
43、configure/1.1 pullupGPIO_setPullUp(myGpio, GPIO_Number_28, GPIO_PullUp_Enable); GPIO_setPullUp(myGpio, GPIO_Number_29, GPIO_PullUp_Disable); /1.2 input qualification GPIO_setQualification(myGpio, GPIO_Number_28, GPIO_Qual_ASync); /1.3 modeGPIO_setMode(myGpio, GPIO_Number_28, GPIO_28_Mode_SCIRXDA);/S
44、CI数据发送引脚GPIO_setMode(myGpio, GPIO_Number_29, GPIO_29_Mode_SCITXDA);/SCI数据接收引脚 /2. enable SCIA clk CLK_enableSciaClock(myClk); /3. configure the low speed peripheral clock(LSPCLK) LSPCLK = SYSCLKOUT/4 =15MHzCLK_setLowSpdPreScaler(myClk, CLK_LowSpdPreScaler_SysClkOut_by_4);/设置时钟分频 /4. SCI BRR = LSPCLK
45、/(SCI BAUDx8) - 1SCI_setBaudRate(mySci, SCI_BaudRate_9_6_kBaud);/设置波特率为9600 /5. configure package(1 stop bit, No loopback, No parity,8 char bits, async mode, idle-line protocol) SCI_disableParity(mySci); SCI_setNumStopBits(mySci, SCI_NumStopBits_One); SCI_setCharLength(mySci, SCI_CharLength_8_Bits);
46、 /6. enable SCI TX&RX SCI_enableTx(mySci); SCI_enableRx(mySci); /7.configure the SCI TX&RX FIFO/7.1 enable FIFO/先进先出 SCI_resetChannels(mySci); SCI_enableFifoEnh(mySci); /7.2 configure TX FIFO SCI_resetTxFifo(mySci); /7.3 configure RX FIFO SCI_resetRxFifo(mySci); /8. enable SCI module SCI_ena
47、ble(mySci);/! brief Transmit a string from the SCI/! paramin string/! paramout Nonevoid scia_msg(char * msg) int i; i = 0; while(msgi != '0') scia_xmit(msgi); i+; /! brief Transmit a char from the SCI/! paramin char/! paramout Nonevoid scia_xmit(int a)while(SCI_getTxFifoStatus(mySci) != SCI_
48、FifoStatus_Empty) SCI_putDataBlocking(mySci, a);/! brief Receive a char from the SCI/! paramin None/! paramout a:receive data/! 00: no received /00: receivedint scia_receive(uint16_t *a)if(SCI_getRxFifoStatus(mySci) < SCI_FifoStatus_1_Word)return 0;else *a = SCI_getData(mySci);return 1;/ end of file/*mySci.h*/#ifndef _MYSCI_H_#define _MYSCI_H_/ */ the includes#include <stdint.h>/ driver#
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 购物中心儿童游乐区运营管理与品牌合作协议
- 纳米药物研发与临床试验伦理审查合作协议
- 高端别墅房产中介独家代理销售协议
- 网络短视频与影视项目联合投资协议
- 全民健身活动赞助合作协议书
- 高清网络直播用监听音箱租赁服务协议
- 粤港澳大湾区跨境合伙企业项目投资信托合同
- 家具出口运输保险及关税豁免合同
- 个性化网络直播虚拟背景定制服务协议
- 水利枢纽安全生产责任保证书
- 肿瘤专科进修汇报护理
- 配电房防火安全施工技术措施
- 地铁乘客满意度影响因素组态效应分析:出行链视角研究
- 数学三角形的高、中线、角平分线教案2024-2025学年北师大版(2024)七年级数学下册
- 2021水闸工程运行管理规程
- (高清版)DB51∕T 1292-2011 牧草种质资源田间鉴定与评价技术规程
- 三农项目申请操作流程指南
- 组织行为学(对外经济贸易大学)知到课后答案智慧树章节测试答案2025年春对外经济贸易大学
- 贴太阳膜知识培训课件
- 面粉厂粉尘防爆培训课件
- 1000道二年级数学口算练习题
评论
0/150
提交评论