How I was fooled

Enhanced mid-range devices. PIC12F1xxx and PIC16F1xxx

How I was fooled

Postby tunelabguy » Thu Jan 08, 2015 1:49 pm

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.
User avatar
tunelabguy
Verified identity
 
Posts: 29
Joined: Sun Jul 20, 2014 9:41 pm
PIC experience: Professional 5+ years with MCHP products

Re: How I was fooled

Postby ric » Thu Jan 08, 2015 10:22 pm

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
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 409
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products


Return to 14-Bit Core (enhanced)

Who is online

Users browsing this forum: No registered users and 1 guest