??? 08/23/08 10:50 Read: times |
#157684 - Language-independent method Responding to: ???'s previous message |
This is a common problem, and their matematician directly identified it. Had he been a software engineer, he would have told you to make all branches equal time, but instead suggested to slow down the loop to make the delay represent the largest time. Slowing the loop down would just have reduced the imbalance, but not removed it.
A way to do this in a high-level language with less effect by the geneated code is to replace the conditional assign with a computed assign: unsigned char next[6] = {0x02,0x04,0x08,0x10,0x20,0x01}; unsigned char n = 0x01; for (;;) { if (pressed) break; n = next[n]; } If the div/modulo instructions are known to run at a fixed number of clock cycles for any numeric value, this can be done: unsigned char n = 0; for (;;) { if (pressed) break; n = (n+1) % 6; } n = 1 << n; |