Today 05:03
Forum: The Lounge
Starter: charliecoultas
Views: 0
Replies: 10
Go to last post By: shantanu@india
Yesterday 13:16
Forum: The Lounge
Starter: shantanu@india
Views: 0
Replies: 16
+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: PIC 24f Memory write723 days old

  1. #1
    Junior Member deutrion's Avatar
    Join Date
    Jan 2009
    Posts
    25
    Thumbs Up
    Received: 0
    Given: 39
    Total Downloaded
    3.57 GB

    0 Not allowed!

    Default PIC 24f Memory write

    Hi,

    Can I write a data to the PIC24F series microcontroller.
    I want the data to be saved in the microcontroller when power is off,
    but does not want to use external EEPROM IC.
    How do I do that?

    Thank you.

  2. #2
    Member matty's Avatar
    Join Date
    Dec 2003
    Posts
    115
    Thumbs Up
    Received: 6
    Given: 3
    Total Downloaded
    228.03 MB

    0 Not allowed!

    Default Re: PIC 24f Memory write

    Dear Deutrion,

    I have faced this problem before and could not solve it.

    Before I tried Proton 24 Very recently I got my first taste of 33F Device using C30 Compiler (booo the dark side)

    Using a 33FJ32GP202 28 pin through hole device to make a fast closed loop motor positioner with C30 Compiler.

    Only later on did I realise towards the end of my C30 project the darn 33FJ32GP202 had no internal EEPROM oh no.

    I studied for days microchip "AN1095" Application note EMULATING EEPROM In DPICS,

    Yes theoretically yes you can write to flash from within your program as the PIC24 33F etc can write data to its own flash memory to save data just like an EEprom would.

    However after studying the AN1095 it just seemed so complex it was above my level of experience to implement

    however if you are feeling brave and study it hard enough for long enough time that document AN1095 shows you how to implelment software to write to the 24x internal flash to emulate eeprom.

    In the end I gave up and was beaten I used a 24LC16 External EEPROM the link below shows the full project

    http://www.microchip.com/forums/m858053.aspx

    The last pages of the above thread have my attached C code example of 33F writing to EEPROM.

    I hope someone on the 24 Forum has en example of writing to flash of a DSPIC to EMULATE eeprom otherwise again Ill be forced to use external EEPROM I2C on my 33EP512MU810 tripple mcu project

    Hope this is helpfull Deutrion AN1095 tells you how to do it in detail but I couldnt implement this as it was to complex for my level of experience and I was forced into using an external EEPROm

    Cheers Matthew

  3. #3
    Member tumbleweed's Avatar
    Join Date
    May 2011
    Posts
    334
    Thumbs Up
    Received: 54
    Given: 0
    Total Downloaded
    95.95 MB

    0 Not allowed!

    Default Re: PIC 24f Memory write

    You can use a page of the internal flash memory to emulate an EEPROM, but you need to be aware that the two types of memory are very different and may not be suitable for what you want to do.

    The internal flash has to be erased in pages vs single bytes for a typical EEPROM, and the number of times you can write/erase it are MUCH lower (typ 10K vs 1M-10M)

  4. #4
    Administrator John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    2,965
    Thumbs Up
    Received: 94
    Given: 28
    Total Downloaded
    1.39 GB

    1 Not allowed!

    Default Re: PIC 24f Memory write

    I came up against this too for a new project. I need to store values long term. As I will be using the RTCC and need to battery backup I thought I'd just have a 'factory default' in program memory and then store the changed values in RAM. Then I'd put the device to sleep when the power went off and hopefully just have a tiny current for the RTCC and the sleep condition with RAM kept alive.
    I really don't want to put an extra chip on board for data storage. I really got used to the EEDATA in the 8bit uP. Any other thoughts.
    John

  5. #5
    Junior Member Ken's Avatar
    Join Date
    Feb 2016
    Posts
    5
    Thumbs Up
    Received: 2
    Given: 3
    Total Downloaded
    332.47 MB

    0 Not allowed!

    Default Re: PIC 24f Memory write

    Hi,

    I have been reading the Proton 24 manual and this forum for quite some time to shed light on how to write in program flash memory after compiling my code, unfortunately I did not find any.
    And just like Matthew, studying AN1095, Emulating Data EEPROM for PIC18 and PIC24 MCUs and dsPIC DSCs is beyond my level of experience.

    I hope someone could help me out.

    Thanks in advance.

    Ken

  6. #6
    Administrator John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    2,965
    Thumbs Up
    Received: 94
    Given: 28
    Total Downloaded
    1.39 GB

    2 Not allowed!

    Default Re: PIC 24f Memory write

    There's an article in the WIKI that might help Ken.
    John

  7. #7
    Junior Member Ken's Avatar
    Join Date
    Feb 2016
    Posts
    5
    Thumbs Up
    Received: 2
    Given: 3
    Total Downloaded
    332.47 MB

    0 Not allowed!

    Default Re: PIC 24f Memory write

    Hi John,

    I still could not find that article in WIKI, but I was able to do it somehow using erase and BTLWT. I am still trying to convert everything in PicBasic from assembly. The good thing is that it is working right now.

    Thanks.

    Ken

  8. #8
    Administrator John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    2,965
    Thumbs Up
    Received: 94
    Given: 28
    Total Downloaded
    1.39 GB

    0 Not allowed!

    Default Re: PIC 24f Memory write

    Hi Ken
    Here it is - link

    I know it's for the 18F series but the code should hold good for P24. There have been other posts on this topic. I think Les contributed at one stage.
    I haven't used CWRITE for storage of changing values myself yet. Like you I put it in the too hard bucket and mostly use PIC18F and the eedata unless I need menu strings in which case I'll use CDATA entered at program time.
    John

    Last edited by John Drew; 24th March 2018 at 00:35. Reason: Added extra comment

  9. #9
    Junior Member Ken's Avatar
    Join Date
    Feb 2016
    Posts
    5
    Thumbs Up
    Received: 2
    Given: 3
    Total Downloaded
    332.47 MB

    1 Not allowed!

    Default Re: PIC 24f Memory write

    Hi John,

    I have seen that example before and tried it my self but CWRITE is not supported for Pic24.
    Here is how I did it and I am sure there is a better way of doing this.

    Device = 24FJ16GA004
    Declare Xtal= 16 ' Set OSC to 16MHz


    Dim vMemory[64] As Word
    Dim x As Byte


    '----------------------------
    ' FLASH ERASE
    '----------------------------
    F_ERASE: ' Setup block erase operation
    NVMCON = $4042 ' Initialize NVMCON bits
    TBLPAG = 0 ' Initialize PM Page Boundary SFR
    WREG8 = $1400 ' Initialize in-page EA<15:0> pointer and
    ' base address of erase block

    Asm
    TblwtL W8, [W8] ' Set base address of erase block
    Disi #5 ' Block all interrupts with priority <7
    EndAsm ' for next 5 instructions


    NVMKEY = $55 ' Write the 0x55 key
    NVMKEY = $AA ' Write the 0xAA key
    NVMCON.15 = 1 ' Start the erase/write sequence
    Nop ' Insert two NOPs after the write sequence
    Nop
    While NVMCON.15 = 1 : Wend ' wait until erase/write operation is complete
    Return
    '----------------------------
    ' FLASH WRITE
    '----------------------------
    F_WRITE: ' Modified Flash Write / Tidying
    ' Setup write by row operation
    NVMCON = $4001 ' Initialize NVMCON
    TBLPAG = 0 ' Initialize PM Page Boundary SFR
    WREG8 = $1400 ' starting address for writing data


    For x = 0 To 63 ' pre-load SAMPLE values for Testing
    vMemory[x] = x
    Next


    For x = 0 To 63 ' perform TBLWT to write the latches
    WREG4 = vMemory[x] ' move variable to W4
    Asm
    Mov #0x0000, W5 ' clear High Word
    TblwtL W4, [W8] ' Write PM low word into program latch
    TblwtH W5, [W8++] ' Write PM high byte into program latch
    EndAsm
    Next


    Asm ' Apply Write operation
    Disi #5 ' Block all interrupts with priority <7
    EndAsm ' for next 5 instructions


    NVMKEY = $55 ' Write the 0x55 key
    NVMKEY = $AA ' Write the 0xAA key
    NVMCON.15 = 1 ' Start the erase/write sequence
    Nop ' Insert two NOPs after the write sequence
    Nop
    While NVMCON.15 = 1 : Wend ' wait until erase/write operation is complete
    Return
    '----------------------------
    ' FLASH READ
    '----------------------------
    F_Read: ' Read Virtual EEPROM
    wAddress = $1400 ' Load Virtual EEPROM base address
    For x = 0 To 63 ' x64 memory locations
    vMemory[x] = cPtr16 (wAddress++) ' Read from Virtual EEPROM data storage 0x1400 to 0x143F
    Next
    Return

    Thanks again.

    Ken

  10. #10
    Administrator John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    2,965
    Thumbs Up
    Received: 94
    Given: 28
    Total Downloaded
    1.39 GB

    0 Not allowed!

    Default Re: PIC 24f Memory write

    Hi Ken,
    Well done.
    As things get lost in the forum I wonder if you would write up a brief article in the WIKI?
    It would be good if you had a demo main to illustrate its use too.
    If you do write it up send me a private message with the heading you've used and I'lll publish it for you.
    WIKI/Example code/Proton24 would be a good location.
    Best wishes
    John

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Write to flash memory after compile time?
    By electronicsuk in forum Proton Plus Compiler v3
    Replies: 3
    Last Post: 17th November 2014, 20:43
  2. How to write in program memory?
    By pdgnr in forum Proton Plus Compiler v3
    Replies: 2
    Last Post: 5th March 2006, 07:14
  3. PIC with external memory
    By vpapanik in forum The Lounge
    Replies: 0
    Last Post: 11th October 2005, 14:35

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