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

发布时间:2024年01月09日

实验 中断和定时器试验

一、实验目的

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
文章来源:https://blog.csdn.net/m0_51993913/article/details/135469347
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。