Saving variable(s) contents before power is removed


+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2006
    Posts
    31

    Default Saving variable(s) content to EEPROM before power is cut-off

    Hi,

    I have this notion of saving memory variable(s) before power is cut-off. Anybody who has an idea. I'm using PIC16F628A with internal RC osc enabled and PICBasic Pro.
    Last edited by emavil; - 3rd February 2007 at 03:41.

  2. #2
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    347

    Smile

    Hi Emavil,

    You could monitor the PICs voltage supply for a loss and as soon as the PIC sees the voltage dropping write the variables to the EEPROM built-in to the PIC. As soon as the power up occurs you read back the vairables as part of your INIT routine.

    As for monitoring the power, I would put a 100uF capacitor on the PICs Vdd to ground and monitor the power coming into the power supply using something like an opto-isolator that will signal the loos of power coming in.

    HTH,

    BobK

  3. #3
    Join Date
    Jan 2006
    Posts
    31

    Default saving variable content to eeprom before power is cut-off

    Quote Originally Posted by BobK View Post
    Hi Emavil,

    You could monitor the PICs voltage supply for a loss and as soon as the PIC sees the voltage dropping write the variables to the EEPROM built-in to the PIC. As soon as the power up occurs you read back the vairables as part of your INIT routine.

    As for monitoring the power, I would put a 100uF capacitor on the PICs Vdd to ground and monitor the power coming into the power supply using something like an opto-isolator that will signal the loos of power coming in.

    HTH,

    BobK
    thanks BobK,

    yeah, an opto-isolator is a good option.

    Do i need to waste one I/O just to monitor power loss. Is there a hardware built-in to 648A that automatically detects power loss so that i can power simple housekeeping. How long does it take to perform this simple housekeeping?

    can u share to me a simple schematic for that opto-isolator solution?

  4. #4
    Join Date
    Oct 2005
    Location
    Loveland CO USA
    Posts
    83

    Smile save on power down

    The PIC16F628 has voltage comparators that can cause an interrupt. In the schematic the programmable reference is compared against a division of the input voltage. If input power falls dangerously low then an interrupt is generated.

    I do not see a way of monitoring supply voltage with out using a pin.

    Good luck!
    Attached Images Attached Images  

  5. #5

    Default

    Hi Emavil. This is a snippet of code I use with a 16F872 with eeprom. In case of power interruption it will go back to the mode it was in. The line at the top "IF MODE > 2 Then LET MODE = 0" is only valid with a newly programmed PIC. Once a write is performed, it will read a 0 or 1 or 2. Hope this helps.



    address VAR WORD 'address variable
    TRISA = %00110000
    TRISB = %11111101
    TRISC = %00000000
    Read 1,MODE
    IF MODE > 2 Then LET MODE = 0

    START:
    MAIN PROGRAM HERE


    CHANGEMODE:
    LET MODE = (MODE + 1) 'ADVANCE MODE
    IF MODE > 2 Then LET MODE = 0
    Write 1,MODE
    GoTo START

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,560

    Default

    Quote Originally Posted by ronsimpson View Post
    The PIC16F628 has voltage comparators that can cause an interrupt. In the schematic the programmable reference is compared against a division of the input voltage. If input power falls dangerously low then an interrupt is generated.

    I do not see a way of monitoring supply voltage with out using a pin.

    Good luck!
    Hi, Ron

    Good analysis ...

    you can even avoid using a comparator input, as the Schmitt trigger inputs High/Low thresolds of the pic are quite precise ( you can use pin polling instead of interrupts ).
    If no comparator available, you also can use a To 92 case MC 33064 P5 or equivalent which will drive its output pin LOW for voltage < 4.65 v.

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  7. #7
    Join Date
    Jul 2007
    Location
    Grass Valley CA
    Posts
    16

    Default Simple Analog Power Down Detector

    Drat. I hate doing this stuff without a blackboard.

    Large (several dozen uf) capacitor directly from Vcc of the uP to ground. Schottky diode in series between power supply and Vcc of uP. 10k resistor from power supply to ground.

    Bipolar PNP transistor emitter to Vcc, base to power supply through 10k resistor, collector to ground through 10k resistor. Collector will go to Vcc and slowly drop to zero when power is removed and capacitor slowly discharges. Use the Vcc pulse from the collector to an input port and check as many times as you like in your code as to whether or not this port has gone high.

    And I freely admit (see elsewhere in this section) that I am an absolute newbie at microcontrollers but can generally hold my own in the analog world.

    Jim

Similar Threads

  1. ADC Max Impendance and Power saving
    By Michael Wakileh in forum Schematics
    Replies: 3
    Last Post: - 28th June 2009, 20:29
  2. Battery powered applications
    By NavMicroSystems in forum Off Topic
    Replies: 7
    Last Post: - 22nd June 2009, 08:12
  3. 12 Servo's together does not seem to work, Power problem
    By macx75 in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 13th December 2006, 20:30
  4. Saving Variables
    By Tear in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 16th June 2005, 20:48
  5. saving program variables
    By Srigopal007 in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 2nd November 2004, 23:25

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts