Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

PIC problem

  1. Nov 5, 2007 #1
    I hope I am putting this in the right forum (it is Hardware and Software)but here it goes.

    I am having a problem with my PIC18F1220 keeping its EEPROM settings. it has thrown me for a loop for a while. Here is how it goes.

    In simulation it works perfectly,

    When running for the first time it loads default settings by detecting the presents of settings within the EEPROM

    There after you load your settings Via. RS232 it places them in the EEPROM the EEPROM is then referenced every time the board is turned on.

    Global variables are referenced and set when ever you communicate the settings as a "working" table independent from the EEPROM and are used for program operation.

    What happens in real life is:

    It does not load default settings on the first start up

    it will set the working table as can be verified by the RS-232 com. but the program will not use them for program operation I.E. the Duty Cycle will show changed but the board will not use the new settings and the EEPROM will not be updated with the new settings.

    A problem with my program you say? (of course!)

    But here is the kicker!

    if you program the PIC and then read the EEPROM from the programmer the first time it will show blank "all FFs" but if you load it the second time it will show that the internal (load default) subroutine has worked.

    And on top of that. It all works perfectly after that!

    I don’t get it! Its simple you just program it and run it and it does not work! You read the EEPROM two times and it Works exactly as it was designed!

    if you mess with the power (brown outs) rapid on-off on-off cycles it will loose the EEPROM settings and you will have to re read the EEPROM twice to get it to work again.

    I tried resetting with /MCLR but to no avail!

    Has anyone else had this problem? ANY help will be greatly appreciated!

    If you have an idea and want to see part of the code I will be happy to post it!

    Thank you.
  2. jcsd
  3. Nov 5, 2007 #2


    User Avatar
    Science Advisor
    Homework Helper

    Not enough info.
    Is this a manufactures demo board you are using?
    Sounds like you are saying that a built in function is not working rather than some code you wrote.

    If so my guess is that one of the addressing latches to the EEPROM is not being reset at power up or on /MCLR so there may be a fialure in the reset circuitry.
  4. Nov 6, 2007 #3


    User Avatar

    Staff: Mentor

    There are some subtleties to PIC EEPROMs -- have you read the datasheet in detail about how to work with the EEPROM? I remember something from a recent project about protected and non-protected areas of EEPROM, and how you had to access them differently. I'd suggest pouring over the PIC documentation from the Microchip website -- you should be able to get some clues there.
  5. Nov 6, 2007 #4
    Yea I have read and re read the documentation. I even used the exact procedure in order to what the datasheet recommended. I will re read it as I have nowhere else to go from. I do think that if I solve the EEPROM issue the other issue will be solved even though I don’t see how they are connected. (They are proven though, to be connected… somehow)

    As far as the project goes. It is a board that I designed and the EEPROM demands aren’t that demanding. I am using the PIC18F1220 at 40Mhz (10Mhz PLL) and am using the addresses 00 through 05.

    The circuit is simple. 5V supply coming off of a small onboard switching power supply filtered through a 1000Uf cap with .01 uf decoupling caps sprinkled on the board at usual places. There is a pull-up resistor on the /MCLR pin valued at 4.7K but 10K (spec.) was also tried. It uses ICSP with all lines dedicated to the PIC. There are 4 ports used to operate power transistors, one port with a PWM output, RX TX to a MAX 202 transceiver and 5.04V +- .001V to the chip. That’s it. As far as the internal programming goes that is a bit more complex but the specifics on the EEPROM write are:

    void PTEE (int DAT,int ADRS) //Writes data into the EEPROM
    EECON1bits.EEPGD = 0;
    EECON1bits.WREN = 1;
    INTCONbits.GIE = 0;
    EECON2 = 0x55;
    EECON2 = 0xAA;
    EECON1bits.WR = 1;
    while(PIR2bits.EEIF == 0); //wait for write to complete
    PIR2bits.EEIF = 0;
    int GTEE (int ADRS) //Returns a byte stored in the address denoted by ADRS
    EECON1bits.EEPGD = 0;
    EECON1bits.RD = 1;
    return EEDATA;
    int GetDutyCycle (void)
    return GTEE(0);
    void PutDutyCycle (int DC)
  6. Nov 7, 2007 #5
    I am thinking there is something wrong with the chip, when power is removed for a length of 4 hours the EEPROM reads blank, actually all 32. Anyway I am planning on replacing the chip soon. Any ideas on making the replacement of a 28 pin QFN chip easier? Taking it off with a butane torch is easy, but soldering a new one is a little harder. I used a reflow process to solder it in the first place. Anyway thanks for looking at the problem.

  7. Nov 7, 2007 #6


    User Avatar

    Staff: Mentor

    On the chip problem, I'd suggest contacting Microchip Technical Support:


    It looks like you have to register in order to submit a support ticket, but presumably it is free support at the initial contact level. Also (you probably have done this), be sure to look at the reference design schematics for that part, to be sure that your circuit is the same as is used on the Evaluation Boards.

    On replacing the SMT chip, there was a pretty good thread about SMT rework recently....(searching)....This is close to what I was thinking of:


    Normally you would use a hot-air SMT rework gun to remove the chip (not a blowtorch!), and a good soldering iron like the Metcal to solder the new one on. You'll need a magnifying lamp (or a binocular microscope like we use) to be able to see the little bitty leads for accurate soldering.
  8. Nov 7, 2007 #7


    User Avatar
    Science Advisor
    Gold Member

    I don't know what compiler you are using but I have heard of compilers causing things that seem impossible. This is not first hand experience though as I am just getting started myself with PIC microcontrollers.
  9. Nov 9, 2007 #8
    Yea the circuit is typical, the compiler is C18, and well a small butane torch works well and fast, you should try it sometime! As far as soldering goes most SMT is simple to rework (I like it more then DIP and other pinned packages) but the QFN is leadless and has a sink pad in the center, I could use a hot air iron but I have not had any luck with it as I think I am heating it too fast.
    thanks for the replies.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook