I think I can see the light at the end of the tunnel. I took on a little programming project for Stevens. It wasn't supposed to be a big deal, I originally figured I would be done by Christmas, and I was, sort of. But then the bugs appeared and I spent the last two months tracking them down.
The first one was an optimization problem. I had a delay loop that worked fine under the old compiler, but the new one's optimizer realized that it accomplished nothing, other than waste time, which is the enemy of optimizers, and so deleted it. So I had to look up the correct incantations and spells to use on this compiler to ensure that it would waste time when I told it to.
There were some little bugs involving some changes to commands and responses, but those were easily dealt with. After all, I could see what was wrong there. There was also a problem with trying to herd a large number of ducks down the same path, but that was more of mental technique than a programming problem.
Finally, last Wednesday, I thought it was all working and shipped it off. Finally, relieved of my obligations, at least until they test it and find something wrong. So Thursday I sat down, and just for grins, rewrote a large section of code that had been bugging me ever since I first saw it. It contained about a dozen nearly identical sections which should have been combined into one procedure. It would need a couple of parameters to stand in for the bits that changed in each section, but other than that it was a no-brainer. So I sliced and diced and cut about 200 lines out of a thousand line file, and I was very pleased with the results.
Friday I hear back from Keith and the program I sent them seems to have a very serious shortcoming. Never mind that it got over the first major hurdle, you have to be able to finish the race, and it wasn't doing that. I went back and looked at it again, and by gum, he was right. Load the program on the actual hardware and it croaks whenever you ask it to do some actual work. However, run the program in the simulator on the PC and it works fine.
I originally blamed this discrepancy on the lack of an analog input board on my set of test hardware. Maybe something funny is going on here. Well, no, it fails when run on a complete set of hardware too. What's going on? I pull my hair. I stew. I mull over possibilities. I think of nothing. Fine. Just for grins, let's try the piece of code I reworked on Thursday. There is no reason it should work any better, but hey, let's just try it anyway. And it works.
There is no reason for it to work any better than the previous version, but work it does, so I ship it off. The code size is slightly smaller, so it occupies less flash memory. It uses less RAM, though the same amount is allocated. It was down around 70-80% of available space in both cases, both before and after, so it's not like it was bumping up against any limits. I can't explain it, but I will accept that it works. Maybe the answer will appear in a circle of fire tonight in my dreams.
3 hours ago