k3ng_rotator_controller/libraries/digitalWriteFast/NOTES/NOTES.md
Anthony Good 56e6ed8233 2021.10.14.01
FEATURE_STEPPER_MOTOR
          Removed OPTION_STEPPER_MOTOR_MAX_50_KHZ.  Too much overhead from interrupts.
          Implemented faster digital writes using digitalWriteFast library (library now included in Github)
          Added OPTION_STEPPER_DO_NOT_USE_DIGITALWRITEFAST_LIBRARY to disable digitalWriteFast library use
2021-10-13 20:58:48 -04:00

1.2 KiB
Executable File

Notes

Notes down the observations, experiences and occurrences during the development of the repo.

Useful for explaining certain decisions.

speed of digitalWriteFast:

On Arduino Uno clone, 16MHz

digitalWriteFast is so fast that

void loop() {
  digitalWriteFast(pinNum, HIGH);
  digitalWriteFast(pinNum, LOW);
}

The above did not result in 50% duty cycle. Graph 1

Rather, the pin stays low for quite some time until the program loops again.

Took around 600ns for the program to repeat

So, the below was done instead:

void loop() {
  digitalWriteFast(pinNum, HIGH);
  digitalWriteFast(pinNum, LOW);
  digitalWriteFast(pinNum, HIGH);
  digitalWriteFast(pinNum, LOW);
//	...  and it goes on, multiple times
  digitalWriteFast(pinNum, HIGH);
  digitalWriteFast(pinNum, LOW);
  digitalWriteFast(pinNum, HIGH);
  digitalWriteFast(pinNum, LOW);
}

It only took 250ns to toggle, meaning it took only 250ns/2= 125ns to set or clear the pin/port. Graph 2

speed of digitalWrite:

On Arduino Uno clone, 16MHz

It took 12.56us to toggle, meaning it took 12.56us/2= 6280ns to set or clear the pin/port.

50 times slower than direct port manipulation!

Graph 3