TMS320F28335定时器

来源:本站
导读:目前正在解读《TMS320F28335定时器》的相关信息,《TMS320F28335定时器》是由用户自行发布的知识型内容!下面请观看由(电工技术网 - www.9ddd.net)用户发布《TMS320F28335定时器》的详细说明。
简介:TMS320F28335定时器

CPU有3个32位定时器0/1/2。CPU定时器0和1可以给用户使用,CPU定时器2留给实时操作系统(DSP/BIOS),如果不使用DSP/BIOS,那么CPU定时器2可以在应用程序中使用。

#include "DSP28x_Project.h" // Device Headerfile and Examples Include File

void InitCpuTimers(void);

void ISRCpuTimer0(void);

void ISRCpuTimer1(void);

struct CPUTIMER_VARS CpuTimer0;

struct CPUTIMER_VARS CpuTimer1;

int count_timer0=0;

int count_timer1=0;

void main(void)

{

// Step 1. Initialize System Control:

// PLL, WatchDog, enable Peripheral Clocks

// This example function is found in the DSP2833x_SysCtrl.c file.

InitSysCtrl();

DINT;

IER=0x0000;

IFR=0x0000;

InitPieCtrl();

InitPieVectTable();

InitCpuTimers();

//第三个参数指定了定时间 定时时间

ConfigCpuTimer(&CpuTimer0, 150, 1000000);

ConfigCpuTimer(&CpuTimer1, 150, 1000000);

EALLOW;

PieVectTable.TINT0=&ISRCpuTimer0;

PieVectTable.XINT13=&ISRCpuTimer1;

EDIS;

//使能PIE模块

PieCtrlRegs.PIECTRL.bit.ENPIE=1;

//PIE通道使能

PieCtrlRegs.PIEIER1.bit.INTx7=1;

//CPU级 中断允许位

IER|=0x0001;

IER|=0x1000;

EINT;

EALLOW;

//这个寄存器是外设的控制中断寄存器,这里选择定时器1作为输入

XIntruptRegs.XNMICR.bit.SELECT=0;

EDIS;

// CpuTimer0Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0

// CpuTimer1Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0

CpuTimer0Regs.TCR.bit.TSS = 0; // Use write-only instruction to set TSS bit = 0

CpuTimer1Regs.TCR.bit.TSS = 0; // Use write-only instruction to set TSS bit = 0

while(1);

}

interrupt void ISRCpuTimer0(void)

{

count_timer0++;

PieCtrlRegs.PIEACK.bit.ACK1=1;

}

interrupt void ISRCpuTimer1(void)

{

count_timer1++;

}

void InitCpuTimers(void)

{

// CPU Timer 0

// Initialize address pointers to respective timer registers:

CpuTimer0.RegsAddr = &CpuTimer0Regs;

// Initialize timer period to maximum:

CpuTimer0Regs.PRD.all = 0xFFFFFFFF;

// Initialize pre-scale counter to divide by 1 (SYSCLKOUT):

CpuTimer0Regs.TPR.all = 0;

CpuTimer0Regs.TPRH.all = 0;

// Make sure timer is stopped:

CpuTimer0Regs.TCR.bit.TSS = 1;

// Reload all counter register with period value:

CpuTimer0Regs.TCR.bit.TRB = 1;

// Reset interrupt counters:

CpuTimer0.InterruptCount = 0;

// CPU Timer 1

// Initialize address pointers to respective timer registers:

CpuTimer1.RegsAddr = &CpuTimer1Regs;

// Initialize timer period to maximum:

CpuTimer1Regs.PRD.all = 0xFFFFFFFF;

// Initialize pre-scale counter to divide by 1 (SYSCLKOUT):

CpuTimer1Regs.TPR.all = 0;

CpuTimer1Regs.TPRH.all = 0;

// Make sure timer is stopped:

CpuTimer1Regs.TCR.bit.TSS = 1;

// Reload all counter register with period value:

CpuTimer1Regs.TCR.bit.TRB = 1;

// Reset interrupt counters:

CpuTimer1.InterruptCount = 0;

}

void ConfigCpuTimer(struct CPUTIMER_VARS *Timer, float Freq, float Period)

{

Uint32temp;

// 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 = 0;

Timer->RegsAddr->TCR.bit.FREE = 0; // Timer Free Run Disabled

//开启时钟 中断使能

Timer->RegsAddr->TCR.bit.TIE = 1; // 0 = Disable/ 1 = Enable Timer Interrupt

// Reset interrupt counter:

Timer->InterruptCount = 0;

}

//===========================================================================

// No more.

//===========================================================================

ConfigCpuTimer第三个参数指定了定时时间

提醒:《TMS320F28335定时器》最后刷新时间 2024-03-14 01:13:26,本站为公益型个人网站,仅供个人学习和记录信息,不进行任何商业性质的盈利。如果内容、图片资源失效或内容涉及侵权,请反馈至,我们会及时处理。本站只保证内容的可读性,无法保证真实性,《TMS320F28335定时器》该内容的真实性请自行鉴别。