I'm using the timer module 0 to write my own delay routine that takes a value in miliseconds and poll the TATORIS flag busy waiting for the time out event.
All is fine when down counting (the prescaler acts as a true prescaler containing the least significant bits of the count according to the data sheet), and I use this code to calculate the start value to load into TAILR:
GPTM0->TAILR = millis*16000/256 - 1; // down-counting (true prescaler) GPTM0->TAPR = 255;
the formula I use is the following:
Ftimer = Fbus/((PR+1)(ILR+1))
But when up-counting, the prescaler acts as a timer extension and contains the most significant bits of the count, so the timer starts from 0x00 and counts up to the combination of TAPR and TAILR (the timer counts up to 0xFFFF and then increments the prescaler until the prescaler equals TAPR and then the timer counts up to TAILR,right?).
how can I calculate the value to load into TAILR?
Ftimer = Fbus/(n+1)
n is 0xPS.ILR (bit fields)