본문 바로가기

[DSP]/DSP280x

[DSP28x EVM] Timer Interrupt Test - TMS320F2808 타이머 1초 만들기

[DSP28x EVM] Timer Interrupt Test - TMS320F2808 타이머 1초 만들기

사용자 삽입 이미지
TMS320F2808, TMS320F2812호환  EVM - 타이머 인터럽트 테스트

[DSP280x EVM]의 LED를 이용하여 1초 주기로 타이머를 구동하여 LED를 깜박이는 프로그램을 작성해 보았다.

초기화
main()
{

    :

   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, 100, 1000000);
   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

   while(1);

     :

}


//인터럽트 핸들러
//------------------------------------------------------------------
interrupt void cpu_timer0_isr(void)
{

   CpuTimer0.InterruptCount++;

   //Toggle LED
   GpioDataRegs.GPADAT.bit.GPIO6 ^= 1;

   // Acknowledge this interrupt to receive more interrupts from group 1
   PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
//------------------------------------------------------------------

void ConfigCpuTimer(struct CPUTIMER_VARS *Timer, float Freq, float Period)
{
 Uint32  temp;
 
 // Initialize timer period:
 Timer->CPUFreqInMHz = Freq;
 Timer->PeriodInUSec = Period;
 temp = (long) (Freq * Period);
 Timer->RegsAddr->PRD.all = temp;

 // Set pre-scale counter to divide by 1 (SYSCLKOUT):
 Timer->RegsAddr->TPR.all  = 0;
 Timer->RegsAddr->TPRH.all  = 0;
 
 // Initialize timer control register:
 Timer->RegsAddr->TCR.bit.TSS = 1;      // 1 = Stop timer, 0 = Start/Restart Timer
 Timer->RegsAddr->TCR.bit.TRB = 1;      // 1 = reload timer
 Timer->RegsAddr->TCR.bit.SOFT = 1;
 Timer->RegsAddr->TCR.bit.FREE = 1;     // Timer Free Run
 Timer->RegsAddr->TCR.bit.TIE = 1;      // 0 = Disable/ 1 = Enable Timer Interrupt
 
 // Reset interrupt counter:
 Timer->InterruptCount = 0;
}

반응형