I know there are several places in Teensy code where when people need accurate timings
and/or delays, they use the ARM cycle count register.
Some of the Teensy code looks like:
I will rerun it some at different delay times to make sure I am not getting rollover issues
on the counts...
As anyone played with this stuff? If it works, who knows maybe I will play with SoftwareSerial code. Although will need to bypass things like digitalWrite and the like.
CYCCNT is part of the "Debug, Watchdog, and Trace" (DWT) unit that is part of the Arduino core. I've written a microsecond delay routine using DWT->CYCCNT that I've used on SAMD51 boards (120MHz; which means that the 32bit counter overflows in about 37s.) It should work on other ARMs with the DWT option as well.
I did also write a "dumb, tx-only, SoftwareSerial" that should work on any system that is both fast and implements an accurate delayMicroseconds() function:
Thanks, for the fun of it I have hacked up version of Paul's version of SoftwareSerial that I am debugging.
The TX is working, the RX is faulting... Just pulled out hardware debugger.
The code is sort of interesting that Paul did for RX.
He setup a Pin Change interrupt to catch the start bit, at which time on the Teensy,
he started up an IntervalTimer to read in each of the bits, that part appears to be sort of working, but then after receiving all of the bits, it detaches that interrupt and tries to reattach the pinInterrupt, which is faulting...
Instead of IntervalTimer (which is specific to the Teensy code base), I am using a
mbed::Ticker ticker; // calls a callback repeatedly with a timeout
I am also using sort of a variation of my digitalWriteFast code, where at begin time, I convert the pin number into a pointer to the Port and the bitmask, and Set the clear the bits only...