Olin Lathrop wrote: > Brent Brown wrote: > > Don't miss the other point though - a boolean flag (single bit, 0/1) > > could be used but if the flag itself was randomly corrupted (software > > bug, ESD, EMI, whatever) there would only be a 50/50 chance of > > detection. > > > > Instead here an 8 bit token is used. It is initialised only once, > > thereafter modified by each section of code in a prescribed fashion. > > Somewhat analogous to a game of > > Chinese whispers. Corruption of the token itself now has a 255/256 > > chance of detection. > > I'm no C whiz, but it looks to me like your method degenerates to the same > thing as using a single flag bit. > > > During ISR: > > if watchcat = 0xAA > > watchcat = !watchcat (invert the value) > > > > At end of mainline code: > > if watchcat = 0x55 > > watchcat = !watchcat > > reset watchdog > > I could be wrong about this, but I thought the C "!" operator used in this > context does a boolean inversion, not a integer one's complement. If so, > you no longer know what the value is after the first watchcat = !watchcat, > only that it is now zero if it wasn't and non-zero if it was. If you wanted > to check for random corruption you'd have to take the one's complement or > XOR with FFh. (Of course that may be what the C "!" does. Like I said, I'm > no C whiz and usually have to look these things up on the rare occasions I > write C). My bad, I did mean ones complement (every bit in the byte gets inverted)... but the example was intended to be just pseudocode. Actual C code would be like this.. // Initialise once only in mainline code: unsigned char watchcat = 0xAA; // At end of ISR: if(watchcat == 0xAA){ watchcat = ~watchcat; // (invert the byte, new value is 0x55) } // At end of mainline code before looping: if(watchcat == 0x55){ watchcat = ~watchcat; // (invert the byte, new value is 0xAA) ClearWatchDog(); } -- Brent Brown, Electronic Design Solutions 16 English Street, St Andrews, Hamilton 3200, New Zealand Ph: +64 7 849 0069 Fax: +64 7 849 0071 Cell: +64 27 433 4069 eMail: brent.brown@clear.net.nz -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist