[solved : 200ns] pin interrupt latency = 2.6us : too long ! #1024
Replies: 4 comments 8 replies
-
@trimarco232 You could try the gpio_... functions, instead of relying on digitalWrite(). That might be a touch faster: https://raspberrypi.github.io/pico-sdk-doxygen/group__hardware__gpio.html
I've found gpio_put_masked() to be the most generally useful one, but one of the simpler ones might be faster still - I've never measured it. You can try putting it in RAM by using __not_in_flash_func in a function definition, apparently. See: #421 |
Beta Was this translation helpful? Give feedback.
-
The XIP cache is non-deterministic, so definitely put the ISR code in RAM The Arduino ISR API needs to do some processing before it calls your function, so that adds overhead. If you use the raw SDK functions and none of the Arduino GPIO ISR API you should be safe to skip all that (but note you only get 1 GPIO IRQ callback, not one per pin this way). |
Beta Was this translation helpful? Give feedback.
-
What happens if you remove the static keyword? If I've understood what I've read correctly, in this context it's just an instruction to the linker to not make it available outside the source file where it's declared, so you could probably just omit "static" and not cause any problems for yourself. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I made a simple test :
// first, in the setup, pwm and interrupt for pin 10
analogWriteFreq(10000); analogWriteRange(256); // can it be different for each (pair of) pin ?
attachInterrupt(digitalPinToInterrupt(10), isr_test_interrupt_rising, RISING) ;
analogWrite(10, 64);
// than the isr, outside the loop
void isr_test_interrupt_rising() {
static int fall_rise;
if (fall_rise) {
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
fall_rise = 0 ;
}
else {
digitalWrite(11, LOW);
digitalWrite(12, LOW);
fall_rise = 1 ;
}
}
it works, but my 10€ logic analyser show me :
delay between pin 10 and pin 11 : 3.2us
delay between pin 11 and pin 12 : 0.6us ; so the time for a digitalWrite is 0.6us ...
interrupt latency : 3.2 - 0.6 = 2.6us = 346 cycles @ 133MHz
it's not so ugly than an ESP32 (4us) , but far too much for an ARM based chip
any solution , and how to :
thanks a lot !
Beta Was this translation helpful? Give feedback.
All reactions