• AVR Freaks

Hot!EEPROM Issues at 16f886

Author
Thyagaraj C
New Member
  • Total Posts : 4
  • Reward points : 0
  • Joined: 2018/01/24 05:54:58
  • Location: 0
  • Status: offline
2019/02/11 00:22:15 (permalink)
0

EEPROM Issues at 16f886

Hi Team,
we are using PIC16F886 controller for our project and providing the supply of 3.3V through LM317 regulator, Input to LM317 is 6 volt battery.
It is working fine till the battery gets drained, but once the battery is complitly drained, the EEPROM data is getting reset/giving some garbage value
after providing the supply again. Here when the battery voltage is reducing the LM317 output also comes down less than 3.3V.
This product has gone for the production and we are facing this issue at customers place. Request you to look on priority and provide the solution.
let us know for any more information.
 
Thanks,
Thyagaraj
#1

12 Replies Related Threads

    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11179
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: EEPROM Issues at 16f886 2019/02/11 10:08:45 (permalink)
    +1 (1)
    The PIC is browning out.
    #2
    coffee critic
    Super Member
    • Total Posts : 357
    • Reward points : 0
    • Status: offline
    Re: EEPROM Issues at 16f886 2019/02/11 10:12:59 (permalink)
    +1 (1)
    The LM317 is an incredibly stable and reliable regulator but it is not an LDO.  It needs at least 1.4V to maintain regulation. 

    n_*$
    #3
    jack@kksound
    code tags!
    • Total Posts : 3188
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: EEPROM Issues at 16f886 2019/02/11 11:03:17 (permalink)
    +1 (1)
    Probably in you program code. As @jtemples mentioned you need to detect the drooping Vdd voltage (BOR or brown-out-reset) and complete all EEPROM operation before the Vdd drops too low. Keep all EEPROM operation as short as possible so you can be sure to complete each set between the BOR reset and the Vdd falling below the minimum for proper EEPROM operation.
    #4
    Ian.M
    Super Member
    • Total Posts : 13225
    • Reward points : 0
    • Joined: 2009/07/23 07:02:40
    • Location: UK
    • Status: offline
    Re: EEPROM Issues at 16f886 2019/02/11 12:05:21 (permalink)
    +2 (2)
    coffee critic
    The LM317 is an incredibly stable and reliable regulator but it is not an LDO.  It needs at least 1.4V to maintain regulation. 

    It also needs typically 5mA, worst case 10mA through it to regulate correctly.    If your circuit draws less than that, (including your voltage set potential divider current) you may be getting more than 3.3V on your supposedly 3.3V rail.    I wouldn't expect more than about 5V assuming 6V max battery voltage, which is fortunately within your PICs operating range, but ii you have any 3.3V only chips on the same rail, you could easily destroy them all. 
     
    Its high minimum current for regulation makes it unsuitable for most battery powered applications.  I certainly wouldn't use it running from anything much smaller than a golf cart battery.
     
    By the time you get a BOR reset its too late - any EEPROM write in progress at that instant will be corrupted.  You can work around that with multiple copies of critical data with a checksum for each record, but it would be preferable to mod your circuit to use a LDO regulator to get more margin for declining battery voltage before the 3.3V rail starts to drop, and add a potential divider to let you directly monitor the battery voltage. e.g. reduce it to 50% to get it under 3.3V and take it to a PIC comparator input so you can detect low battery and prevent EEPROM writes before there is any risk of EEPROM corruption.

    --
    NEW USERS: Posting images, links and code - workaround for restrictions.
    I also support http://picforum.ric323.com because this forum is sometimes too broken to use!
    #5
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11179
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: EEPROM Issues at 16f886 2019/02/11 12:26:03 (permalink)
    +2 (2)
    By the time you get a BOR reset its too late

     
    The OP has not indicated that BOR is enabled, and I suspect it is not, in which case his issue is random code execution.  That's the first thing that needs to be fixed.
    #6
    Ian.M
    Super Member
    • Total Posts : 13225
    • Reward points : 0
    • Joined: 2009/07/23 07:02:40
    • Location: UK
    • Status: offline
    Re: EEPROM Issues at 16f886 2019/02/11 12:48:02 (permalink)
    +2 (2)
    I agree enabling BOR is necessary, as random code execution,  (if the write unlock critical sequence is present anywhere in the firmware), in addition to having a significant risk of causing EEPROM corruption, can even cause FLASH corruption.   The only difference between an EEPROM write at an address with its three LSBs set and a FLASH write is the state of the EECON1:EEPGD biit, (the critical sequence and setting the WR bit are identical), and if execution has already gone off into the weeds I wouldn't bet my job on that bit staying cleared.  However my point was: enabling BOR on its own isn't sufficient to guarantee to prevent EEPROM data loss.
    post edited by Ian.M - 2019/02/11 12:50:48

    --
    NEW USERS: Posting images, links and code - workaround for restrictions.
    I also support http://picforum.ric323.com because this forum is sometimes too broken to use!
    #7
    jack@kksound
    code tags!
    • Total Posts : 3188
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: EEPROM Issues at 16f886 2019/02/11 13:11:52 (permalink)
    +1 (1)
     enabling BOR on its own isn't sufficient to guarantee to prevent EEPROM data loss.

    Ian, I completely agree and was only trying to point out PART of the issue not present a complete solution,which as we know is not that easy to do (guarantee safe EEPROM writing that is).
    Your comments are very on-the-point of this (complex) issue.
    #8
    NKurzman
    A Guy on the Net
    • Total Posts : 17349
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: EEPROM Issues at 16f886 2019/02/11 16:57:16 (permalink)
    +1 (1)
    Beside the BOR as a safety measure you can Set EEADR to point to and unused address.  Some Older PICs had an issue with inadvertent writes during power down.  But, I do not thing the PIC16F886 was on of them.
    #9
    Mysil
    Super Member
    • Total Posts : 3324
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: EEPROM Issues at 16f886 2019/02/11 18:45:11 (permalink)
    +2 (2)
    Hi,
    When supply voltage is too Low, do not try to write in EEPROM at all!
     
    PIC16F886 have internal fixed voltage reference, nominally 0.6 V,
    that may be measured by ADC as channel 15:
         ADCON0bits.CHS = 15;
    Measure this ADC channel using power supply voltage as ADC reference voltage,
        ADCON1bits.VCFG = 0;
    Depending on what oscillator settings are used, the fixed voltage reference may need to be enabled by:
        SRCONbits.FVREN = 1;
     
    When power supply voltage become lower, ADC count from measuring FVR, will be higher.
    Depending on what margin is wanted, ADC count higher than 150 or 200 will indicate that supply voltage is reduced. This may need Calibration.
     
        Mysil
    #10
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: EEPROM Issues at 16f886 2019/02/11 18:50:29 (permalink)
    +2 (2)
    If you're accessing EEPROM, you MUST have BOR enabled.
    I know from sad experience that PIC16F87x devices can corrupt EEPROM locations even if just READ at low voltages.
    I suspect PIC16F88x devices are the same.
     

    Nearly there...
    #11
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11179
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: EEPROM Issues at 16f886 2019/02/11 19:34:31 (permalink)
    +3 (3)
    When supply voltage is too Low, do not try to write in EEPROM at all!

     
    The issue is not just a brownout happening while you're writing to EEPROM, it's that a brownout can cause random code execution which can cause unexpected EEPROM writes.  You cannot work around brownouts in software.  As qhb said, you MUST have BOR enabled (or have an external supervisor).
     
    #12
    madscientist99
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2019/02/21 11:02:37
    • Location: 0
    • Status: offline
    Re: EEPROM Issues at 16f886 2019/02/24 18:02:51 (permalink)
    0
    This raises an important point 
     
    If the BOR can corrupt a flash write and in a PIC18F- K series , with a fast external resonator , you only have a small window between the voltage/frequency oscillator graph and the BOR point.  Even if you monitor VddCore , you have very little time before the oscillator could fail 
     
    Its seems like a catch 22 situation , how do you reliably prevent flash corruption if you have a BOR that corrupts ! and an operating clock window, thats at or just below the BOR !
     
    Dave 
    post edited by madscientist99 - 2019/02/24 18:04:04
    #13
    Jump to:
    © 2019 APG vNext Commercial Version 4.5