In my project I need highest avaiable UART baudrates between Atmega328p and BTM-222 so I have to use 18.432.000 Mhz crystal to achieve 460.8 kbps transfer without erros.
But same time I need high accuracy time measurement. Previously when I was using 16Mhz crystal I was using this method: Timer0 with 64/ prescaler. So it took 4us to incrament counter register.
(1/16000000)*64 = 4us
4us was my measure resolution Overflow counting: counter overflow occurs every 1024us
4us * 256 = 1024us
Then to receive time scaled in us there is equation:
time(uint32) = current_counter * 4 + overvlow_counter * 1024
Everything is easy because multiplying x4 and x1024 are bit shifts. I am using long integer so longest time i can measure is
2^32 * 1ms = 71 minutes.
Excelent!
Then when I use 18432000 MHz crystal there is (1/18432000)*64 = 3,47(2) so it cant be calculated using my simply previous code.
Maybe you have some ideas what can I do? I have one: use 1MHz timer0 external clock source coming from crystal. My question is: how to connect 1MHz crystal to T0 pin and provide clock source for timer0?