1 / 24

介面設計專題實務 Object Teaching of Interface Design 實驗四 事件管理器計時器實驗

介面設計專題實務 Object Teaching of Interface Design 實驗四 事件管理器計時器實驗. 授課教師:任才俊. 實驗目的. (a) 熟悉 F2812 事件管理的計時器。 (b) 掌握 F2812 事件管理計時器控制方法。 (c) 學會使用事件管理器計時器中斷方式。. 實驗原理. 事件管理器模組 EVA 、 EVB 中都有兩個通用目的 (GP) 計時器。這些計時器在以下的應用中可以作為獨立的時基。 在控制系統中產生採樣週期。 為捕捉單元和正交編碼脈衝電路的操作提供時基。 為比較單元和與產生 PWM 輸出相關的電路提供時基。

Download Presentation

介面設計專題實務 Object Teaching of Interface Design 實驗四 事件管理器計時器實驗

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 介面設計專題實務Object Teaching of Interface Design實驗四 事件管理器計時器實驗 授課教師:任才俊

  2. 實驗目的 • (a)熟悉F2812事件管理的計時器。 • (b)掌握F2812事件管理計時器控制方法。 • (c)學會使用事件管理器計時器中斷方式。

  3. 實驗原理 • 事件管理器模組EVA、EVB中都有兩個通用目的(GP)計時器。這些計時器在以下的應用中可以作為獨立的時基。 • 在控制系統中產生採樣週期。 • 為捕捉單元和正交編碼脈衝電路的操作提供時基。 • 為比較單元和與產生PWM輸出相關的電路提供時基。 • 計時器的輸入一般有: • 內部元件(CPU)的時鐘。 • 外部時鐘TCLKINA/B,最大頻率為元件自身時鐘1/4。 • 帶有方向的輸入TDIRA/B,用於GP計時器的增/減計數模式。 • 重置信號RESET。 • 計時器的輸入一般有: • GP計時器的比較輸出TxCMPR(1、2、3、4)。 • 送給ADC模組的ADC啟動轉換信號。 • 下溢、上溢、比較匹配和週期匹配信號,送給自身的比較單元和比較邏輯。 • 計數方向指定。

  4. 實驗說明 • 8位元的數位量輸入(由八指撥開關產生)當指撥開關切到靠近LED時為低,相反為高,通過74LS244緩衝連接到DSP的資料匯流排的低8位元。8位元的數字量輸出(通過八個LED燈顯示)當對應LED點亮時說明輸出為低,熄滅時為高,通過74LS273緩衝連接到DSP的資料匯流排的低8位元。 • 實驗中採用簡單的一一映射關係來對資料位址進行驗證,目的是使實驗者能夠對資料一目了然的認識,在本實驗中,提供的資料空間配置如下: • CS2基底位址:0x8000 • CPU的資料空間:基底位址+0x8000 • 指撥開關input 8位元:通過74LS244擴充 • CPU的資料空間:基底位址+0x8001 • LED燈output 8位元:通過74LS273擴充

  5. EV Interruput

  6. /*******************************頭文件****************************//*******************************頭文件****************************/ #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 eva_timer1_isr(void); void init_eva_timer1(void); void delay(void); // Global counts used in this example Uint32 EvaTimer1InterruptCount; /*******************************主程序***********************/ 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 PIE control registers to their default state. // The default state is all PIE interrupts disabled and flags // are cleared. // This function is found in the DSP281x_PieCtrl.c file. InitPieCtrl(); // Disable CPU interrupts and clear all CPU interrupt flags: IER = 0x0000; IFR = 0x0000;

  7. // Initialize the PIE vector table with pointers to the shell Interrupt // Service Routines (ISR). // This will populate the entire table, even if the interrupt // is not used in this example. This is useful for debug purposes. // The shell ISR routines are found in DSP281x_DefaultIsr.c. // This function is found in DSP281x_PieVect.c. 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.T1PINT = &eva_timer1_isr; EDIS; // This is needed to disable write to EALLOW protected registers // This function is found in DSP281x_InitPeripherals.c // InitPeripherals(); // Not required for this example init_eva_timer1(); //User specific code, enable interrupts: // Initialize count values to 0 EvaTimer1InterruptCount = 0; // Enable PIE group 2 interrupt 4 for T1PINT PieCtrlRegs.PIEIER2.all = M_INT4; // Enable CPU INT2 for T1PINT, INT3 for T2PINT, INT4 for T3PINT // and INT5 for T4PINT: IER |= M_INT2 ; // Enable global Interrupts and higher priority real-time debug events: EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM

  8. for(;;) { if(EvaTimer1InterruptCount<10) { asm(" nop "); *(int *)0x88001=0x00aa; } else if( EvaTimer1InterruptCount<20) { asm(" nop "); *(int *)0x88001=0x0055; } else EvaTimer1InterruptCount = 0; } void delay(void) { Uint16 i,j; for(i=0;i<300;i++) for(j=0;j<6500;j++); }

  9. void init_eva_timer1(void) { // Initialize EVA Timer 1: // Setup Timer 1 Registers (EV A) EvaRegs.GPTCONA.all = 0; // Set the Period for the GP timer 1 to 0xFFFF; EvaRegs.T1PR = 0xE4E2; // Period EvaRegs.T1CMPR = 0x0000; // Compare Reg // Enable Period interrupt bits for GP timer 1 // Count up, x128, internal clk, enable compare, use own period EvaRegs.EVAIMRA.bit.T1PINT = 1; EvaRegs.EVAIFRA.bit.T1PINT = 1; // Clear the counter for GP timer 1 EvaRegs.T1CNT = 0x0000; EvaRegs.T1CON.all = 0x1742; // Start EVA ADC Conversion on timer 1 Period interrupt EvaRegs.GPTCONA.bit.T1TOADC = 2; }

  10. interrupt void eva_timer1_isr(void) { EvaTimer1InterruptCount++; // Enable more interrupts from this timer EvaRegs.EVAIMRA.bit.T1PINT = 1; // Note: To be safe, use a mask value to write to the entire // EVAIFRA register. Writing to one bit will cause a read-modify-write // operation that may have the result of writing 1's to clear // bits other then those intended. EvaRegs.EVAIFRA.all = BIT7; // Acknowledge interrupt to receive more interrupts from PIE group 2 PieCtrlRegs.PIEACK.all = PIEACK_GROUP2; }

  11. 練習題 • 試以開關1設定LED每0.5秒閃爍一次;試以開關2設定LED每1秒閃爍一次;試以開關3設定LED每1.5秒閃爍一次;試以開關4設定LED每秒閃爍一次。(0.5秒需改計數值) • 設計一個跑馬燈,以遞增的方式亮燈,每一秒讓8顆LED亮一輪。

More Related