#include <csl_timer.h>
TIMER_Handle hTimer0;
TIMER_Config TimerConfig =
{
TIMER_CTL_RMK
(
TIMER_CTL_SPND_EMUSTOP,
TIMER_CTL_INVINP_NO,
TIMER_CTL_CLKSRC_CPUOVR8, //定时器的频率是CPU频率的1/8
TIMER_CTL_CP_PULSE,
TIMER_CTL_HLD_NO, //时钟有效
TIMER_CTL_GO_NO, //时钟没有开启
TIMER_CTL_PWID_TWO,
TIMER_CTL_DATOUT_1,
TIMER_CTL_INVOUT_YES,
TIMER_CTL_FUNC_TOUT
),
0xffffffff, //定时器计数值,一旦达到该值就会产生中断,该计数值可以最大计数57秒不中断
0x0 //计数器初值
};
void Timer0_Cnt()
{
float timecnt,timeval;
hTimer0 = TIMER_open(TIMER_DEV0,TIMER_OPEN_RESET); //打开定时器0,返回操作句柄
TIMER_config(hTimer0,&TimerConfig); //使用配置结构体配置定时器0
TIMER_start(hTimer0); //开始计数
/***********此处为要计时的程序段***********/
timecnt = TIMER_getCount(hTimer0); //获取定时器的计数值
TIMER_pause(hTimer0); //停止计数
timeval = (float)(timecnt*8/600000000); //将计数值转化为时间值
printf("The time spended is %fs",timeval); //打印程序运行时间
}
CCS中使用DSP定时器的计时程序,可以精确计算某一段程序的执行时间
最新推荐文章于 2023-09-08 16:34:47 发布