关于DSP28335的CPU 定时器的配置问题
voidConfigCpuTimer(structCPUTIMER_VARS*Timer,floatFreq,floatPeriod){Uint32temp;//Init...
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 = 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;
}
能给我解释一下这段程序吗? 展开
{
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 = 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;
}
能给我解释一下这段程序吗? 展开
1个回答
展开全部
CPUFreqInMHz是DSP的实际工作频率,这个参数的单位是MHz,
PeriodInUSec是要定时的时间长度,单位是微秒
定时值=定时长度/(CPU的周期)=定时长度×CPU的频率
Timer->RegsAddr->PRD.all= temp 向定时器周期寄存器赋值
Timer->RegsAddr->TPR.all = 0;
Timer->RegsAddr->TPRH.all = 0;
上面两句是配置定时器预定标寄存器,每个定时器源时钟周期TIM(定时器计数器)减一
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
上面这五句是配置定时器控制寄存器,TSS写1,停止定时器;TRB写1,使能定时器重新装载;SOFT=0、FREE=0是配置CPU定时器仿真模式;TIE写1,CPU定时器中断使能。
以上是我的理解,我也是刚学,如有错误,还望高三指点
PeriodInUSec是要定时的时间长度,单位是微秒
定时值=定时长度/(CPU的周期)=定时长度×CPU的频率
Timer->RegsAddr->PRD.all= temp 向定时器周期寄存器赋值
Timer->RegsAddr->TPR.all = 0;
Timer->RegsAddr->TPRH.all = 0;
上面两句是配置定时器预定标寄存器,每个定时器源时钟周期TIM(定时器计数器)减一
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
上面这五句是配置定时器控制寄存器,TSS写1,停止定时器;TRB写1,使能定时器重新装载;SOFT=0、FREE=0是配置CPU定时器仿真模式;TIE写1,CPU定时器中断使能。
以上是我的理解,我也是刚学,如有错误,还望高三指点
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询