[SOLVED] Internal EEPROM memory of PIC18F4550 Microcontroller issue

Status
Not open for further replies.

desgin

Full Member level 1
Joined
Apr 7, 2017
Messages
96
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
813
Hello All,

I am using internal EEPROM memory to store the data.
But if i am removing power, i am getting garbage value.
Code is working OK because read, write operation is happening.
But anybody please tell me about this power issue.
Please help me.

Regards
Desgin
 

Hi,

Where is your code, where is your schematic, where can we see what data you write into the EEPROM, how you verify it and what data you read from the EEPROM after power cycling?

Klaus
 

Seems to be he is trying to make 'power loss' aghorithm to store settings. This is have to be done mostly by schematic - 'power present' pin activate interrupt with highest priority, which is stores all the data to EEPROM and schematic have to keep power capacitor charged during all the writing cycle. So, the power loss pulse should come 10-20ms earlier than mcu will be unpowered.
 
Reactions: andre_luis

    andre_luis

    Points: 2
    Helpful Answer Positive Rating
    V

    Points: 2
    Helpful Answer Positive Rating
If you get excessive bouncing on the power supply switch (on and off) it can cause corruption of the EEPROM I assume you are not writing when the power is switched off. A large value capacitor after the switch may help.
 

Hi,

Where is your code, where is your schematic, where can we see what data you write into the EEPROM, how you verify it and what data you read from the EEPROM after power cycling?

Klaus

Thank u so much for reply.
ya my code is not at all an issue, it works fine with continous power.
If i am switching of my board, at starting getting garbage value for almost 1 minute then again getting correct data.
Sorry for late reply.

Please help me out !!

Thanks in advance !!!
 

So you are saying the data IS stored correctly but for some reason your code cant read it back for a minute after powering up?

Brian.
 
Reactions: desgin

    desgin

    Points: 2
    Helpful Answer Positive Rating
Hi,

you say the data is correctely stored in the EEPROM and the code is correct.
--> everything is correct.
--> but you say it is not correct.

***
We can´t verify a single piece, because you don´t give us the informations.

Klaus
 

If i am switching of my board, at starting getting garbage value for almost 1 minute then again getting correct data.

By this statement I have understood that you are switching off your board & not switching on. Kindly explain clearly the methods which you are following for writing the data at the location and also the method you are trying to read back at the same location during power on & Power off
 

So you are saying the data IS stored correctly but for some reason your code cant read it back for a minute after powering up?

Brian.

Yes, exactly
After 1 minute its getting correct data. That is reading the data whatever written in EEPROM memory.
So, tell me how to solve this problem ?

- - - Updated - - -


Thanks for reply.
Ya, after loading, able store data in EEPROM as well as read back from it.
But after removing power supply also it should works fine once power supply makes ON, right ?
But thats not happening, ist take 1 minute to read the data from EEPROM after again giving power supply back.
Till 1 minute, some garbage value is displaying on LCD :-(
I hope now yu understood what exactly i mean.
Sorry for bad english.

Thanks in advance
Desgin
 

Hi,

Sorry for bad english.
It's not the problem of language. The problem is that you don't show us schematic and code.

Klaus
 

That is a strange scenario though. You should be able to read back the EEPROM as soon as the processor has started up, in other words within a few mS.

This has to be a software problem, my first guess is an un-initialized timer is running through a complete count on it's first pass and it is holding up or diverting the program flow so the EEPROM read is unaccessible. We need to see your code to be sure.

Brian.
 

I hope now yu understood what exactly i mean.
Yes, Understood... But not completely.. What is the interface which you used between your EEPROM & PIC? What is the EEPROM which you are using in the design?
Share the part number.. If possible post your connection diagram.

Sorry for bad english.
The problem is not with your English. It is with your explanation. No issue provide the details requested to help you out.
 

What is the interface which you used between your EEPROM & PIC? What is the EEPROM which you are using in the design?
Share the part number.. If possible post your connection diagram.
You know what internal EEPROM of a PIC processor is?
 


For EEPROM, no need of any interface.
I am using Internal EEPROM. It Means, data will store in memory and read whenever i give command for read.
i am using PIC18F4550 Micro controller.
There is no connections for EEPROM. I am storing data by EEPROM write function & reading those data by calling that address of data, that's all.

Thanks in advance!!
Desgin
 

... which can only mean something in your software is preventing the EEPROM read being performed, or is overwriting the result until one minute has elapsed. This has to be a coding issue so we need to see what you have done to find a solution.


Brian.
 


Below is my code
Code:
#include "xc.h"
#include "lcd_display.h"

#pragma config PLLDIV = 1       // PLL Prescaler Selection bits (No prescale (4 MHz oscillator input drives PLL directly))
#pragma config CPUDIV = OSC1_PLL2// System Clock Postscaler Selection bits ([Primary Oscillator Src: /1][96 MHz PLL Src: /2])
#pragma config USBDIV = 1       // USB Clock Selection bit (used in Full-Speed USB mode only; UCFG:FSEN = 1) (USB clock source comes directly from the primary oscillator block with no postscale)

// CONFIG1H
#pragma config FOSC = INTOSC_HS//XT_XT//XT_XT     // Oscillator Selection bits (XT oscillator (XT))
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF       // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)

// CONFIG2L
#pragma config PWRT = OFF       // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOR = ON         // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
#pragma config BORV = 3         // Brown-out Reset Voltage bits (Minimum setting)
#pragma config VREGEN = OFF     // USB Voltage Regulator Enable bit (USB voltage regulator disabled)

// CONFIG2H
#pragma config WDT = OFF//ON         // Watchdog Timer Enable bit (WDT enabled)
#pragma config WDTPS = 32768    // Watchdog Timer Postscale Select bits (1:32768)

// CONFIG3H
#pragma config CCP2MX = ON      // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
#pragma config PBADEN = ON      // PORTB A/D Enable bit (PORTB<4:0> pins are configured as analog input channels on Reset)
#pragma config LPT1OSC = OFF    // Low-Power Timer 1 Oscillator Enable bit (Timer1 configured for higher power operation)
#pragma config MCLRE = ON       // MCLR Pin Enable bit (MCLR pin enabled; RE3 input pin disabled)

// CONFIG4L
#pragma config STVREN = ON      // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config LVP = OFF//ON         // Single-Supply ICSP Enable bit (Single-Supply ICSP enabled)
#pragma config ICPRT = OFF      // Dedicated In-Circuit Debug/Programming Port (ICPORT) Enable bit (ICPORT disabled)
#pragma config XINST = OFF      // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))

// CONFIG5L
#pragma config CP0 = OFF        // Code Protection bit (Block 0 (000800-001FFFh) is not code-protected)
#pragma config CP1 = OFF        // Code Protection bit (Block 1 (002000-003FFFh) is not code-protected)
#pragma config CP2 = OFF        // Code Protection bit (Block 2 (004000-005FFFh) is not code-protected)
#pragma config CP3 = OFF        // Code Protection bit (Block 3 (006000-007FFFh) is not code-protected)

// CONFIG5H
#pragma config CPB = OFF        // Boot Block Code Protection bit (Boot block (000000-0007FFh) is not code-protected)
#pragma config CPD = OFF        // Data EEPROM Code Protection bit (Data EEPROM is not code-protected)

// CONFIG6L
#pragma config WRT0 = OFF       // Write Protection bit (Block 0 (000800-001FFFh) is not write-protected)
#pragma config WRT1 = OFF       // Write Protection bit (Block 1 (002000-003FFFh) is not write-protected)
#pragma config WRT2 = OFF       // Write Protection bit (Block 2 (004000-005FFFh) is not write-protected)
#pragma config WRT3 = OFF       // Write Protection bit (Block 3 (006000-007FFFh) is not write-protected)

// CONFIG6H
#pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) are not write-protected)
#pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot block (000000-0007FFh) is not write-protected)
#pragma config WRTD = OFF       // Data EEPROM Write Protection bit (Data EEPROM is not write-protected)

// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protection bit (Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF      // Table Read Protection bit (Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTR2 = OFF      // Table Read Protection bit (Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTR3 = OFF      // Table Read Protection bit (Block 3 (006000-007FFFh) is not protected from table reads executed in other blocks)

// CONFIG7H
#pragma config EBTRB = OFF      // Boot Block Table Read Protection bit (Boot block (000000-0007FFh) is not protected from table reads executed in other blocks)


#define _XTAL_FREQ 20e6

unsigned char d0,d1;
unsigned char e_address;
unsigned char e_data;

void main()
{
    ADCON1 = 0x0F;     
    TRISD = 0;
    lcd_display_on();
    EECON1bits.CFGS = 0;
    
    EEPROM_Write(0xF0, 0x30);
    d0 = EEPROM_Read(0xF0);
    lcd_data(d0); 
    
    EEPROM_Write(0xF1, 0x31);
    d1 = EEPROM_Read(0xF1);
    lcd_data(d1);    
       
    while(1) 
    {}  
}



void EEPROM_Write(unsigned char e_address, unsigned char e_data)
{
    EEADR = e_address;
    EEDATA = e_data;
    EECON1bits.EEPGD = 0;    
    EECON1bits.WREN = 1;    
    INTCONbits.GIE = 0;        
    EECON2 = 0xAA;
    EECON1bits.WR = 1;        
    INTCONbits.GIE = 1;        
    EECON1bits.WREN = 0;    
    while(PIR2bits.EEIF == 0)
    {
    }
   PIR2bits.EEIF = 0; 
}

unsigned char EEPROM_Read(unsigned char e_address)
{
    EEADR = e_address;
    EEDATA = e_data;
    EECON1bits.EEPGD = 0;    
    EECON1bits.WREN = 0;    
    EECON1bits.CFGS = 0;    
    EECON1bits.RD = 1;        
    return(EEDATA);
}
 
Last edited by a moderator:

I am using Internal EEPROM.

Sorry I misunderstood your question and got confused with another post.

Could you please try by providing some delay immediately after enabling the interrupts.. Generally, There must me at least 20ms delay between successive usage of routines
 

The write to EEPROM unlock sequence is wrong, it shouldn't be writing anything to EEPROM at all.

You MUST use the exact sequence of writing 0x55 to EECON2 then writing 0xAA to EECON2. You are missing out the 0x55 part.

Brian.
 

The write to EEPROM unlock sequence is wrong, it shouldn't be writing anything to EEPROM at all.

You MUST use the exact sequence of writing 0x55 to EECON2 then writing 0xAA to EECON2. You are missing out the 0x55 part.

Brian.

Ya that was already that but missed in posting. Sorry.
Write and read is already happening sir!!
Problem is, of that garbage value.
Should i post it again ??

Thanks in advance!!
 

Yes, please post again.
Is that the whole program? If it is, how do you know it doesn't read back properly as it writes fresh data each time it is run.

Brian.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…