How to avoid pulse jitter?

One of my programs is the version of R3, which uses interrupts for high-speed pulse output, and the interval between two pulses is about 1us. In the version of R3, a method is used to disable TIMER 0. After porting the program to R4 MINIMA, I can't find a response method to disable TIMER 0, which leads to fluctuations in the interval of two pulses. There is a 5us interval change in about 10s. Dear friends, is there any way to solve it?

The R4 doesn't have a Timer0. If you mean to disable the interrupt driving millis then that is now on the AGT0 timer.

However the R4 has a very inaccurate clock. If it matters to that level that you wanted Timer0 turned off then the R4 is not going to be the right choice. For fine timing it the worst possible choice in the Arduno stable.

Disable Timer0's method using R3

          TIMSK0 = TIMSK0 & B11111110;         // R3 disable Timer0 to avoid pulse jitter

The part of the output after the interrupt response

          delayMicroseconds(1);
          digitalWriteFast(pulse1,HIGH);
          delayMicroseconds(1);
          digitalWriteFast(pulse2,HIGH);
          delayMicroseconds(100);
          digitalWriteFast(pulse1,LOW);
          digitalWriteFast(pulse1,LOW);

Turning off AGT0 should be like:

R_AGT0->AGTCR |= 0x04;

That should set the TSTOP bit in the AGT0.AGTCR register which will stop the timer running.

But like I said before, if the interrupt mattered at all on the R3 then this needs really tight timing control and you won't get that with the R4 since it has no crystal.

Thank you so much. You explained it very clearly that I should use R3!

Using interrupts for high-frequency output is not a good choice. When using interrupts, jitter is almost inevitable.
Use a mechanism specifically designed to generate pulses of precise duration - hardware timers.

1 Like