Hello i am tryng to make a digital filter with arduino, and tryng to sample at 25khz that correspoeand to +- 640 value of OCR1A.
But less than 2500 value of OCR1A arduino seems to "not follow" the step.
I make analogWrite(ledPin, 200);
analogWrite(ledPin, 0);
at every interrupt and log it via oscilloscope to check if arduino follow frequency.
Till 2500 /3000 of OCR1A arduino seems follow and made an output on pwm port at regular and correct frequency, but less this value range begin to output some "strange" and not regular.
Can yu suggest me some code to reduce interrupt latency?
I think I outlined that earlier.
The easiest would be to ditch the arduino's isr management system: it does so via a set of function calls - costly. You can speed that by writing your own isr.
Under that approach, the most common and dangerous way to reduce latency is to use naked ISR (using the ISR_NAKED attribute). For that approach to work, you have to manually save the context.
Then there is the option to hand-code assembly isr.
I think there is not a whole lot to gain by going beyond writing your own isr (in C), in terms of reducing latency.
or operative strategy
This is where I think the attempt at reducing latency may be misguided. Unless you are doing something super time critical, there is a lot more to be gained by stepping back and ask yourself what you are trying to do and think of an approach that does it better.
Your pwm period is far bigger (by a few magnitude) than the latency you are trying to reduce. So essentially you are resetting the pwm module over and over.
No you aren't. You are reconfiguring the PWM output at every interrupt. I think what you're trying to achieve is to configure it once and leave it running. Usually with PWM you would configure the duty cycle and it would run at a fixed frequency. If you want to vary the frequency, be prepared to do a little digging into the way PWM uses hardware timers and how the hardware timers are configured.