need eeprom to save values


Closed Thread
Results 1 to 14 of 14
  1. #1
    Join Date
    Jun 2011
    Location
    Indian Harbour Nova Scotia
    Posts
    108

    Default need eeprom to save values

    I'm using a 12F675 to control a servo that swings back and forth like a pendulum. When the power goes off and comes back on, the servo resets to limits then starts to work on the narrower range I've specified.

    I want to use the EEPROM to save the values when the power goes off. (This servo is part of a really big project that gets turned on or off by one main switch).

    How do I detect the impending power loss and trigger the EEPROM to save the values? Then on power restoration I read the values.

    Or is a simpler way just to put stops on the servo until the program in the 675 "get going"? Or some kind of delay for the servo power?

  2. #2
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: need eeprom to save values

    why not save the range to eeprom and just use them on powerup ?

  3. #3
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: need eeprom to save values

    http://www.avrfreaks.net/index.php?n...57055&start=20

    just a quick google , may be worth a look

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: need eeprom to save values

    Use a FET to control the power supply, the FET will be controlled by the PIC.

    When you give the PIC the command to kill the FET jump to a routine to write whatever is needed to the EEPROM, then kill the FET.

    This thread has a couple schematics and discussion that should help.
    http://www.picbasic.co.uk/forum/showthread.php?t=19293
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: need eeprom to save values

    If you have a spare ADC pin available, than you can place a diode (1N4148 for example) and an electrolitic capacitor on the Vdd line to your pic. With the ADC you will monitor the power supply and when you detect a low ( you will establish the safe value) you will jump to the saving routine and write to eeprom all the necessary value the pic will need at start.

    An example of what I mean can be seen in the attached hand drawing.

    Cheers

    Al.
    Attached Images Attached Images  
    All progress began with an idea

  6. #6
    Join Date
    Jun 2011
    Location
    Indian Harbour Nova Scotia
    Posts
    108


    Did you find this post helpful? Yes | No

    Default Re: need eeprom to save values

    Quote Originally Posted by longpole001 View Post
    why not save the range to eeprom and just use them on powerup ?
    I don't think that will work, but will try. I say "may not work" because in the program itself, I start off by going to the lower limit, ie "my lower limit". I do not swing the servo to ITS limits, but rather a subset in-between. My problem is mostly a startup problem, starting the servo only after the program is running and no slamming it to either of the stops.

  7. #7
    Join Date
    Jun 2011
    Location
    Indian Harbour Nova Scotia
    Posts
    108


    Did you find this post helpful? Yes | No

    Default Re: need eeprom to save values

    been there. good info.

  8. #8
    Join Date
    Jun 2011
    Location
    Indian Harbour Nova Scotia
    Posts
    108


    Did you find this post helpful? Yes | No

    Default Re: need eeprom to save values

    thanks a lot for this. Good link.

  9. #9
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: need eeprom to save values

    Quote Originally Posted by queenidog View Post
    ... I want to use the EEPROM to save the values when the power goes off. (This servo is part of a really big project that gets turned on or off by one main switch).

    How do I detect the impending power loss and trigger the EEPROM to save the values? Then on power restoration I read the values.
    I do not believe this is possible, unless there is some other indication from the system of an impending power loss (or I misunderstand the nature of your inquiry). Two ideas come to mind, either use an alternate power supply to power the PIC after shut-down and "detect" the loss of main power to activate the write or, write the values routinely in the main program and start from them on power up each time.

  10. #10
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: need eeprom to save values

    Quote Originally Posted by Amoque View Post
    I do not believe this is possible, unless there is some other indication from the system of an impending power loss (or I misunderstand the nature of your inquiry). Two ideas come to mind, either use an alternate power supply to power the PIC after shut-down and "detect" the loss of main power to activate the write or, write the values routinely in the main program and start from them on power up each time.
    You isolate the PIC power from the power supply with a diode. Place a large cap on the PIC side of that diode to power the PIC when the power fails, and interrupt the PIC & write the eeprom when power failure is sensed on the other side of the diode. Very possible. HTH
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  11. #11
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: need eeprom to save values

    Quote Originally Posted by Archangel View Post
    You isolate the PIC power from the power supply with a diode. Place a large cap on the PIC side of that diode to power the PIC when the power fails, and interrupt the PIC & write the eeprom when power failure is sensed on the other side of the diode. Very possible. HTH
    Yes, thank you. For some reason I assumed the OP was suggesting that the PIC would be without power - in such a case writing to EEprom is clearly impossible. A battery or capacitor is an ideal solution - providing power AFTER the main is switched off. Yours (and others?) suggestions to provide power via a cap is a very efficient answer - allowing, with careful design - the ability to control the shutdown and perhaps even position the servo in a non-destructive position before exhausting the supply. Thanks again!

  12. #12
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: need eeprom to save values

    Please let me ask an obvious question. Why does the data have to be stored when power is taken away? Why can't it be stored then it is actually changed?
    Dave Purola,
    N8NTA
    EN82fn

  13. #13
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,520


    Did you find this post helpful? Yes | No

    Default Re: need eeprom to save values

    Hi,
    If you go the ADC route I suggest putting a voltage divider in between Vdd and the ADC input. Otherwise you're overdriving the ADC input, the internal protection diode from the input to Vdd may be forward biased (depending on its actual Vf compared to the 1N4148 or whatever).

    If the PIC has a comparator you may want to use that instead of the ADC because then you can set it up to trip an interrupt when the comparator output toggles - may be better than continously sampling the ADC. (The voltage divider still applies though.)

    /Henrik.

  14. #14
    Join Date
    Jun 2011
    Location
    Indian Harbour Nova Scotia
    Posts
    108


    Did you find this post helpful? Yes | No

    Default Re: need eeprom to save values

    Thanks all for responding. All good ideas that I will be sure to use in the future.

    I looked back at my project, which was to automate a 1/87 scale (HO train scale) dump truck so it's box would dump, reset, then dump again. For this I was using a servo with a sweep motion of about 90 degrees, not the full range of the servo (180 deg from stop to stop). This worked well except when I would shut off power and power-up. The servo would immediately jump to one of the stops, which was out of range of my sweep, then the program would run and everything would be fine. If the dump truck box had been connected, the servo would have lifted the entire truck off the layout. This is why I was wondering how I could save the last value I sent to the servo, power off, and when power came back on again, the servo would know where to start. (I put the initial value at the beginning of my program but this did not work: the servo still swung to one of the limits. In other words it did this BEFORE the program could actually run).

    So...employing the KISS principle (Keep it Simple Stupid), I decided there was a MUCH simpler way. I was so happy to be controlling servos, my judgement became cloudy. My solution is to use a simple DC gear motor under PWM control (easy with a PIC 12F1501), and operate the truck box with a crankshaft coming off the motor, basically an eccentric. Voila! Smooth operation, total speed control (and lots of torque thanks to PWM), no extra electronics required.

    All the ideas you gave me guys are still useful and I will use them in the future. I ain't done with servos.

Similar Threads

  1. Save a port number into the EEPROM?
    By Fredrick in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 20th August 2009, 09:06
  2. Save number cell in to EEprom
    By piombazzo in forum GSM
    Replies: 0
    Last Post: - 18th August 2008, 20:49
  3. Using serial eeprom to save data ?
    By iugmoh in forum General
    Replies: 4
    Last Post: - 8th February 2008, 08:36
  4. Replies: 5
    Last Post: - 29th January 2008, 09:19
  5. Replacing an ARRAY with EEPROM write to save space?
    By Tom Gonser in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th March 2005, 18:31

Members who have read this thread : 2

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

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