Hi all,
digitilWrite() and digitalWriteFast comparison:
I have been playing around with Teensy 4.1 and noticed that there isn't a material difference between digitalWrite() and digitalWriteFast().
I set up a simple loop test, repeating a pin toggle on pin13 (LED_PIN) 100,000 times to see if there was any time difference, and there was nothing, maybe a few parts in ~10,000. Is that reasonable to assume? Have I missed anything obvious?
Serial Monitor:
Also, the Serial monitor has started to get flaky after behaving perfectly for at least 3 weeks. As suggested in the notes on help in the min web pages, I rebooted the hosting computer from power off, and that sorted it for a while. Soon enough, it showed 'Teensy not connected' at the bottom panel again, and the Serial monitor was not kicking off reliably. Program uploads work fine, though. The computer is a HP Pavilion with SSD disk and 16GB RAM. Has anyone else noticed this serial monitor behaviour?
Thanks,
Steve
digitilWrite() and digitalWriteFast comparison:
I have been playing around with Teensy 4.1 and noticed that there isn't a material difference between digitalWrite() and digitalWriteFast().
I set up a simple loop test, repeating a pin toggle on pin13 (LED_PIN) 100,000 times to see if there was any time difference, and there was nothing, maybe a few parts in ~10,000. Is that reasonable to assume? Have I missed anything obvious?
Code:
#include <TeensyThreads.h>
#include <digitalWriteFast.h>
int LED_PIN = 13; // pin 13 is the orange LED
int i = 0;
void setup() {
pinMode(LED_PIN, OUTPUT);
Serial.begin(115200);
Serial.println("System starting...");
}
void loop() {
elapsedMicros elapsedTime;
elapsedTime = 0;
for (i = 0; i < 100000; i++) {
digitalWrite(LED_PIN, HIGH);
digitalWrite(LED_PIN, LOW);
}
Serial.print("digitalWrite: ");
Serial.print(elapsedTime);
Serial.println(" us"); // Measure time taken by digitalWrite() - sometimes this would be 9506, sometimes 9513, or 9511
elapsedTime = 0;
for (i = 0; i < 100000; i++) {
digitalWriteFast(LED_PIN, HIGH);
digitalWriteFast(LED_PIN, LOW);
}
Serial.print("digitalWriteFast: ");
Serial.print(elapsedTime);
Serial.println(" us"); // Measure time taken by digitalWriteFast() - sometimes this also would be 9506, sometimes 9513, or 9511
delay(1000); // Wait for 1 second
}
Serial Monitor:
Also, the Serial monitor has started to get flaky after behaving perfectly for at least 3 weeks. As suggested in the notes on help in the min web pages, I rebooted the hosting computer from power off, and that sorted it for a while. Soon enough, it showed 'Teensy not connected' at the bottom panel again, and the Serial monitor was not kicking off reliably. Program uploads work fine, though. The computer is a HP Pavilion with SSD disk and 16GB RAM. Has anyone else noticed this serial monitor behaviour?
Thanks,
Steve