Sunteți pe pagina 1din 3

Lab 6 - Using a Timer on DSP

Objective In this lab exercise you will learn to configure a timer and write ISR for interrupt generated by timer. 1. Create a project Timer1.pjt in your working folder in D: drive and add a new timer1.c file having the following code. This code can be copied from the file timer1.txt placed in instructors share folder.
#include <stdio.h> #include <csl.h> #include <csl_timer.h> #include <csl_irq.h> #define TIMER_CNT 20 /* Maximum count value */ static int cnt = 0; void main() { /* Initialize the chip support library, must when using CSL */ CSL_init(); IRQ_map(IRQ_EVT_TINT1, 10); // Map T1 interrupt onto INT11 IRQ_globalEnable(); // Globally enable interrupts IRQ_enable(IRQ_EVT_TINT1); // Enable T1 interrupt while(cnt <= TIMER_CNT); } /*------------------Timer 1 ISR ---------------------------Increments a count value every time when interrupt occurs and exit the program when count reaches TIMER_CNT value -------*/ void HWI_T1(void) { /* increments count value */ cnt++; /* Exit from the program when certain count is reached */ if (cnt > TIMER_CNT) { printf("\nTEST PASSED\n"); exit(0); } printf("\n Count : %3d ",cnt); return; }

2. 3.

4. 5. 6.

Create a new CDB file and save as timer1.cdb. In the left column of the Config Tool window, double-click on CSL-Chip Support Library and double-click on TIMER-Timer Device. Right-click on TIMER Configuration Manager and select Insert timerCfg. This will create timerCfg0 module. Right-click on the newly-created timer configuration module and select Properties. Under the General tab, type T1 in comment. Click on Clock Control tab. In the Input Clock Source select (CPU clock)/4. In the Clock/Pulse Mode select Clock mode. Click on Counter Control tab. In the Timer Operation select Start with reset. In the Period Value, type 0x10000. This value sets the number of clock cycles after which an interrupt will be generated. This value can be converted to time using following relation.

Interrupt period in seconds =

Period Value Clock Frequency

7.

8.

In our case Period Value is 10000 hex or 65536 decimal and clock frequency is CPU clock/4 or 225/4 = 56.25 MHz. Hence an interrupt will be generated after every 1.165 ms (65536 / 56.25 MHz = 1.165 ms). Click OK. It is a 32-bit timer and at maximum you can set 4294967295 (4.29 x 109) as period value*. Double-click on Timer Resource Manager. You will see three timers numbered from 0 to 2. Timer2 is not available in C6713 while Timer0 is not available to user. Right-click on Timer_Device1 and select Properties. Mark the two available options. In Pre-Initialize with field select timerCfg0. This is the same timer configuration module that you have created and setup in steps 3 ~ 6. Now timer 1 has been configured to interrupt CPU after every 1.165 ms. Now configure INT 10 and associate it with Timer 1. When you have configured INT 10, it should look like following. Dont forget to use dispatcher.

* 232 -1 = 4294967295

9. 10.

11. 12.

Save this CDB file as timer1.cdb and close. Add this file to project. Open Build Options dialog box and select Compiler tab. Under Basic category, select C671x as Target Version. Under Preprocessor category type CHIP_6713 in Pre-Define Symbol field. Click OK. Build, load and run the program. This program will print count values from 1 to 20 and exit.

Assignment 6 Create a new project Timer_LED. In this project, use timer1 to generate interrupt after every 2 seconds. At the occurrence of interrupt, toggle LED 0. Consequently, LED 0 will flash with 2 seconds ON and 2 seconds OFF. Hint: Use following functions to access LEDs. DSK6713_LED_init( ) [For initialization, call once at the start of code] DSK6713_LED_on(n) DSK6713_LED_off(n) DSK6713_LED_toggle(n) where n = 0, 1, 2 ,3 indicating the LED to access.

S-ar putea să vă placă și