Convert timer value to wall time
Posted: Sun Jun 11, 2017 12:32 pm
I'm setting up a timer like this:
When I read the timer counter (with timer_get_counter_value) how can I convert this to a timer (eg in ms)? I'm currently using:
But this produces the wrong result. It's hard to say exactly how much wrong, but it's a factor of three or four out. On my system, TIMER_BASE_CLK = 80,000,000 - is that the base frequency of the timer?
Thanks for any help,
Tom
Code: Select all
timer_config_t tconf;
tconf.alarm_en = false;
tconf.auto_reload = false;
tconf.counter_dir = TIMER_COUNT_UP;
tconf.counter_en = true;
tconf.divider = 1;
timer_init(TIMER_GROUP_1, TIMER_0, &tconf);
timer_set_counter_value(TIMER_GROUP_1, TIMER_0, 0);
timer_start(TIMER_GROUP_1, TIMER_0);
Code: Select all
uint64_t value;
timer_get_counter_value(TIMER_GROUP_1, TIMER_0, &value);
uint64_t t = value / (TIMER_BASE_CLK / 1000);
Thanks for any help,
Tom