介面設計專題實務 object teaching of interface design 實驗四...

24
介介介介介介介介 Object Teaching of Interface Design 實實實 實實實實實實實實實實 實實實實 實實實

Upload: erica-whitaker

Post on 02-Jan-2016

62 views

Category:

Documents


3 download

DESCRIPTION

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

TRANSCRIPT

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

介面設計專題實務 Object Teaching of Interface Design

實驗四 事件管理器計時器實驗

授課教師:任才俊

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

實驗目的 • (a) 熟悉 F2812 事件管理的計時器。• (b) 掌握 F2812 事件管理計時器控制方法

。• (c) 學會使用事件管理器計時器中斷方式

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

實驗原理 • 事件管理器模組 EVA 、 EVB 中都有兩個通用目的 (GP) 計時器。這些計時器在以下

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

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

實驗說明 • 8 位元的數位量輸入 ( 由八指撥開關產生 ) 當指撥開關切到靠近

LED 時為低,相反為高,通過 74LS244 緩衝連接到 DSP 的資料匯流排的低 8 位元。 8 位元的數字量輸出 ( 通過八個 LED 燈顯示 ) 當對應 LED 點亮時說明輸出為低,熄滅時為高,通過 74LS273 緩衝連接到 DSP 的資料匯流排的低 8 位元。

• 實驗中採用簡單的一一映射關係來對資料位址進行驗證,目的是使實驗者能夠對資料一目了然的認識,在本實驗中,提供的資料空間配置如下 :– CS2 基底位址: 0x8000– CPU 的資料空間:基底位址 +0x8000– 指撥開關 input 8 位元:通過 74LS244 擴充– CPU 的資料空間:基底位址 +0x8001– LED 燈 output 8 位元:通過 74LS273 擴充

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

EV Interruput

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

/*******************************頭文件 ****************************/#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 exampleUint32 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;

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

// 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 0EvaTimer1InterruptCount = 0; // Enable PIE group 2 interrupt 4 for T1PINTPieCtrlRegs.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 INTMERTM; // Enable Global realtime interrupt DBGM

Page 10: 介面設計專題實務 Object Teaching of Interface Design 實驗四 事件管理器計時器實驗
Page 11: 介面設計專題實務 Object Teaching of Interface Design 實驗四 事件管理器計時器實驗
Page 12: 介面設計專題實務 Object Teaching of Interface Design 實驗四 事件管理器計時器實驗
Page 13: 介面設計專題實務 Object Teaching of Interface Design 實驗四 事件管理器計時器實驗
Page 14: 介面設計專題實務 Object Teaching of Interface Design 實驗四 事件管理器計時器實驗

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++); }

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

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; // PeriodEvaRegs.T1CMPR = 0x0000; // Compare Reg

// Enable Period interrupt bits for GP timer 1// Count up, x128, internal clk, enable compare, use own periodEvaRegs.EVAIMRA.bit.T1PINT = 1;EvaRegs.EVAIFRA.bit.T1PINT = 1;

// Clear the counter for GP timer 1EvaRegs.T1CNT = 0x0000;EvaRegs.T1CON.all = 0x1742;

// Start EVA ADC Conversion on timer 1 Period interruptEvaRegs.GPTCONA.bit.T1TOADC = 2;

}

Page 16: 介面設計專題實務 Object Teaching of Interface Design 實驗四 事件管理器計時器實驗
Page 17: 介面設計專題實務 Object Teaching of Interface Design 實驗四 事件管理器計時器實驗
Page 18: 介面設計專題實務 Object Teaching of Interface Design 實驗四 事件管理器計時器實驗
Page 19: 介面設計專題實務 Object Teaching of Interface Design 實驗四 事件管理器計時器實驗
Page 20: 介面設計專題實務 Object Teaching of Interface Design 實驗四 事件管理器計時器實驗
Page 21: 介面設計專題實務 Object Teaching of Interface Design 實驗四 事件管理器計時器實驗
Page 22: 介面設計專題實務 Object Teaching of Interface Design 實驗四 事件管理器計時器實驗
Page 23: 介面設計專題實務 Object Teaching of Interface Design 實驗四 事件管理器計時器實驗

interrupt void eva_timer1_isr(void){

EvaTimer1InterruptCount++;

// Enable more interrupts from this timerEvaRegs.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 2PieCtrlRegs.PIEACK.all = PIEACK_GROUP2;

}

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

練習題• 試以開關 1 設定 LED 每 0.5 秒閃爍一次;試以開關 2 設定 LED 每 1 秒閃爍一次;試以開關 3 設定 LED 每 1.5 秒閃爍一次;試以開關 4 設定 LED 每秒閃爍一次。 (0.5 秒需改計數值 )

• 設計一個跑馬燈,以遞增的方式亮燈,每一秒讓 8 顆 LED 亮一輪。