Page 1 of 1

high precision timer

Posted: Mon Apr 02, 2018 10:42 pm
by Reiner1210
Hello,

I know that with esp_timer_get_time() I can get a timestamp on µsec base. Is there an even better time base resolution possible? Idea behind: Build a low budget logic analyzer. For this the edges of a signal must have very exact timestamps.
An other question: What is the highest frequency on a GPIO input which should trigger an interrupt. Can I go up to some MHz ?

Reiner

Re: high precision timer

Posted: Mon Apr 02, 2018 10:55 pm
by WiFive

Re: high precision timer

Posted: Tue Apr 03, 2018 7:25 am
by Cellie
I recently stumbled upon this repo:
https://github.com/botofancalin/M5Stack ... cilloscope
Might find some info there.

Re: high precision timer

Posted: Fri Apr 06, 2018 9:12 am
by Reiner1210
Thanks @WiFive

The following pseudo code will do it

#include "soc/cpu.h"
#include "esp_clk.h"

uint32_t cycle_counts;
uint32_t cycle_counts_last = 0;
int clock_freq = esp_clk_cpu_freq();

RSR(CCOUNT, cycle_counts);
printf("Diff: %llu nsec\n", ((uint64_t)(cycle_counts - cycle_counts_last)*1000000000) / clock_freq);
cycle_counts_last = cycle_counts;