I am using MPLABX + Harmony framework to write code for a PIC32MZ1024EFK064.
My goal is, to trigger the ISR every microsecond. In order to test this, I toggle a LED after 1000000 cycles of the ISR:
uint32_t xxx = 0;
void __ISR(_TIMER_2_VECTOR, ipl1AUTO) IntHandlerDrvTmrInstance0(void)
{
xxx++;
if(xxx > 1000000){
xxx = 0;
blink();
}
PLIB_INT_SourceFlagClear(INT_ID_0,INT_SOURCE_TIMER_2);
}
Timer2 runs at 80MHz with a prescaler of 1 with a timer period of 80.
At my first attempt, the LED toggled every 4 seconds (ISR = every 4us).
I figured out that I can reach 2 seconds by changing the Postscaler of PBCLK7 from 2 to 1. (now the CPU-core runs at 160MHz instead of 80MHz).
But even when I change the timer period to 1, I only get my LED toggled every 2 seconds.
Any idea how to speed things up further here?
UPDATE:
The subroutine blink()
was too slow.
By manipulating the Register directly, it works at 1us
void __ISR(_TIMER_2_VECTOR, ipl1AUTO) IntHandlerDrvTmrInstance0(void)
{
LATBINV = 1<<8;
PLIB_INT_SourceFlagClear(INT_ID_0,INT_SOURCE_TIMER_2);
}