Hi,
Thanks for all the info. I'll write my own ISR function and it will probably help a lot.
While testing this I found another weird thing, I have simplified reading the TPM counter value just to make sure there is no overhead in that either.
I ended up with this bit of test code:
static uint32_t NewCount = 0, PrevCount = 0;
void CheckTimeDifference( void )
{
NewCount = TPM0_CNT; // get the latest microsecond counter value
PrevCount = NewCount;
NewCount = TPM0_CNT; // get the latest microsecond counter value
NewCount = TPM0_CNT; // get the latest microsecond counter value
NewCount = TPM0_CNT; // get the latest microsecond counter value
NewCount = TPM0_CNT; // get the latest microsecond counter value
NewCount = TPM0_CNT; // get the latest microsecond counter value
PrevCount = NewCount;
}
When I put a breakpoint on the last line I end up with PrevCount holding the first counter value and NewCount holding the last value read.
the intermediate read operations are just there to evaluate the execution speed.
I know for sure that the core clock is at 48 MHz and the bus/flash clock is at 24 MHz.
I am equally sure that my TPM0 counter counts at a rate of 1 Microsecond, I have done plenty of testing to be 100% certain.
I would expect the few single cycle read and store operations (at 48/24 MHz) to take well below 1 microsecond to execute but strangely enough they always end up taking 3 microseconds.
So: I think something is slowing down the processor but I have no idea what it might be.