Page 1 of 1

How I was fooled

PostPosted: Thu Jan 08, 2015 1:49 pm
by tunelabguy
This is a story of debugging and how it can be misleading. I was debugging my 16F1823 interrupt code. I handled two interrupts in my ISR: Timer 2 overflow (61 times per second) and Comparator 1. The comparator interrupt was for recognizing an imminent power interruption so I could save some data in EEPROM before the power actually failed. Everything seemed to be working fine, except that the comparator interrupt latency was irregular, as indicated on a scope. I was looking into all sorts of esoteric things, like the high/low power setting on the comparator. But even on the low power setting, the comparator should respond in less than a microsecond. Finally I realized that I had forgotten to enable the comparator interrupt in PIE2. The reason I did not look there right away was that everything was basically working. If I had forgotten to enable the comparator interrupt in PIE2, things would not work at all, right? Wrong. Remember the timer interrupt? It was ensuring that I got into the ISR on a regular basis. Once in the ISR, the code simply checks the C1IF flag and processes the interrupt if it is pending. Everything seemed to work because the timer interrupt ensured that the comparator interrupt got looked at 61 times per second whether or not the interrupt was enabled. The moral of the story is not to assume something just because things are "almost working". Sometimes conditions conspire to make something sort-of work even when something very fundamental is wrong.

Re: How I was fooled

PostPosted: Thu Jan 08, 2015 10:22 pm
by ric
Ha ha, been there, done that, got the t-shirt.

Sometimes you have to be very attentive to details, that just seem a little "odd".

Remember the story how the computer hacker Kevin Mitnick was caught due to a few cents error in a university computer accounting log....
http://en.wikipedia.org/wiki/Kevin_Mitnick
http://en.wikipedia.org/wiki/Takedown:_ ... ter_Outlaw