【DSP原理及应用】实验-中断和定时器试验

实验 中断和定时器试验

一、实验目的

1.通过实验熟悉 VC5509A 的定时器

2.掌握 VC5509A 定时器的控制方法

3.掌握 VC5509A 的中断结构和对中断的处理流程

4.学会 C 语言中断程序设计,以及运用中断程序控制程序流程。

二、试验设备

计算机,CCS开发环境

三、实验内容

1.编写C5509A时钟发生器初始化代码,外接晶振为20M,配置CPU工作频率为200M;

  1. 编写C5509A定时器0初始化代码及中断服务程序,使LED1 1S钟闪烁一次;

3.理解和掌握CMD文件;

4.熟悉用CCS调试程序、查看外设寄存器;

5.掌握C55X dsp的中断流程;

6.编写满足下面条件的定时器0的初始化代码。

Configure the timer to produce a 2 MHz clock source on the TIN/TOUT pin given a DSP CPU clock speed of 200 MHz. In the event of a software breakpoint or emulation halt, the timer should continue to run. If the DSP peripheral domain is set into IDLE mode, this timer should continue to run.

四、实验程序

void interrupt Timer()
{
	nCount++;
	if(nCount==1000)
	{
		LBDS^=0x01;
		nCount=0;
	}
}
void TIMER_init(void)
{
    ioport unsigned int *tim0; 
    ioport unsigned int *prd0; 
    ioport unsigned int *tcr0; 
    ioport unsigned int *prsc0;  
	tim0  =  (unsigned int *)0x1000;
	prd0  =  (unsigned int *)0x1001;
	tcr0  =  (unsigned int *)0x1002;
	prsc0 =  (unsigned int *)0x1003;
   *tcr0 =0x0c30;
   *tim0 = 0;
   *prd0 =0x4e1f;
   *prsc0 =0x0009;
   *tcr0 =0x0c20;
}
void PLL_Init(int freq)
{
    int i;
    DSPCLK dspclk;
    ioport unsigned int *clkmd;
    ioport unsigned int *sysr;
    clkmd=(unsigned int *)0x1c00;
    sysr=(unsigned int *)0x07fd;
       *clkmd=0x2502;
    *clkmd=0x2512;
    while(!(*clkmd&0x0001));
  }
TIMER_PERIOD .set 49 ;for timer period of 10 
TIMER_PRESCALE .set 1 ;for prescale value of 5 
.text 
INIT: 
mov #TIMER_PERIOD, port(#PRD0) ;configure the timer period register 
mov #TIMER_PRESCALE, port(#PRSC0) ;configure the timer prescaler register 
mov #0000110100111000b, port(#TCR0) 
;0~~~~~~~~~~~~~~~ IDLEEN 0 = do not idle with Peripheral Domain 
;~0~~~~~~~~~~~~~~ INTEXT n/a 
;~~0~~~~~~~~~~~~~ ERR_TIM 1 = if illegal function change occurs 
;~~~01~~~~~~~~~~~ FUNC 01 = TIN/TOUT pin is a timer output 
;~~~~~1~~~~~~~~~~ TLB 1 = loading from period registers 
;~~~~~~0~~~~~~~~~ SOFT n/a 
;~~~~~~~1~~~~~~~~ FREE 1 = Timer doesn’t stop on emulation halt 
;~~~~~~~~00~~~~~~ PWID n/a 
;~~~~~~~~~~1~~~~~ ARB 1 = auto-reload enabled 
;~~~~~~~~~~~1~~~~ TSS 1 = stop timer 
;~~~~~~~~~~~~1~~~ CP 0 = pulse mode, 1=clock (toggle) mode 
;~~~~~~~~~~~~~0~~ POLAR 0 = normal polarity 
;~~~~~~~~~~~~~~0~ DATOUT n/a 
;~~~~~~~~~~~~~~~0 Reserved 
and #1111101111101111b, port(#TCR0) 
;~~~~~0~~~~~~~~~~ TLB 0 = stop loading from period registers 
;~~~~~~~~~~~0~~~~ TSS 0 = start timer

这段代码主要是针对 C5509A DSP 开发板进行定时器0的初始化和中断服务程序的编写。具体内容如下:

  1. void interrupt Timer() 是中断服务程序,用于处理定时器中断。当定时器计数器 nCount 达到1000时,将 LBDS 变量的最低位取反,并将计数器 nCount 重置为0。

  2. void TIMER_init(void) 是初始化定时器0的函数,配置了 tim0prd0tcr0prsc0 四个寄存器的值,设置了定时器的初始值、定时周期、定时器控制寄存器和定时器预分频器等。

  3. void PLL_Init(int freq) 是一个初始化频率的函数,根据传入的频率参数进行一系列设置,其中涉及到 clkmdsysr 寄存器的操作,来配置 DSP 的时钟和系统寄存器。

  4. TIMER_PERIODTIMER_PRESCALE 是用来设置定时器周期和预分频值的常量。

  5. .textINIT: 是一些程序段的标签和指令,用于指示程序段的开始和初始化。

  6. 注释部分解释了 port(#TCR0) 寄存器的配置,设置了定时器控制寄存器 TCR0 的各个位的含义和作用,通过位操作进行配置,设置了定时器的工作模式和一些相关参数。

总体来说,这段代码主要是为 C5509A DSP 设置定时器0的工作模式和初始化相关寄存器,同时实现了一个中断服务程序 Timer(),当定时器计数器达到一定值时触发中断,执行相应的操作。

五、实验结果

1.指示灯在定时器的定时中断中按照设计定时闪烁。

2.使用定时器和中断服务程序可以完成许多需要定时完成的任务,比如 DSP 定时启动 A/D 转

换,日常生活中的计时器计数、空调的定时启动和关闭等。

3.在调试程序时,有时需要指示程序工作的状态,可以利用指示灯的闪烁来达到,指示灯灵活

的闪烁方式可表达多种状态信息。

寄存器配置图:

;************************************************************************** 
; TIMER Register Addresses 
;************************************************************************** 
TIM0 .set 0x1000 ; TIMER 0, Timer Count Register 
PRD0 .set 0x1001 ; TIMER 0, Timer Period Register 
TCR0 .set 0x1002 ; TIMER 0, Timer Control Register 
PRSC0 .set 0x1003 ; TIMER 0, Timer Prescaler Register 
;************************************************************************** 
; TIMER Configuration 
;************************************************************************** 
TIMER_PERIOD .set 49 ;for timer period of 50 
TIMER_PRESCALE .set 1 ;for prescale value of 2 
.text 
INIT: 
mov #TIMER_PERIOD, port(#PRD0) ;configure the timer period register 
mov #TIMER_PRESCALE, port(#PRSC0) ;configure the timer prescaler register 
mov #0000110100111000b, port(#TCR0) 
;0~~~~~~~~~~~~~~~ IDLEEN 0 = do not idle with Peripheral Domain 
;~0~~~~~~~~~~~~~~ INTEXT n/a 
;~~0~~~~~~~~~~~~~ ERR_TIM 1 = if illegal function change occurs 
;~~~01~~~~~~~~~~~ FUNC 01 = TIN/TOUT pin is a timer output 
;~~~~~1~~~~~~~~~~ TLB 1 = loading from period registers 
;~~~~~~0~~~~~~~~~ SOFT n/a 
;~~~~~~~1~~~~~~~~ FREE 1 = Timer doesn’t stop on emulation halt 
;~~~~~~~~00~~~~~~ PWID n/a 
;~~~~~~~~~~1~~~~~ ARB 1 = auto-reload enabled 
;~~~~~~~~~~~1~~~~ TSS 1 = stop timer 
;~~~~~~~~~~~~1~~~ CP 0 = pulse mode, 1=clock (toggle) mode 
;~~~~~~~~~~~~~0~~ POLAR 0 = normal polarity 
;~~~~~~~~~~~~~~0~ DATOUT n/a 
;~~~~~~~~~~~~~~~0 Reserved 
and #1111101111101111b, port(#TCR0) 
;~~~~~0~~~~~~~~~~ TLB 0 = stop loading from period registers 
;~~~~~~~~~~~0~~~~ TSS 0 = start timer
  • 24
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值