…utter dismay, it stopped counting.

The units counted fine, the tens counted okay too.

But the hundreds?

No chance!

It is no word of a lie to say that this problem has taken up virtually all my ‘thinking’ time over the last ten days or so.

What I found totally perplexing by this bug was that just when I though I’d cracked it and the hundreds must click over to the magic ‘1’ from zero, the left hand display which was quite happily counting up from zero to nine repeatedly would reset itself to zero, then carry on counting from there as if nothing had happened!

Was it the Watch Dog Timer?  Was it somehow resetting itself because of an unknown time-out?

Was my wiring faulty?

And for that matter, why did it sometimes stop counting -on both numbers- or even fail to start when I switched it on?

Was I going mad???

Well, Dear Reader, you can make your own mind up about the last question, but this morning, either side of an excellent shower*, I figured out I had not one, but two main problems.

The first, and most pressing was this last one -the irregular start-up and occasional freezing of the display -and 40 MHz clock.

I checked through the hardware, and found everything all A-Okay.  Well, actually I must qualify that last statement.  The best electronics engineer I mentioned a couple of posts ago would’ve had to go and have a lie-down somewhere dark and quiet had he seen my board, but for me, it was pretty neat and everything ‘bleeped’ through fine with a continuity tester and there were no dry joints.

I finally traced it down to some pre-processing commands I didn’t actually need that were confusing the programmer.  Of course, this being Microchip and all, they didn’t actually say in Big Red Letters not to do this.  Like our good friends at Microsoft, Microchip tend to be a little ‘cryptic’ with their clues.  The way they figure it is, Hells, you’re going to have to learn this, so why make it easy for you?  Have a little fun on the way!  As I’ve always said, you only learn when things screw up.

Okay, number one problem out of the way, what about the real ‘Biggie’?  Why would it not count past the tens, and why when it tried did it ‘crash out’ the other display back to zero?

And therein lies the rub.

While washing my hair for the second time this morning, I had it figured.

It was crashing out the other display because it was doing just that -producing an error!

For those who’ve never attempted to program in ‘C’ -or its little brother ‘Assembler’- for the PIC processor, let me tell you that the error-trapping is worse than useless.  There are no big, friendly boxes appearing on the screen saying ‘Error in line xxxx’, because as far as the PIC is concerned, there’s no screen to display it on.

What was actually happening was that I was trying to address a part of the array used for displaying the LED display that didn’t actually exist!

I’d totally forgotten that in  ten element array, the last available address is the ninth element -because you start from the zero element.  Like a first-semester rookie, I’d been trying to address the tenth element when it was meant to be carrying over to the next digit.

Hence the reset.

Unsurprisingly, I didn’t do the full ‘I’m Too Sexy For My Cat’ dance when I learned of my error.

I didn’t even do the half-version.

I went very quietly into the kitchen, half opened one of the top cupboard doors and repeatedly smacked my head against it.

Then I did it again.

So, Dear Reader, we’re running a little behind schedule right now, so I’d better get back to it and make it measure speed of wheel rotation.

This will be through a different interrupt system, but that’s not a huge problem now.  As I said last post, I now know more that I’d ever wanted to know about the PIC interrupt system.

But rest assured:  When I get that cracked, it will be the FULL ‘I’m Too Sexy For My Cat’  Dance.

Oh yes.

*Note.  I know that amongst programmers, when you’re stuck on such a problem, little social niceties like personal hygiene go straight out of the window.  Fact.