主题中讨论的其他器件:HALCOGEN
您好!
我想为我的 TI Hercules 应用创建一个微秒计数器。
由于我正在使用 FreeRTOS、好像我无法在 HalCoGen 中激活 RTI 模块。
看了一会儿后、好像 RTOS 端口用 RTI 来 生成节拍 ISR。
有没有方法仍然可以使用 RTI 计数器1?
生成此计时器的最佳方式是什么?
此致!
加布里埃尔
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
更新:我仍然很喜欢指导、但我想出了这样的解决方案:
uint32 const free_running_counter = rtiREG1->CNT[0].FRCx; uint32 const prescale_counter = rtiREG1->CNT[0].UCx; uint32_t const compare_up_counter = (1 << rtiREG1->CNT[0].CPUCx); uint64_t const total_counter = (free_running_counter * compare_up_counter) + prescale_counter; // 1 // second = counter_value * ------------ // rti_freq uint64_t const rti_clock_frequency_MHz = (uint64_t)RTI_FREQ; //< Defined by halcogen uint64_t const microsecond = total_counter / rti_clock_frequency_MHz;
它利用了 FreeRTOS 使用的已经运行的 RTI 计时器。
不确定它是如何影响内核的。
对于 FreeRTOS、HALCoGen 仅启用1个 RTI 比较。
您可以手动添加其他 RTI 与 prvSetupTimerInterrupt()函数的比较。
portRTI_CNT0_COMP1_REG =(configCPU_CLOCK_Hz / 2)/ configTICK_RATE_Hz;
portRTI_CNT0_UDCP1_REG =(configCPU_CLOCK_Hz / 2)/ configTICK_RATE_Hz;
portRTI_SETINTENA_REG = 0x00000003U;
RTI 计数器块为64 位宽:32位预分频计数器(RTIUC0或 RTIUC1)+ 32位自由运行计数器(RTIFRC0或 RTIFRC1)
RTI 计数器块为64位宽: 32位预分频计数器(RTIUC0或 RTIUC1)+ 32位自由运行计数器(RTIFRC0或 RTIFRC1)
您不需要同时将频率计数器乘以比较递增计数器吗?
如下所示:
uint32 const free_running_counter = rtiREG1->CNT[0].FRCx; uint32 const prescale_counter = rtiREG1->CNT[0].UCx; uint32_t const compare_up_counter = (1 << rtiREG1->CNT[0].CPUCx); uint64_t const total_counter = (free_running_counter * compare_up_counter) + prescale_counter;
> 您可以手动添加其他 RTI 与 prvSetupTimerInterrupt()函数的比较。
我同意、这样做可能会更容易一些。
只需将 RTI[1]配置为以1M Hz 的频率溢出、然后只需读取溢出计数器。
自由运行时钟周期=(rtiREG1->CNT[0].CPUCx + 1)* RTI 时钟周期
TOTAL COUNTER = (rtiREG1->CNT[0].CPUCx + 1)* FREE_RUNNING_COUNTER + PRESCALE_COUNTER
我不理解您的消息中的公式: compare_up_counter =( 1 << rtiREG1->CNT[0].CPUCx);
您好、QJ:
你是对的。 位移是一个错误(因为 CPUCx == 2才起作用);
这是该代码的最终版本。
// The free running counter store the number of time the up-counter has matched with the compare up-counter. uint32_t const free_running_counter = rtiREG1->CNT[0].FRCx; // The up-counter value is stored in its counter register (RTIUCx). // RTIUCx store the number of RTICLK cycles that have elapsed since reading `free_running_counter` uint32_t const up_counter_value = rtiREG1->CNT[0].UCx; // The compare up-counter register store the threshold for the up-counter (which will trigger the increment) uint32_t const compare_up_counter_value = (rtiREG1->CNT[0].CPUCx + 1); // We can compute the total RTI tick uint32_t const total_rti_tick = (free_running_counter * compare_up_counter_value) + up_counter_value;
这已经过测试、似乎足够精确。