I have tested this with the code below which outputs (to the serial monitor) the number of cycles between interrupt calls. However this number of cycles between interrupts varies. Is my code wrong or perhaps another interrupt (Timer1 maybe, but how to turn it off?) messing with TImer0?
#define MAXI 30
uint32_t d[MAXI];
int c=0;
void setup() {
Serial.begin(115200);
Serial.println("Setup");
noInterrupts();
timer0_isr_init();
timer0_attachInterrupt(itr);
timer0_write(ESP.getCycleCount() +80005000);
interrupts();
}
void itr (void){
timer0_write(ESP.getCycleCount()+80000000);
d[c]=ESP.getCycleCount();
c++;
if (c==MAXI){
for (int i=0;i<MAXI-1;i++) Serial.println(d[i+1]-d[i]);
c=0;
}
}
A sample of the output is 80000445, 80000440, 80000441, 80000495, 80000462, 80000476, 80000440, 80000502, 80000441, 80000440, 80000442. Each number meaning the number of cycles passed between interrupts.