精品資料(2021-2022年收藏)嵌入式系統(tǒng)設計課設報告分析解析_第1頁
精品資料(2021-2022年收藏)嵌入式系統(tǒng)設計課設報告分析解析_第2頁
精品資料(2021-2022年收藏)嵌入式系統(tǒng)設計課設報告分析解析_第3頁
精品資料(2021-2022年收藏)嵌入式系統(tǒng)設計課設報告分析解析_第4頁
精品資料(2021-2022年收藏)嵌入式系統(tǒng)設計課設報告分析解析_第5頁
已閱讀5頁,還剩28頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、福州大學嵌入式系統(tǒng)設計課設報告書題 目: 基于28027的虛擬系統(tǒng) 姓 名: 學 號: 學 院: 電氣工程與自動化學院 專 業(yè): 電氣工程與自動化 年 級: 起訖日期: 指導教師: 目 錄1、課程設計目的12、課程設計題目和實現目標13、設計方案14、程序流程圖15、程序代碼16、調試總結17、設計心得體會18、參考文獻11、課程設計目的嵌入式系統(tǒng)設計課設是與嵌入式系統(tǒng)設計課程相配套的實踐教學環(huán)節(jié)。嵌入式系統(tǒng)設計是一門實踐性很強的專業(yè)基礎課,通過課程設計,達到進一步理解嵌入式芯片的硬件、軟件和綜合應用方面的知識,培養(yǎng)實踐能力和綜合應用能力,開拓學習積極性、主動性,學會靈活運用已經學過的知識,并

2、能不斷接受新的知識。培養(yǎng)大膽發(fā)明創(chuàng)造的設計理念,為今后就業(yè)打下良好的基礎。通過課程設計,掌握以下知識和技能:1 嵌入式應用系統(tǒng)的總體方案的設計;2 嵌入式應用系統(tǒng)的硬件設計;3 嵌入式應用系統(tǒng)的軟件程序設計;4 嵌入式開發(fā)系統(tǒng)的應用和調試能力 2、 課程設計題目和實現目標 課程設計題目:基于28027的虛擬系統(tǒng)任務要求:A、 利用28027的片上溫度傳感器,檢測當前溫度;B、 通過PWM過零中斷作為溫度檢測A/D的觸發(fā),在PWM中斷時完成溫度采樣和下一周期PWM占空比的修正;PWM頻率為1K;C、 利用按鍵作為溫度給定;溫度給定變化從10度到40度。D、 當檢測溫度超過給定時,PWM占空比增減

3、小(減小幅度自己設定);當檢測溫度小于給定時,PWM占空比增大(增大幅度自己設定);E、 把PWM輸出接到捕獲口,利用捕獲口測量當前PWM的占空比;F、 把E測量的PWM占空比通過串口通信發(fā)送給上位機;3、 設計方案-介紹系統(tǒng)實現方案和系統(tǒng)原理圖系統(tǒng)實現方案:任務A:利用ADC模塊通道A5獲取當前環(huán)境溫度。任務B:PWM過零觸發(fā)ADC模塊,在PWM中斷服務函數中,將當前環(huán)境溫度和按鍵設定溫度進行比較,并按照任務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模塊有關。系統(tǒng)原理圖: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) /環(huán)境檢測溫度小于設定溫度時mycmp-=100*(SET_TEMP-MY_ADC); /PWM占空比增大elsemycmp+=100*(MY_ADC-SET_TEMP); /環(huán)境檢測溫度大于設定溫度 / 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個捕獲點之后發(fā)生中斷 / 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數據發(fā)送引腳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#i

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論