Technical Tips
Technical Quips We Hold Dear
- I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone. (Bjarne Stroustrup.)
- If you code to the limit of your ability you will end up debugging beyond the limit of your ability. (Unattributed.)
- In theory, practice & theory are the same – in practice they tend to be rather different! (Unattributed.)
Preprocessor Directives
For conditional compilation #ifdef may be compact but the defined syntax is
more flexible, consider:
#if (defined OPT1 && defined OPT2) || (defined OPT3 && !defined OPT4)
Short of scope channels when debugging serial receive
Here’s a nifty idea for squeezing more information onto a scope channel when debugging serial receive. Set up spare outputs to indicate receipt of start pattern, start edge, bit sampling, etc. Diode OR them into a multi-level resistive divider such that each output causes a different voltage. Ensure that the signal on which you wish to trigger gives rise to the highest voltage.
The circuit & scope trace shown below are a real-world example. The option DIP switch was temporarily disconnected & the micro pins thus freed were wired up as shown. The firmware was modified so that the outputs pulsed briefly as follows:
- PB0 - packet start (no edges detected for "blanking" period)
- PD7 - start bit edge
- PD5 - start & data bit value
The previously intransigent bug was quickly found.