I am looking for some recommendations for a well-maintained or popular library for replacing the default digitalWrite() and analogWrite() Arduino functions. My current implementation requires as fast as possible switching, without using direct port manipulations
If you use MegaCoreX as the board package with the IDE instead of the megaavr package you can use the built in fast io functions.
For timing critical applications the standard digitalRead() and digitalWrite() functions may be too slow. To solve this, MegaCoreX also includes some improved variants that compiles down to a single instruction. Call digitalReadFast(myPin) or digitalWriteFast(mypin, state) to use these. Note that the pin number and pin state has to be known at compile time!
Sorry for the late reply Delta. I measured that the nano every runs the digitalWrite() functions at ~4 us, while the port set was ~0.44 us, so nearly a 10x slowdown to use digitalWrite(). I don't have a set number at the moment, but will be running a real time system, and so am hoping to optimise wherever I can!
Thank you! I was able to luckily get the system to run a workaround to still be able to utilise the port manipulations that were previously giving me errors. This was the next solution!
LOL no worries, this isn't an optimising a button type situation here
For safety reasons for the system I am building, we have a separate system that will utilise my Arduino code as an API to interact with a large machine. In the case that something happens, we want to be able to control the system as fast as possible to limit as many potential situations as possible!
Thank you for your help, I appreciate the conversation we have had!
I appreciate your passion about the speed of these functions here. I am not going to fight you on this, or try to explain my entire system to you, and why I may or may not need this level of speed. I appreciate your enthusiasm, but I do hope that you understand that some systems will require this level of speed, although not the large majority of users on this forum.
Lets leave this discussion here, as my question has been answered and I have found my solution.