CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Reading garbage values from ram

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
cbarberis



Joined: 01 Oct 2003
Posts: 172
Location: Punta Gorda, Florida USA

View user's profile Send private message Send e-mail

Reading garbage values from ram
PostPosted: Sat Jun 09, 2007 6:12 pm     Reply with quote

Embarassed
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.
Confused

*****************************************************************************************************************
// 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,0,0,0,0,0,0,0,0,0,0,0,0,//53
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,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) Default TempValues

#ROM int8 0xF000EA = {3,3,3,6,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,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0} // 200 (50X4)Default Timevalues minutes

#ROM int8 0xF001B4 = {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,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,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;
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jun 09, 2007 11:58 pm     Reply with quote

Quote:

#define EEPROMSETPT 0x0A
#define EEPROMTEMP 0x20
#define EEPROMMINUTES 0xEA
#define EEPROMHOURS 0x1B4
#define PROGNAMES 0x27E
#define PAGES 4

unsigned int8 p,i, j = EEPROMMINUTES, k=EEPROMHOURS, q=EEPROMTEMP;

There's a problem with the initialization of 'k'. It's declared as 'int8'
but it's loaded with a 16-bit value. The upper byte will be truncated
and it will only be loaded with 0xB4.
cbarberis



Joined: 01 Oct 2003
Posts: 172
Location: Punta Gorda, Florida USA

View user's profile Send private message Send e-mail

Thank YOU PCMprogrammer!
PostPosted: Sun Jun 10, 2007 7:05 am     Reply with quote

Not only did I declared the hours variable wrong but also the minutes as well:
Quote:
#define EEPROMMINUTES 0xEA // run minutes starts at 234 ends at 434
#define EEPROMHOURS 0x1B4 //run hours starts at 436 ends at 636

Once these two were corrected the corruption was resolved, minor details that you can stare at for days are the ones that usually mangle you up. That is why I really appreciate the existance of this user forum.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group