WestfW / ArduinoCore-samd

Arduino Core for SAMD21 CPU
0 stars 0 forks source link

Speed up DigitalWrite() and etc. #1

Open WestfW opened 6 years ago

WestfW commented 6 years ago

The three commits refactor wiring_digital.c and WVariant.h in a relatively safe and obvious manner, and result in a trivial digitalWrite() loop getting almost 50% faster (from ~300kHz to ~448kHz)

https://github.com/WestfW/ArduinoCore-samd/commit/4da75ccdfb349ab5d27481152bfa9e429de6a78e https://github.com/WestfW/ArduinoCore-samd/commit/58a6e6f6516bacdacafcc3b34c588727d686fce0 https://github.com/WestfW/ArduinoCore-samd/commit/2a0c0f7a1f995174fc1f4f8f31fb03516b085392

void setup() {
  pinMode(13, OUTPUT);
}

void loop() {
  while (1) {
    digitalWrite(13, 0);
    digitalWrite(13, 1);
  }
}
WestfW commented 6 years ago

I do, however, see 10% or so variation in the output frequency even with the same loop running. (cache effects due to placement of code and/or data structures? Grr.)