While in the process of getting some higher-resolution spectrums to evaluate my XRF setup I now seem to have some sort of programming problem -- the Teensy code hangs at random times into the pulse acquisition process. The problem may be some sort of buffer overflow issue in my code, or perhaps a clipping problem in the TFT library code. I'm in the process of adding code here and there to flash LEDs attached to some otherwise unused digital pins so I can get a better idea regarding where the code is hanging up.
So far I haven't found a smoking gun.....
That's a tricky one. A hang at random is tricky to catch in the act.
In every small compute code I ever did, I always kept the "heartbeat".
It is true that the 32-bit processors, and other types I got into did not have the power of SBCs like a Teensy, or a Pi, but there was always the "cycle", where a certain fraction was always running essential housekeeping code, and a remaining time within the cycle for user code. If the cycle was 10mS or 5mS or 2mS, that was fast enough for programs to seem "instantly responsive", at least for interface. Yes indeed, I would have high priority interrupts to deal with, and put away stuff that had to happen at high speed, but the time through it's route was so instantaneous, it never threatened the cycle.
The "heartbeat" was a very low impact little thing that would execute each cycle, counting up a sufficient delay to flash one IO LED slowly, and with a longer OFF time than ON.
Eventually, I took to giving specific program segments a "heartbeat" of their own. Without this, a little computer looks very much much like when it is switched off, except perhaps for the "+5V is here" red LED. When the LED is flashing, you immediately know
lots of stuff, mainly that it is alive, has a clock running, and that it is executing tons of code just to go around it's cycle!
Having a heartbeat for code segments, supposedly to let me know which had hung up, proved less useful than I had thought. Reasonable breakpoints, and adding in bits of code in program segments to make output with diagnostics worked rather better. I even had code where the amount of "commented out" diagnostics exceeded the amount of working stuff. Even so, looking at three LEDs winking away did have a nice positive sychological effect on the mood. Utterly useless when they wink away, and the code is still crashing!
I admit - I am not very good at "programming" ! :|