如何在 PIC32 上测量性能
首先,使用 MPLab Harmony Configurator 3 为你的项目启用 CORETIMER 模块。不需要特殊配置。
PIC32 Core Timer 始终以 CPU 频率的一半运行。例如,如果 CPU 以 200 MHz 运行,Core Timer 将以 100 MHz 运行。
然后你可以使用
coretimer_counter_get.cpp
uint32_t CORETIMER_CounterGet();获取核心定时器的当前值。此外,你可以使用以下命令获取 Core Timer 的频率(以 Hz 为单位)
coretimer_frequency_get.cpp
uint32_t CORETIMER_FrequencyGet();使用以下代码片段测量运行特定函数所需的时间:
measure_function_time.cpp
uint32_t t0 = CORETIMER_CounterGet();
run_my_func();
uint32_t t1 = CORETIMER_CounterGet();之后,你可以使用例如以下命令计算运行函数所用的秒数
compute_seconds.cpp
uint32_t tdelta = t1 - t0;
float seconds = tdelta / (float)CORETIMER_FrequencyGet();或毫秒数:
compute_milliseconds.cpp
uint32_t tdelta = t1 - t0;
float milliseconds = tdelta / (CORETIMER_FrequencyGet() / 1000.0);或微秒数:
compute_microseconds.cpp
uint32_t tdelta = t1 - t0;
float microseconds = tdelta / (CORETIMER_FrequencyGet() / 1000000.0);Check out similar posts by category:
C/C++, Electronics, Embedded
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow