I'd like to implement a ten-millisecond counter on my MCU so that the cycle count representing ten milliseconds could be arbitrary. I need this to account for inaccuracies in the internal clock frequency.
For example my bus frequency is 36.864.000Hz and each 10ms period would be represented by 368.640 cycles. I get a reference time from a GPS module and I'd like to change this cycle count accordingly.
My problem is I don't know how to build a timer mechanism that would fire every n cycles, where n can be over 65536. I've tried to use PIT but it needs the timeout to be n * m cycles so a cycle count that is e.g. a prime number cannot be used and the resolution in general would be the minimum of n and m.
Using ECT this could be achieved by dynamically adjusting the compare register with the modulus of the desired cycle count but it seems inaccurate and inelegant.