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

EEPROM reading 0 on starting

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



Joined: 22 Dec 2004
Posts: 78

View user's profile Send private message

EEPROM reading 0 on starting
PostPosted: Mon Jun 26, 2006 11:13 pm     Reply with quote

Hi...I made a simple following program. Sometime on starting it is
reading eeprom value 0.

Even though I increase or descrase sometime it is reading perfect
after power on but sometime it is reading 0 even though it was greater
than 0 while running normal.

I tried to display the ScrPercent variable on 7-segment LED.

I am using 18F4525, CCS PCH C Compiler, Version 3.249 and
10MHz crystal X PLL = 40MHz.


Anybody have any idea why it is doing like that?

Is it require any delay before and after reading eeprom and writing eeprom?

Code:


#include <18F4525.h>
#fuses H4,NOWDT,NOLVP,BROWNOUT,BORV46,NOPBADEN,PUT,NOXINST,NOMCLR,NOLPT1OSC,NOWRT,NOWRTD,EBTR,NOCPB,EBTRB,NOWRTC,
NOWRTB,PROTECT,CPD,CCP2B3
#use delay(clock=40000000)   


#define DOWN_BUTTON  PIN_B1
#define UP_BUTTON  PIN_B5


#define SCRAM_PERCENT  0x0A


unsigned int8 ScrPercent=0;

void main() {



  delay_ms(100);

  set_tris_a(0xFF);
  set_tris_c(0x00);
  set_tris_d(0x00); // We need only Port D as output
  set_tris_b(0xFF);   //check this

 
  delay_ms(10);

   
        ScrPercent  = read_eeprom(SCRAM_PERCENT);      



  while(TRUE) {


    if(ScrPercent == 0)
    {
          output_high(PIN_D4);
     }
    else
    {
          output_low(PIN_D4);
      }


   if(!input(UP_BUTTON))
     {

     delay_ms(300);   

      if(ScrPercent<100)
         ScrPercent++;
      else if(ScrPercent>100)
         ScrPercent = 1;
        

      }
      else if(!input(DOWN_BUTTON))
   {

      delay_ms(300);
      if(ScrPercent>0)
         ScrPercent--;

     }//if(!input(UP_BUTTON))     

    write_eeprom(SCRAM_PERCENT, ScrPercent);


   //sprintf(int_str,"%3U",ScrPercent);         
   //DisplayInt(int_str[0], int_str[1], int_str[2]);


  }//while(TRUE)
 
}//main

Ttelmah
Guest







PostPosted: Tue Jun 27, 2006 4:00 am     Reply with quote

At heart, what you post should work, _but_ will kill the EEPROM in only a few minutes!...
As posted, the code sits writing the EEPROM, on every loop. There are no delays in the loop, if no buttons are pressed, so the loop 'time' will be a total of just on 4mSec/loop. This gives about 250 writes/second. The write endurance of the EEPROM, has a 'worst case' spec of only 100K cycles, so the chip could die in about 400 seconds. Even if the chip is better than this, and meets the 'typical' spec of 1M cycles on the EEPROM, this only rises to 4000 seconds. So anything between about 7 minutes, and an hour of this code, will kill the EEPROM...
I suspect this is what you have done.
Key is:
Only write the EEPROM if the value _has_ changed...

Best Wishes
prayami



Joined: 22 Dec 2004
Posts: 78

View user's profile Send private message

PostPosted: Tue Jun 27, 2006 3:29 pm     Reply with quote

Thanks....Ttelmah....you told very important thing....

I read from the previous post that: before writting eeprom, read it first
and check whether the value has changed or not. If changed then
only write and thus increasing the eeprom life. One question I have is
does those 100K cycle life also consider the eeprom reading? Means
if you read the eeprom number of times say more than 100K cycles than
also eeprom can dead..??


Is it require any delay before or after writting and reading EEPROM?.
Because of which it is reading 0 sometime.....

Thanks.....
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