-
大学
《嵌入式系统设计课设》
报告书
题
目:
基于
2
8027
的虚拟系统
姓
名:
学
号:
学
院:
电气工程与自动化学院
专
业:
电气工程与自动化
年
级:
起讫日期:
指导教师:
. .
.
目
录
1
、课程设计目的
< br>.
...................................
..........................
1
2
、课程设计题目和实现目标
.
..............................
.....................
1
3
、设计方案
..........................
...............................1
4
、程序流程图
...........................
............................1
5
< br>、程序代码
...............................
..........................1
6
、
调试总结
..................................................
..............
1
7
、设计心得体会
...............................
......................1
8
、参考
文献
.....................................
....................1
.
页脚
.
.
.
.
1
、课程设计目的
< br>《嵌入式系统设计课设》
是与
《嵌入式系统设计》
课程相配套的实践教学环节。
《嵌
入式系统设
计》是一门实践性很强的专业基础课,通过课程设计,达到进一步理解嵌入
式芯片的硬件
、软件和综合应用方面的知识,培养实践能力和综合应用能力,开拓学习
积极性、主动性
,学会灵活运用已经学过的知识,并能不断接受新的知识。培养大胆发
明创造的设计理念
,为今后就业打下良好的基础。
通过课程设计,掌握以下知识和技能:
1
.
嵌入式应用系统的总体方案的设计;
2
.
嵌入式应用系统的硬件设计;
3
.
嵌入式应用系统的软件程序设计;
4
.
嵌入式开发系统的应用和调试能力
2
、课程设计题目和实现目标
<
/p>
课程设计题目:基于
28027
的虚拟系
统
任务要求:
A
、
利用<
/p>
28027
的片上温度传感器,检测当前温度;
< br>
B
、
通过
PWM
过零中断作为温度检测
A
/D
的触发,
在
PWM
中断时完成
温度采样和下一周期
PWM
占空比的修正;
PWM
频率为
1K;
C
、
利用按键作为温度给定;温度给定变化从
10
度到
40
度。
D
、
当检测
温度超过给定时,
PWM
占空比增减小
(减小幅度自己设定)
;
当检测温度小于给定时,
PWM
占空比增大(增大幅度自己设定)
;
E
、
把
PWM
输出接到捕获口,利用捕获口测量当前
p>
PWM
的占空比;
F
、
把
p>
E
测量的
PWM
占
空比通过串口通信发送给上位机;
3
、设计方案
-----
介绍系统实现
方案和系统原理图
①系统实现方案:
任务
A:
利用
ADC
模块通道
A5
获取当前环境温度
。
任务
B:PWM
< br>过零触发
ADC
模块,
在
PWM
中断服务函数中,
将当前环境温度
p>
和按键设定温度进行比较,并按照任务
D
的
要求修订
PWM
占空比。
PWM
频率为
1K HZ:
.
页脚
.
.
.
.
根据关系式:
< br>TBCLK=SYSCLKOUT/
(
HSPCLKDI
V*CLKDIV)
取
SYSCLKOUT=60M HZ,
HSPCLKDIV=6
,
CLKDIV=1
< br>,求得
TBCLK=10M HZ
。将
period
设为
10K
p>
,便得到
1K HZ
的
PWM
波。
任务
C:
用
K
EY
模块的中断实现温度给定。
任务
D
:在
PWM
的周期结束产生的中断中,通过改变比较点
CMPA
的位置
p>
来改变
PWM
占空比的大小。
任务
E
:利用
CAP
模块设置
3
个捕获
点捕获
PWM
的上升沿和下降沿,计算
得到
PWM
波的占空比。
任务
F
:利用
SCI
p>
模块实现串口通信将温度和占空比上传到上位机。
此外,各模块的配置都与
GPIO
模块有关。
②系统原理图:
28027 C2000
Piccolo Launchpad
原理图
.
页脚
.
. .
.
.
页脚
.
.
.
.
4<
/p>
、程序流程
--------
各个模块的
流程图
5
、程序代码
①
/*app.c*/
// the
includes
#include
//
**
**************************************************
*****************
*****
// the defines
.
页脚
.
. .
.
//
***************************************
******************************
*****
// the globals
//
*************
**************************************************
******
*****
//
the functions
void
delay
(
uint32_t
time)
{
while
(time--);
}
//
延时函数
// end of file
②
/*isr.c*/
// the
includes
#include
//
*************************
********************************************
*****
// the
defines
//
*************************
********************************************
*****
// the
globals
//
*************************
********************************************
*****
// the
functions
interrupt
void
LED_PWM_isr<
/p>
(
void
)
//PWM
的中断服务函数
{
if
清零
(MY_ADC
//
环境检测温度小于设定温度时
.
页脚
.
.
.
.
{
mycmp-=100*(SET_TEMP-MY_ADC);
//PWM
占空比增大
}
else
{
mycmp+=100*(MY_ADC-SET_TEMP);
//
环境检测温度大于设定温度
// PWM
占空比减小
}
PWM_setCmpA(myPwm1,mycmp);
//
设定
CmpA
值
PWM_clearIntFlag(myPwm1);
//
清零
PWM
中断标志位
PIE_clearInt(myPie,
PIE_G
roupNumber_3
);
//
PIE
中断标志位
mycmp=5000;
//
将比较点初值设为
5000
}
interrupt
void
MY_ADC_isr
p>
(
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(my
Pie,
PIE_GroupNumber_10
);
}
interrupt
void
KEY_xint1_is
r
(
void
)
//
按键中断服务函数
{
SET_TEMP++;
if
(SET_TEMP>40)
{
SET_TEMP=10;
}
PI
E_clearInt(myPie,
PIE_GroupNumber_1
);
}
interrupt
void
MY_CAP_isr
p>
(
void
)
//CAP
中断服务函数
{
uint32_t
CapEvent1Count=0,Ca
pEvent2Count=0,CapEvent3Count=0;
.
页脚
.
.
.
.
float
fPwmDuty=0.0;
CapEvent1Count = CAP_getCap1(myCap);
CapEvent2Count =
CAP_getCap2(myCap);
CapEvent3Count = CAP_getCap3(myCap);
fPwmDuty
=
(<
/p>
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(myPie,
PIE_GroupNumber_4
);
}
//redefined in
Isr.h
// end of file
①
/*F2802x_Device.h*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
.
页脚
.
.
.
.
①
/*Key.c*/
// the
includes
#include
// <
/p>
****************************************
*****************************
*****
// the defines
//
*************
**************************************************
******
*****
//
the globals
// <
/p>
****************************************
*****************************
*****
// the functions
// the function prototypes
//! brief KEY initail
//! param[in] None
//! param[out] None
void
KEY_initial<
/p>
(
void
)
{
}
//
//! brief
KEY configure
//! param[in]
None
//! param[out]
None
void
KEY_config
(
void
)
{
//
按键为
GPIO12
设置为输入口
//1. mode
.
页脚
.
.
.
.
GPIO_setMode(KEY_obj, KEY1,
GPIO_12_Mode_GeneralPurpose
);
//2.
direction
GPIO_setDirection(KEY_obj, KEY1,
GPIO_Direction_Input
);
//3.
pullup
GPIO_setPullUp(KEY_obj, KEY1,
GPIO_PullUp_Disable
);
//4.
qualification
GPIO_setQualification(KEY_obj, KEY1,
GPIO_Qual_Sync
);
}
//! brief ScanKey API
//! param[in] key
//! param[out] the state of
KEY
uint16_t
ScanKey
(
const
< br>
GPIO_Number_e
key)
{
return
GPIO_getData(KEY_obj,
key);
}
//! param[in] None
//! param[out] None
void
KEY_INT_conf
ig
(
void
)
{
//(3). register PIR
vector
PIE_registerPieIntHandler(myPie,
PIE_GroupNumber_1
,
PIE_SubGroupNumber_4
,
(
intVec_t
) &KEY_xint1_isr);
//(4). module
interrupt configure
PIE_setExtIntPo
larity(myPie
,
CPU_ExtIntNumbe
r_1
,
PIE_ExtIntPolarity_Fall
ingEdge
);
GPIO_setExtInt(myGpio,
GPIO_Number_12
,
CPU_ExtIntNumber_1
);
//(5). enable
module IE
PIE_enableExtInt(myPie,
CPU_ExtIntNumber_1
);
//(6). enable
PIEIERx.y
PIE_enableInt(myPie,
PIE_GroupNumber_1
,
PIE_InterruptSource_XINT_1
);
//(7) enable CPU
IERx
CPU_enableInt(myCpu,
CPU_IntNumber_1
);
.
页脚
.
. .
.
}
//
//! brief
Interrupt Service Routine
//! param[in] None
//! param[out] None
TARGET_EXT
interrupt
void
KEY_xint1_is
r
(
void
);
//redefined
in
Isr.h
// end of file
/*Key.h*/
#ifndef
_KEY_H_
#define
_KEY_H_
// the includes
#include
// driver
#include
#include
#ifdef
__cplusplus
extern
{
#endif
#ifndef
TARGET_GLOBAL
#define
TARGET_EXT
extern
#else
#define
TARGET_EXT
#endif
/*------- hardware
description of the example module
-------------*/
// For
example
// The module
derived from GPIO
#define
KEY_obj
myGpio
//here
myGpio
is
defined
in
System.h
#define
KEY1
GPIO_Number_12
//pin
TARGET_EXT
void
<
/p>
KEY_initial
(
void
p>
);
.
页脚
.
. .
.
TARGET_EXT
void
<
/p>
KEY_config
(
void
);
TARGET_EXT
void
KEY_INT_conf
ig
(
void
);
TARGET_EXT
interrupt
void
KEY_xint1_is
r
(
void
);
//redefined
in
Isr.h
/*-------end of hardware description
-------------*/
TARGET_EXT
uint16_t
ScanKey<
/p>
(
const
GPIO_Number_e
key);
/*-------end of API description
-------------*/
#define
KEYPressed 1
/*------- end of defines
-------------*/
#ifdef
__cplusplus
}
#endif
// extern
#endif
// end of
_EXAMPLE_H_ definition
②
/*LED_PWM.c*/
// the includes
#include
// the functions
void
LED_PWM_init
ial
(
void
)
{
mycmp=0;
}
void
LED_PWM_conf
ig
(
void
)
{
//GPIO
的配置
GPIO_setMode(myGpio,
GPIO_Number_0
,
GPIO_0_Mo
de_EPWM1A
);
GPI
O_setPullUp(myGpio,
GPIO_Number_0
,
GPIO_PullUp_Disable
);
//PWM
的配置
CLK_disableTbClockSync(myClk);
.
页脚
.
.
.
.
//PWM
模块使能
CLK_enablePwmClock(myClk,<
/p>
PWM_Number_1
);
//
设置
P
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,<
/p>
PWM_PeriodLoad_Shadow
);
//
比较点的设置
PWM_setCmpA(myPwm1,5000);
//PWM
装载模式
PWM_setLoadMode_CmpA(myPwm1,
PWM_LoadMode_Period
);
//
动作
PWM_setActionQual_CntUp_CmpA_PwmA(myPwm1,
PWM_ActionQual_Set
);
PWM_setActionQual_Period_PwmA(myPwm1,
PW
M_ActionQual_Clear
);
//
时钟同步
CLK_enableTbClockSync(myClk);
}
void
LED_PWM_INT_config
(
void
)
{
PIE_registerPieIntHandler(myPie,
PIE_GroupNumber_3
,
PIE_SubGro
upNumber_
1
,(
intVe
c_t
)&(LED_PWM_isr));
//
模块中断配置
PWM_setIntMode(myPwm1,
PWM_IntMode_CounterEqualPeriod
);
PWM_setIntPeriod(myPwm1,
p>
PWM_IntPeriod_FirstEvent
);
//PWM
中断使能
PWM_enableInt(myPwm1);
//PIE
开关的允许
PIE_enableInt(myPie,
PIE_GroupNumber_3
,
PIE_InterruptSource_EPWM1
);
//CPU
全局中断
CPU_enableInt(myCpu,
CPU_IntNumber_3
);
.
页脚
.
.
.
.
}
// end of file
/LED_PWM.h*/
#ifndef
_LED_PWM_H_
#define
_LED_PWM_H_
//
the includes
#include
// driver
#include
#include
#ifdef
__cplusplus
extern
{
#endif
#ifndef
TARGET_GLOBAL
#define
TARGET_EXT
extern
#else
#define
TARGET_EXT
#endif
/*------- hardware
description of the example module
-------------*/
TARGET_EXT
void
LED_PWM_init
ial
(
void
);
TARGET_EXT
void
<
/p>
LED_PWM_config
(
voi
d
);
TARGET_EXT
void
LED_PWM_INT_
config
(
void
);
TARGET_EXT
interrupt
void
LED_PWM_isr<
/p>
(
void
);
//redefined in Isr.h
/*-------end of hardware description
-------------*/
.
页脚
.
.
.
.
TARGET_EXT
uint16_t
mycmp;
#ifdef
__cplusplus
}
#endif
// extern
#endif
// end of _EXAMPLE_H_
definition
③
/*MY_ADC.c*/
// the includes
#include
//
the functions
void
MY_ADC_initi
al
(
void
)
{
SET_TEMP=30; //
初始设定温度为
30
摄氏度
}
void
MY_ADC_config
(
void
)
{
//ADC
时钟使能
CLK_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
,
.
页脚
.
-
-
-
-
-
-
-
-
-
上一篇:完整版freeModbus代码解读及移植笔记
下一篇:常用基础代码表解释