cbarberis
Joined: 01 Oct 2003 Posts: 172 Location: Punta Gorda, Florida USA
|
Reading garbage values from ram |
Posted: Sat Jun 09, 2007 6:12 pm |
|
|
Hi,
I Have a program that I wrote a while ago for a PIC18F6720, this is used on a small temperature controller that controls both heat and cooling temperatures for biological samples from -20 to 100 deg C within 0.1 deg C. The instrument works quite well and originally had ten user selectable programs with four temperature sequences per program that the user can name and edit so they can run various sequences. Everything is displayed on a 4X20 alphanumeric LCD screen that spans various menu pages for various different functions, all user input is via four laminated keys.
As usual, I have been asked to expand the functionality of this device so it now has 50 programs and four sequences per program. So far I have painfully got most of the menus modified and working and expanded the number of bytes for each parameter of temperature,time in min and hours that I allocate to eeprom for user storage and retrieval. everything seemed ok until I went to read these values from eeprom into my program structure in ram. Although the values I can read on my eeprom memory using the ICD or MPLAB sim seem to be correct, I occasionally get random garbage values as I read them into my program structure, for some unknown reason I seem to get the value 0xff asigned to my minutes variable when I know that that eeprom location was actually zero. These garbage values seem to occur more frequently to my hours and minutes values and rarely to my temp values. I tried running this on the MPLAB sim and found the same issue, so it appears to be more program related than hardware. I have also compiled this on both the PCH V3.249 and the latest V4.040 with similar results, so I can't blame CCS.
Because my program consists of approximately twenty different source files, I just cut and pasted some of the relevant sections to my problem. Perhaps a new set of fresh eyes may see something that I can't. Any help would be greatly appreciated.
*****************************************************************************************************************
// on the main.c file I declare the following values to be inserted into eeprom at program time:
#define EEPROMSETPT 0x0A //10 1 byte
#define EEPROMTEMP 0x20 // temp values starts at 32 ends at 232
#define EEPROMMINUTES 0xEA // run minutes starts at 234 ends at 434
#define EEPROMHOURS 0x1B4 //run hours starts at 436 ends at 636
#define PROGNAMES 0x27E //prog names starts at 638 ends at 888
#define PAGES 4 // 4 pages per prog menu
#ROM int8 0xF0000A = {0x25} // default setpoint 37 deg C
#ROM int8 0xF00020 = {18,28,35,16,8,30,38,0,5,15,20,5,20,45,30,40,50,20,0,10,20,30,4,3,2,
10,20,10,5,2,4,8,30,40,10,50,40,5,10,15,0,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0} // 200 (50X4) Timevalues hours
#ROM int8 0xF0027E = {'P','R','0','0',0x0,'P','R','0','1',0x0,'P','R','0','2',0x0,'P','R','0','3',0x0,
'P','R','0','4',0x0,'P','R','0','5',0x0,'P','R','0','6',0x0,'P','R','0','7',0x0,
'P','R','0','8',0x0,'P','R','0','9',0x0,'P','R','1','0',0x0,'P','R','1','1',0x0,
'P','R','1','2',0x0,'P','R','1','3',0x0,'P','R','1','4',0x0,'P','R','1','5',0x0,
'P','R','1','6',0x0,'P','R','1','7',0x0,'P','R','1','8',0x0,'P','R','1','9',0x0,
'P','R','2','0',0x0,'P','R','2','1',0x0,'P','R','2','2',0x0,'P','R','2','3',0x0,
'P','R','2','4',0x0,'P','R','2','5',0x0,'P','R','2','6',0x0,'P','R','2','7',0x0,
'P','R','2','8',0x0,'P','R','2','9',0x0,'P','R','3','0',0x0,'P','R','3','1',0x0,
'P','R','3','2',0x0,'P','R','3','3',0x0,'P','R','3','4',0x0,'P','R','3','5',0x0,
'P','R','3','6',0x0,'P','R','3','7',0x0,'P','R','3','8',0x0,'P','R','3','9',0x0,
'P','R','4','0',0x0,'P','R','4','1',0x0,'P','R','4','2',0x0,'P','R','4','3',0x0,
'P','R','4','4',0x0,'P','R','4','5',0x0,'P','R','4','6',0x0,'P','R','4','7',0x0,
'P','R','4','8',0x0,'P','R','4','9',0x0 } // Default prog names (50X5) ends at 0xF00378
// All of the above takes up 888 bytes out of 1024 bytes of eeprom
*****************************************************************************************************************
//On another file named Menus.c I declare the following global structure
#define MaxProgNum 50
unsigned int8 Program_number;
char PrgName[50][5]; // four chars + eol
char *NamePtr;
//Structure of array to define program value sequences
struct ProgSeq{
char ProgStringName[5];
unsigned int8 Step[PAGES];
unsigned int8 TempSet[PAGES];
unsigned int8 TimeHRS[PAGES];
unsigned int8 TimeMin[PAGES]; };
struct ProgSeq ProgSelect[MaxProgNum];
struct ProgSeq *ProgPtr;
*****************************************************************************************************************
//On another file called EEvalues.c I read all the values from eeprom into my struct in ram
void ReadEEpromProgValues()
{
unsigned int8 p,i,j=EEPROMMINUTES,k=EEPROMHOURS, q=EEPROMTEMP;
unsigned int16 nameindex = PROGNAMES;
for(p=0; p<MaxProgNum; p++) // read all prog values into Progseq structures from eeprom
{ ProgPtr = & ProgSelect[p];
for(i=0; i<PAGES; i++)
{ ProgPtr -> TempSet[i] = read_eeprom(q++);
ProgPtr -> TimeHRS[i] = read_eeprom(k++);
ProgPtr -> TimeMin[i] = read_eeprom(j++); }
for(i=0; i<5; i++)
{ ProgPtr -> ProgStringName[i] = read_eeprom(nameindex);
nameindex++; }
} }
*****************************************************************************************************************
// On another page named FileRunPage.c I try to read what programs have valid data in the minutes or hours fields, I read all fifty programs
and record the ones that have active time info so the user can execute them the name of the program that contains data gets tagged and
displayed on the lcd screen.
static unsigned int8 ValidProgs[50];
unsigned int8 i,n=0,hours,minutes, maxpos;
for(p=0; p<MaxProgNum; p++) // look for progs that contain data
{ ProgPtr = & ProgSelect[p];
for(i=0; i<4; i++)
{ hours = ProgPtr -> TimeHRS[i]; // then look for time info in each seq, here is where the problem is
minutes = ProgPtr -> TimeMin[i]; // it seems that I am reading garbage values for minutes and ocassionally for hours
if(hours || minutes) // if any cell contains time data make seq valid and tag the prog name
{ for(i=0; i<5; i++)
PrgName[p][i] = ProgPtr -> ProgStringName[i];
ValidProgs[n] = p;
n++; }}}
n=0; |
|