这段代码的定时器计数值为多少ConfigCpuTimer(&CpuTimer0, 1000, 1000000);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; }
时间: 2024-02-01 10:12:57 浏览: 36
这段代码中的定时器计数值为1000000,即每1秒钟定时器计数器会加1。在函数ConfigCpuTimer中,先初始化了定时器的频率和周期,然后根据频率和周期计算出定时器计数值temp。接着将temp赋值给定时器的PRD寄存器,表示定时器计数器达到temp时会产生定时器中断。最后根据需要设置定时器的一些控制寄存器,比如启动定时器、使能定时器中断等。
相关问题
有了这一行 ConfigCpuTimer(&CpuTimer0, 150, 1000000);,这一行的意义又在哪里CpuTimer0Regs.PRD.all=0x1528;
这两行代码在使用TI DSP芯片的CpuTimer模块时非常有用。
第一行代码 `ConfigCpuTimer(&CpuTimer0, 150, 1000000);` 是用来配置CpuTimer模块的,其中,`CpuTimer0` 是一个结构体变量,表示第一个CpuTimer模块的配置参数。具体来说,该函数设置了CpuTimer模块的时钟分频比为150,定时器周期为1秒(即1,000,000个CPU时钟周期)。这意味着,每当CpuTimer模块计数器达到1,000,000时,就会触发一个定时器中断。我们可以在中断服务程序中编写相应的处理代码,以实现一些定时操作,比如周期性地更新数据、控制设备等。
第二行代码 `CpuTimer0Regs.PRD.all=0x1528;` 则是直接设置定时器的周期寄存器(Period Register)的值。在上面的例子中,该值被设置为0x1528,即5400。这意味着,当CpuTimer模块计数器计数到5400时,就会触发一个定时器中断。这个值也可以通过 `ConfigCpuTimer` 函数的参数来设置,但是通过直接设置周期寄存器的方式更加直观易懂。
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; // Se
ems counter to zero:
Timer->RegsAddr->TIM.all = 0x0000;
// Initialize pre-scale counter to divide by 1 (SYSCLKOUT):
Timer->RegsAddr->TPR.all = 0;
// Make sure timer is stopped:
Timer->RegsAddr->TCR.bit.TSS = 1;
// Reload all counter register with period value:
Timer->RegsAddr->TCR.bit.TRB = 1;
// Reset interrupt counter:
Timer->InterruptCount = 0;
// Register interrupt handler:
Timer->IntRegsAddr->IER.all = M_INT1;
Timer->IntRegsAddr->IFR.all = M_INT1;
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
}
这是一个配置CPU定时器的函数,它主要是用来初始化一个结构体,然后根据传入的频率和周期计算出定时器的周期值,并初始化一些寄存器和计数器。最后注册中断处理程序,使得在定时器到达周期时能够触发中断。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)