Hello,

I have been having a bit of what I think is memory trouble with a refrigeration control algorithm I wrote for an PIC18F86K22.

The symptoms are this:
setup program variables (there are a lot)
refrigeration system powers up and begins to run
superheat stops being calculated after a random amount of time (hours) and SatT is zero or a garbage number.

The superheat is calculated using a lookup table that was defined using this:

SatT var word[61]

If a word is 2 bytes, then this should require 122 bytes of memory to store this array of values. In a PIC18, from what I read on the data sheet, there is 3,862 or 4k or something bytes available. Ah, but the banks! The PIC18 has 16 banks of 256 bytes each.
We know this is not the problem though because when I did this:

SatT var word[61] bank4

It works indefinitely without error. It looks like assigning a bank to this array means that it could not get overwritten or lost.
But now I have a new problem. Compressor RPM started reading zero. There are three variables that go into calculating RPMActual:

SecAvgCount var word bank1
RPMSum var long bank1
RPM var long

As I'm programming this remotely I could not test to see which variable was reading incorrectly, but my guess is that the problem was the unassigned variable RPM.

This should provide us with a hint as to what the problem is. Only one variable is getting lost at a time, and if I apply a bank to the variable that is getting lost, it suddenly never gets lost, but then a new one gets lost. It seems as though I am getting close to the memory limit and it just loses a random variable that was not assigned to a bank. The problem with that is that I don't think I am close to the memory limit. Attached is a guess at how much memory my variables are taking up and what banks they are in. I didn't account for constants, but even so I'm not even at half of the supposed available memory. I could try applying banks to everything, but I thought PICBasic was supposed to do that automatically for everything you don't assign.

Would anyone else know why a variable might get lost because it was not assigned to a bank?

memory calculations.zip