@soulid: I understand your point that you want consistent responses. However you will always pick up some jitter, for example while digitizing the analog signal. What I am aiming at: what is the maximum RPM of you engine and what angular resolution do you really need.
Example: suppose max RPM = 12000 RPM and angular resolution ~ 1°. Then resolution in clock cycles = 16 000 000 * 60 / (12 000 * 360) = 222 ticks (or 13 microseconds). --> You better be precise to ~5 microseconds.
With regard to consistent responses. Turn of all interrupts the Arduino provides by default. Then switch on only what you really need. Actually as it was already proposed you can do this without any interrupts at all.
However since you need to do some other stuff at the same time this might not be an option. I can think of several solutions:
-
Disable all other interrupts but the interrupt for the signal you want to delay. Process the delay in your interrupt routine and then go back to the main program. It follows that you main program must not rely on any timing functions and must not lock interrupts for more than say << 10 microseconds
-
Same as above but instead of a delay enable an additional interrupt in the timer code and set up a timer interrupt for the ouput.
-
Same as (1) but instead of generating the output in software use the PWM hardware to generate just this single pulse. Take care to disable the PWM early enough.
There are some mandatory actions here:
a) Read the datasheet on interrupts, especially timer interrupts.
b) Analyze the Arduino interrupt setup code (not to much and not to hard to understand). Do not forget the interrupts caused by communications
c) Analyze the LCD libraries if it has anything timing critical that might block interrupts.