WRITE routine for EEPROM writing


Closed Thread
Results 1 to 6 of 6
  1. #1
    glaugle's Avatar
    glaugle Guest

    Default WRITE routine for EEPROM writing

    I tried emailing PBP tech support and I got referred to this forum. Please see my question below:
    Greetings,

    I am using the PicBasic PRO version 2.46 inside of MicroCode Studio version 2.3.0.0. I use MPASM to assemble. I am developing code for the PIC18F4620 device.

    I have noticed in the PBP Help that interrupts should be disabled when using the WRITE command for EEPROM writes. But, I cannot afford to do this, because I am relying on the interrupt service routine to keep pulling characters out of the RCREG whenever they are received. At 19200BPS, I get a new character every 469uS, but the EEPROM write command should take about 4mS. However, I also noticed in the PIC datasheet that the interrupts only need to be turned off for 5 critical instructions to occur prior to actually programming the EEPROM. So, I'd like to modify your WRITE command to do this. Otherwise, I'm going to have to write my own routine in assembly language, and I don't want to bother with that. I want to add 2 lines to your WRITE command, which will disable the GIE, then re-enable it, as shown in the PIC18F4620 datasheet section 7, Example 7-2.

    Can you tell me how I can do this? Do I have access to the source code inside of your pre-defined commands? If not, then can you make this change (or have you already) in an updated version?

    Any help on this would be greatly appreciated. If you need to know my license information, then I'm sure I can find that, but I don't know where it is at the moment.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi glaugle,

    We don't work for meLabs, but we still like to help out.

    You might take a look at this...

    EEPROM Variables (EE_Vars.pbp)
    http://www.picbasic.co.uk/forum/showthread.php?t=2444

    Even if you don't use the whole thing, look at the Write2EE: subroutine at the bottom of the EE_Vars.PBP file.

    It makes a pre-defined number of attempts to write to EEPROM, and reads it back each time. If it doesn't read the same thing back, it tries again, otherwise it succeded.

    If it doesn't succeed after so many attempts, it turns off the interrupts and does it one last time.

    I've tried it with several different interrupt programs, and have never had it actually turn-off the interrupts. It always gets it written within a few tries.

    HTH,
      Darrel

  3. #3
    glaugle's Avatar
    glaugle Guest


    Did you find this post helpful? Yes | No

    Default Thanks

    Thanks for your replies everyone, but I've gone ahead and just done it my way. All I really wanted was to disable interrupts during the 5 critical instructions that occur when setting up an EEPROM write, and then I wanted to re-enable them immediately after setting the WR bit, so that interrupts would be active during the 4mS EEPROM write-time. This is okay, and it is described clearly in the PIC datasheet. But, since I never did get access to the guts of the PBP "WRITE" routine, I just wrote my own routine. I called it "WRITE2", and it does what I need. I tested it on my bench for many thousands of EEPROM writes, and it never fails. This is much preferred over the re-try scheme, because the re-try scheme would introduce a lot of non-deterministic timings into my program, which I cannot afford. I am using this for motor control, so timing is critical. Thanks for the effort though.

    Cheers.
    GREG

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by glaugle
    Thanks for your replies everyone
    By "everyone", I assume you mean me. Possibly a good guess since I'm the only one that replied.
    All I really wanted was to disable interrupts during the 5 critical instructions
    Then, Duh!, disable them...
    Code:
    INTCON.7 = 0
    But, since I never did get access to the guts of the PBP "WRITE" routine,
    Double Duh!, look in your PBP folder for PBPPIC18.lib, and then search for "WRITE"
    I just wrote my own routine. I called it "WRITE2", and it does what I need.
    Of course, we will never see the code.
    I tested it on my bench for many thousands of EEPROM writes, and it never fails. This is much preferred over the re-try scheme, because the re-try scheme would introduce a lot of non-deterministic timings into my program,
    non-deterministic timings, this must have some profound meaning, but just cant find it in the dictionary.
    Thanks for the effort though
    Oh sure, happy to not help, any time you want.
    DT

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    At any rate; you're better off making your own version to begin with instead
    of modifying a PBP library function.

    If you attempt to install most PBP patches, they'll fail if you've modified the
    library, and installing the latest PBP upgrade overwrites the library again, so
    your approach was probably still the best one in the end anyhow..;o}

    As Darrel pointed out, the library is there, and easy enough to modify. Just be
    sure you know what you're doing, and make a backup copy before tinkering
    with the original library file.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    glaugle's Avatar
    glaugle Guest


    Did you find this post helpful? Yes | No

    Default Very amusing

    Darrel, okay, I see that you are the only one who replied to me on this post, but I was originally referred to a different discussion group by PBP Help, and some people over there tried to give some advice too. As for your first "Duh", yes thank you, I knew how to do that, but I couldn't find out where. Your "Double-Duh" response answered that question for me. Thank you. If you read my original question, that is what I was looking for. I just needed to know where to find the libraries. As for my new routine, it's nothing special, and the reason I didn't post it is that anything I write is company-confidential, no matter how small or simple. As for "non-deterministic", it basically means that the code has the ability to do different things on different runs. For example, if I used a retry scheme for the EEPROM, then on one run, it may be able to write the EEPROM on the first try, but on the next run, it may not do it until the second try. Well, then the second run would be skewed by about 4mS longer than the first. This makes digital filters and controls very hard to manage.

    Anyway, you have helped me. In the future, if I need to hack a PBP library, now I know where they hide them. And, as Bruce pointed out, I'm probably better off leaving them alone, since an upgrade to PBP would wipe out my changes, in case I forget what I've done.

Similar Threads

  1. WRITE: One more PBP 2.60 Surprise ...
    By Acetronics2 in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 26th August 2009, 09:10
  2. PIC16F684 + LCD to use the 256bytes of EEPROM - HELP
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 7th March 2008, 14:19
  3. Need the code to write to a memory
    By Hamlet in forum General
    Replies: 0
    Last Post: - 20th August 2007, 00:22
  4. Changing declared variables names on the fly
    By jessey in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th December 2006, 06:34
  5. Storing Strings using the Write command
    By BobP in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st November 2005, 11:31

Members who have read this thread : 1

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

Posting Permissions

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