ESP32 timer
Posted: 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?
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?