This code is running on an external board. I’ve not experimented with running it on the counter itself, but as this code also deals with interrupts without notable issues I suspect it might work on the board itself. There would, of course, have to be some mods, and I would want to tighten the code up.
Let us know if you try and what you find!
Kevin