ESP32 timer

tosemusername
Posts: 6
Joined: Tue Feb 05, 2019 5:28 pm

ESP32 timer

Postby tosemusername » Tue Sep 17, 2019 5:01 pm

1. What is the point of a prescaler anyway? From what I understand, it scales down the clock count, which basically reduces the resolution of the counter.
2. Why would that be good or intended? There must be a very good reason why hardware makers would put that in a CPU, and why is that?

Moving on to the ESP32 specific part...

3. Is the timer divider here...
https://github.com/espressif/esp-idf/bl ... imer.h#L85
effectively the value that's applied to the prescaler?

Context for question 4 and 5. Feel free to point out any mistakes in any of my questions and assumptions, especially the ones that follow.
Given that this
https://github.com/espressif/esp-idf/bl ... soc.h#L242
and this
https://github.com/espressif/esp-idf/bl ... main.c#L19 mean exactly the same thing, and the former one is hardcoded, I take that the ESP32 timer is the main system clock of 80MHz prescaled by 16, which makes it 5MHz.

4. When setting up a timer, I'm forced to provide the divider like in the question n. 3 above, whose lowest value is 2. Why? Why do I must divide the clock and have half of the accuracy (2.5MHz)? Why can I not set it as 1, which would mean I don't want to divide it, and want the full 5MHz (200ns) resolution?

5. In here...
https://github.com/espressif/esp-idf/bl ... ain.c#L107, if the timer clock frequency is already prescaled, why do I have to manually and ambiguously set it again? Why is this even an option anyway?

WiFive
Posts: 2823
Joined: Tue Dec 01, 2015 7:35 am

Re: ESP32 timer

Postby WiFive » Wed Sep 18, 2019 1:47 am

1. Correct
2. Because you don't always want to count that fast. Moreso if you have something like a 16-bit timer, but it's not as big a deal with a 64-bit timer.
3. Yes
No, 80mhz.
4. Max timer frequency is 40mhz due to hardware characteristics
5. It's not, that's where you set the 80mhz divider

Who is online

Users browsing this forum: Alexa [Bot], billiam, Google [Bot] and 29 guests