Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

using EEPROM at high clock frequency

Status
Not open for further replies.

hhhsssmmm

Member level 1
Joined
May 14, 2009
Messages
37
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,732
hello

Im using a pic18f4220 with the C18 compiler.

I have successfully written and read back from EEPROM two bytes of data using 4MHz ceramic resonator.

Next I attemted to perform the same write and read operation from the EEPROM using a 10MHz ceramic resonator.
This did not work at all. My data is not being written in the address location....nor can it be read.

I then decided to use 20MHz and then all the way up to 40MHz.......and i got the same problem.
The EEPROM simply refuses to read or write anything above 4MHz clock speed.

Is this an issue with the pic18F4220?

I have used EEPROM read and write at successfully at 20MHz on a pic18f2420 and i had NO problems.

please can some one suggest how to solve this problem.

thank you

haseeb
 

Hi hhhsssmmm,

Is the problem only for reading and writing EEPROM at high freqs? Are you sure all other things are working all right? Did you set the configuration word correctly when you used the new high frequency?
 

EEproms live in their own world, ie. they use internal timing for certain sequences and no matter what clock your MCU has, the EEPROM timings will not change ..
Data sheets are the best place to find out for how long you have to “leave an EEprom alone” when you issue, for example, a WRITE command ..
So, if you increase the MCU’s clock frequency you have to increase delays in your program while accessing EEprom ..

Rgds,
IanP
 

ok here is my code below.

its a simple EEPROM write and read test program.

Im using the following...

40MHz HSPLL (10MHz ceramic resonator)
PIC18F4220
C18 compiler

the result of this program should be a simple LED flash twice which it does after a successful read from the EEPROM.

However upon verifying this result in the MPLAB PM3 programmer, when reading the EEPROM, the result comes out completely blank in the EEPROM window. The data byte 0xEA is never written in the EEPROM location 0x00.

The same happens with 10MHz or 20Mhz clock speed. HOWEVER, the same program and EEPROM verification via PM3 programmer results perfectly only when I use a 4MHz ceramic resonator.

I have also tried changing the PIC to one of serveral PIC18F4220 that I have....but all give the same results as above.

From the above test results of my program i assume (plz correct me) that when i place the PIC on to the MPLAB PM3 programmer to read the the EEPROM, then during power down the PIC loses the EEPROM content. This is strange. I have a clean 7805 stable 5V output for the PIC. Before i take the PIC out from my board, the power supply is shut off for a moment and then I take out the PIC.

Please can someone help me out that for any clock speed above 4MHz, why does the EEPROM is not able to retain its contents after the power down.

thankyou

Haseeb



Code:
#include <p18f4220.h>
#include <delays.h> 

#pragma config OSC = HSPLL
#pragma config WDT = OFF
#pragma config LVP = OFF

#define LED LATCbits.LATC3

unsigned char              
              HighByte = 0;       

void main(void)
{     

  ADCON1 = 0x0F; //SET ALL PORTS as DIGITAL I/O

  //initiallize all PORTs     
  PORTA = 0;
  PORTB = 0;  
  PORTC = 0;   
  TRISCbits.TRISC3 = 0;  //LED output
  PORTD = 0;
  PORTE = 0;

  INTCON = 0; //disable all INTs

  //byte write   
  EECON1bits.EEPGD = 0; //Ensure EEPGD is clear for EEDATA access   
  EECON1bits.WREN = 1; // //Ensure WREN is set to enable for no EEDATA writes    
  EEADR = 0x00; //Write address to EEADR at the respective location   
  EEDATA = 0xEA; //Set EEDATA to the value to write
  EECON2 = 0x55;
  EECON2 = 0xAA;           
  EECON1bits.WR = 1; //Initiate write cycle by setting the WR bit      
  while (!PIR2bits.EEIF); //Wait for the EEIF flag to be set           
  PIR2bits.EEIF = 0; //Clear the EEIF flag             
  EECON1bits.WREN = 0; // //Ensure WREN is set to dissable for no EEDATA writes

  //byte read
  EECON1bits.EEPGD = 0; //Ensure EEPGD is clear for EEDATA access                   
  EEADR = 0x00; //Store the address to EEADR               
  EECON1bits.RD = 1; //Trigger a read by setting the RD bit           
  HighByte = EEDATA;

  if(HighByte == 0xEA)    //are u the same byte read back from EEPROM?
  {                   

        //confirm correct byte read via LED flashing

        LED = 1;   
        Delay10KTCYx(250); //250ms delay    
        LED = 0;
        Delay10KTCYx(250); //250ms delay
        LED = 1;
        Delay10KTCYx(250); //250ms delay
        LED = 0;

  }

  while(1); //loopforever (STOP)

} //end of main()
 

Have a look at **broken link removed**. I use it without any problems for different clockspeeds, upon internal speeds of 48Mhz... The PIC used in the link has a similar architecture as the one you used, so the code should also work for your microcontroller.

edit: just compared both, they look pretty much the same...
One difference, interrupts can be disabled with INTCONbits.GIE = 0; as is shown in the datasheet. Some PIC families contain a bug for disabling interrupts, causing switching of the interrupts to fail sometimes. Then you should write
Code:
while (INTCONbits.GIE) INTCONbits.GIE=0
But I though that this bug does not apply on the 18F PIC family...

Maybe the problem is not the eeprom, but the clock frequency settings? You can check it by letting the led blink in both cases.
 

Thank you for your help.

I have solved the problem for the EEPROM read and write for any clock speed....
high or low...

the solution was a missing code line statement that should have been there in the read and write routines of my EEPROM coding....

that line is as follows:

Code:
EECON1bits.CFGS = 0; //Access Data EEPROM

Now my program works flawlessly.

Many thanks for your consideration and helping me.

Regards
Haseeb
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top