Download presentation
Presentation is loading. Please wait.
Published byStanley Melvin Williamson Modified 5年之前
1
介面設計專題實務 Object Teaching of Interface Design 實驗五 CPU計時器實驗
授課教師:任才俊
2
實驗目的 (a)熟悉F2812的CPU計時器。 (b)掌握F2812的CPU計時器的控制方法。
(c)學會使用CPU計時器中斷方式控制程式流程。
3
實驗說明 F2812的CPU計時器不同於事件管理器模組(EVA、EVB)中的通用計時器(GP) 。
F2812的CPU共有三個計時器,其中,CPU計時器1和2被保留用做即時操作系統OS(例如DSPBIOS),CPU計時器0可以供用戶使用。 計時器的一般操作如下:將週期暫存器PRDH:PRD中的值裝入32位元計數器暫存器TIMH:TIM。然後計數器暫存器以F281x的SYSCLKOUT速率遞減。當計數器減到0時,就會產生一個計時中斷輸出信號(一個中斷脈衝)。
4
/*************************頭文件*********************************/
#include "DSP281x_Device.h" // DSP281x Headerfile Include File #include "DSP281x_Examples.h" // DSP281x Examples Include File /*************************定義函數說明***************************/ // Prototype statements for functions found within this file. interrupt void cpu_timer0_isr(void); /*************************主程序*********************************/ void main(void) { // PLL, WatchDog, enable Peripheral Clocks // This example function is found in the DSP281x_SysCtrl.c file. InitSysCtrl(); // Disable CPU interrupts DINT; // Initialize the PIE control registers to their default state. InitPieCtrl(); // Disable CPU interrupts and clear all CPU interrupt flags: IER = 0x0000; IFR = 0x0000;
5
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR). InitPieVectTable(); // Interrupts that are used in this example are re-mapped to // ISR functions found within this file. EALLOW; // This is needed to write to EALLOW protected registers PieVectTable.TINT0 = &cpu_timer0_isr; EDIS; // This is needed to disable write to EALLOW protected registers InitCpuTimers(); // For this example, only initialize the Cpu Timers // Configure CPU-Timer 0 to interrupt every second: // 100MHz CPU Freq, 1 second Period (in uSeconds) ConfigCpuTimer(&CpuTimer0, 150, ); StartCpuTimer0(); // Enable CPU INT1 which is connected to CPU-Timer 0: IER |= M_INT1; // Enable TINT0 in the PIE: Group 1 interrupt 7 PieCtrlRegs.PIEIER1.bit.INTx7 = 1; // Enable global Interrupts and higher priority real-time debug events: EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM
8
for(;;) { if(CpuTimer0.InterruptCount<1) asm(" nop "); *(int *)0x88001=0x0081; } else if(CpuTimer0.InterruptCount<2) *(int *)0x88001=0x0042; else if(CpuTimer0.InterruptCount<3) *(int *)0x88001=0x0024; else if(CpuTimer0.InterruptCount<4) *(int *)0x88001=0x0018; else if(CpuTimer0.InterruptCount<5) { asm(" nop "); *(int *)0x88001=0x0024; } else if(CpuTimer0.InterruptCount<6) *(int *)0x88001=0x0042; else if(CpuTimer0.InterruptCount<7) *(int *)0x88001=0x0081; else CpuTimer0.InterruptCount = 0;
9
interrupt void cpu_timer0_isr(void)
{ CpuTimer0.InterruptCount++; // Acknowledge this interrupt to receive more interrupts from group 1 PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; }
10
練習題 更改範例程式,試以開關1設定LED每0.5秒動作一次;試以開關2設定LED每1秒動作一次;試以開關3設定LED每2秒動作一次;試以開關4設定LED每3秒動作一次。(不可利用中斷除頻) 設計一個跑馬燈,以遞增的方式亮燈,讓8顆LED依序點亮,開關1設定LED每0.5秒動作一輪;試以開關2設定LED每1秒動作一輪;試以開關3設定LED每2秒動作一輪;試以開關4設定LED每3秒動作一輪。(不可利用中斷除頻) 。
Similar presentations