AN1095. Emulating Data EEPROM for PIC18 and PIC24 Microcontrollers and dspic Digital Signal Controllers INTRODUCTION THEORY OF OPERATION

Please download to get full document.

View again

of 18
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Information Report
Category:

News & Politics

Published:

Views: 0 | Pages: 18

Extension: PDF | Download: 0

Share
Related documents
Description
A1095 Emulating Data EEPROM for PIC18 and PIC24 Microcontrollers and dspic Digital Signal Controllers Author: ITRODUCTIO Microchip Technology Inc, has expanded its product portfolio to include a wide variety
Transcript
A1095 Emulating Data EEPROM for PIC18 and PIC24 Microcontrollers and dspic Digital Signal Controllers Author: ITRODUCTIO Microchip Technology Inc, has expanded its product portfolio to include a wide variety of cost-effective PIC microcontrollers (MCUs) without an internal data EEPROM Many applications store nonvolatile information in the Flash program memory using table write and read operations Applications that need to frequently update this data may have greater endurance requirements than the specified Flash endurance for the device The alternate solution of using an external, serial EEPROM device may not be appropriate for cost-sensitive or pin-constrained applications This application note presents a third alternative that addresses these issues This algorithm features an interface similar to an internal data EEPROM, uses available program memory and can improve endurance by a factor as high as 500 ote: David Otten, Stephen Cowden and Pradeep Budagutta Microchip Technology Inc To use this solution, the device must have word write capability Refer to the specific device data sheet to verify this feature is available Definition of Terms Page The minimum amount of program memory affected by an erase operation Row The maximum amount of program memory affected by a programming operation Erase/Write Cycle The number of erase and write operation pairs Endurance A specification indicating the maximum number of erase/write cycles and associated conditions Retention A specification indicating the minimum length of time and associated conditions for the retention of data in Flash memory Effective Endurance The improved endurance of the emulated data EEPROM as a result of using an efficient programming algorithm Current (Active) Page A page in program memory that is being written and read by the data EEPROM emulation algorithm Packed Page The new current page after the pack routine is complete Page Status Program memory location(s) at the beginning of the current page that stores data EEPROM emulation status The PIC18 implementation uses two locations and the PIC24/dsPIC33F uses one THEOR OF OPERATIO The algorithm in this application note supports selectable, multiple emulated data EEPROMs with a total size of up to multiples of 255 locations, with a single address space, ranging from 0 to the total size of the emulated data EEPROMs minus one (see the below note) For example, if the implemented size of the data EEPROM is 5, and two data EEPROMs are used, only the addresses in the range, 0 to 9, are available ote: PIC18 implementation supports 8-bit data and multiple EEPROM banks; PIC24/dsPIC33F implementation supports 16-bit data and multiple EEPROM banks Due to architectural differences of the program memory, the emulated data EEPROM information is stored differently for 8-bit and 16-bit implementations For these formats, see Table 1 and Table 2 TABLE 1: The PIC18 and PIC24/dsPIC33F implementations support multiple EEPROM banks Each EEPROM can have a maximum of 255 addresses Hence, the total addresses are from 0 to x 255 1, where = number of EEPROM banks PIC18 DATA EEPROM IFORMATIO FORMAT I PROGRAM MEMOR Bits 15-8 Bits 7-0 Data EE Data Data EE Address 2009 Microchip Technology Inc DS01095C-page 1 A1095 TABLE 2: PIC24/dsPIC33F DATA EEPROM IFORMATIO FORMAT I PROGRAM MEMOR The algorithm takes advantage of the PIC microcontroller s ability to self-program a single location of program memory This location is an 8-bit operation for PIC18, and either an 8 or 16-bit operation for PIC24 and dspic33f, depending on whether an odd or even address is being written, respectively ote: Bits Bits 15-0 Data EE Address PIC24/dsPIC33F Scenario Data EE Data For more information on program memory organization, refer to the applicable product data sheet To better understand how the algorithm works, here is a simple scenario for the PIC24 and dspic33f After the first page of each EEPROM bank is initialized, the first location is reserved for the page status information This indicates whether a page is active or expired, and how many erase/write cycles have been performed This information is not directly accessible by the user, but is used by the algorithm to find available pages and update status flags This page is designated as the current or active page In this example, a write operation has been performed to store a data value of 0x0202 to data EEPROM address, 0x2 As provided in Table 3, this information is stored in the first available location in the page As more writes are performed, the algorithm continues to write the information in a similar fashion, as provided in Table 4 through Table 6 In this example, data EEPROM address, 0x7, is written with 0x0707, 0x2 is updated to 0x2222 and address, 0xA, is written with 0x0A0A In Table 7, the last location in the page is written with a rewrite to address 0x7 to 0x7777 Since the currently active page is now full, the data EEPROM information will move to the next available page This new page is referred to as the packed page The pack routine performs this task Since only the most current data for each data EEPROM address is needed, the amount of information decreases After the data is moved, this page is designated as the current page If the current page has incremented through all allocated pages in program memory, the erase/write count is incremented as displayed in Table 8 The page is now ready to store more information via write operations The PIC18 algorithm works in a similar way, but instead of reserving one location of program memory for page status information, two locations are used Also, 8-bit data is stored instead of 16-bit data DS01095C-page Microchip Technology Inc A1095 TABLE 3: WRITE DATA EEPROM (0x0202, 2) TABLE 4: WRITE DATA EEPROM (0x0707, 7) Page Address Data EE Address Data EE Data Page Address Data EE Address Data EE Data Page + 0 Page Status 23:16 0x0000 Page + 0 Page Status 23:16 0x0001 Page x0202 Page x0202 Page + 4 0xFF 0xFFFF Page x0707 Page + 6 0xFF 0xFFFF Page + 6 0xFF 0xFFFF Page + 8 0xFF 0xFFFF Page + 8 0xFF 0xFFFF Page xFF 0xFFFF Page xFF 0xFFFF TABLE 5: WRITE DATA EEPROM (0x2222, 2) TABLE 6: WRITE DATA EEPROM (0x0A0A, 0xA) Page Address Data EE Address Data EE Data Page Address Data EE Address Data EE Data Page + 0 Page Status 23:16 0x0000 Page + 0 Page Status 23:16 0x0000 Page x0202 Page x0202 Page x0707 Page x0707 Page x2222 Page x2222 Page + 8 0xFF 0xFFFF Page + 8 0xA 0x0A0A Page xFF 0xFFFF Page xFF 0xFFFF TABLE 7: WRITE DATA EEPROM (0x7777, 7) TABLE 8: PAGE AFTER PACK OPERATIO Page Address Data EE Address Data EE Data Page Address Data EE Address Data EE Data Page + 0 Page Status 23:16 0x0000 Page + 0 Page Status 23:16 0x0001 Page x0202 Page x2222 Page x0707 Page x7777 Page x2222 Page + 2 0xA 0x0A0A Page + 8 0xA 0x0A0A Page + 8 0xFF 0xFFFF Page x7777 Page xFF 0xFFFF Since each location within the page is programmed once prior to the page erase, only one erase/write cycle is consumed for the page As a result, the algorithm multiplicatively improves the emulated data EEPROM effective endurance The previously filled page is erased only after the latest information has been programmed into the next available page and successfully verified Through this process, the information is always stored in nonvolatile memory which minimizes the effects of an unexpected loss of power As the program memory page is filled sequentially from beginning to end, the algorithm assumes the most current data EEPROM information is the closest instance to the end of the page To simplify the read operation, the search begins at the end of the current program memory page and works toward the start of the page looking for the specified data EEPROM address When a match is found, the associated data is returned for the first instance of the provided address If the address is not found, the return value of all ones, 0xFF or 0xFFFF, is returned to emulate the result of an unwritten address in an independent data EEPROM 2009 Microchip Technology Inc DS01095C-page 3 A1095 s Status flags have been provided to indicate whether an error or warning condition occurs during the emulation process These indicators are accessed in the Data EEPROM Flags register; all flags are active-high ote: All EEPROM banks affect the same status flags The status bits and return values are defined as follows: addrotfound(0xff/0xffff) A read operation occurred on a previously unwritten data EEPROM address expiredpage(0x1) The program memory erase/write cycle count has exceeded the user-defined limit The algorithm will attempt to execute the write operation packbeforepagefull(0x2) The pack routine was called before the currently active page was full The routine will attempt to move the latest data EEPROM information to the packed page even though the active page is not full packbeforeinit(0x3) The pack routine was executed before the initialization routine The pack operation was aborted packskipped(0x4) A page was written beyond the page boundary This may be a result of the pack routine not being executed properly The pack operation was aborted illegaladdress(0x5) There was an attempt to write or read with a data EEPROM address equal to or greater than the size of data EEPROM The read or write operation was aborted pagecorrupt(0x6) The page status information was corrupted The current operation was aborted writeerror(0x7) The information written into program memory failed verification The current operation was aborted Status flags differ in severity and how they are serviced Informational status flags are expected to occur during normal processing and are serviced by simply clearing the flag with the associated macro These include: addrotfound, packbeforepagefull and illegaladdress flags Warning status flags indicate a condition has been exceeded but processing will continue This includes the expiredpage status flag With this flag set, the algorithm will attempt to process read and write requests, but the flag will be set after each operation The most severe flags are the system error status flags These imply either the integrity of the data EEPROM information has been compromised and/or the algorithm cannot continue until the offending condition has been resolved These include packbeforeinit, pagecorrupt and writeerror flags To avoid a packbeforeinit event, ensure the initialization routine, DataEEInit, is called prior to performing any other emulation routine Since this routine accesses the current state of the emulation process, it will take action only if it is required Therefore, it can be called at any time during data EEPROM emulation The pagecorrupt and writeerror flags indicate that a write operation failed to verify and the current operation was aborted If this occurs, the integrity of the data EEPROM information has been compromised o further emulation operations should be attempted The only recourse is to erase all of the pages of program memory reserved for data EEPROM emulation and attempt to reinitialize them Macros are available to retrieve and clear the status flag values Status flags are cleared only by the user o operation is affected by the value of any flag, but the flag s value will indicate whether an operation completed successfully Macros use this naming convention: Example macros: Getx Setx y x = Flag name y = Value assigned to flag All of the flags can be read or cleared in a single operation using the 8-bit character, dataeeflagsval DS01095C-page Microchip Technology Inc A1095 Page Status Each program memory page reserves space for the page status using the first two-word locations for the PIC18 implementation or the first location for PIC24/dsPIC33F Status contains information about the page, whether it is expired or active, and the number of erase/write cycles performed These values are used by the algorithm to monitor and control page information, and are not directly accessible by the user Refer to Register 1, Register 2 and Register 3 for formats of PIC24/dsPIC33F and PIC18 page status information ote: Applications with bootloaders should take care not to change the page status information This can be done by programming 1 s into these locations REGISTER 1: PAGE STATUS FOR PIC24 AD dspic33f ALGORITHM U-1 U-1 U-1 R-1 R-1 R-1 U-1 U-1 Page Expired Page Current Page Available bit 23 bit 16 R-1 R-1 R-1 R-1 R-1 R-1 R-1 R-1 Page Erase/Write Count bit 15 bit 8 R-1 R-1 R-1 R-1 R-1 R-1 R-1 R-1 Page Erase/Write Count bit 7 bit 0 Legend: R = Reserved bit U = Unused bit, read as 1 -n = Value prior to initialization 1 = Bit is in erased state 0 = Bit is in programmed state bit Unimplemented: Read as 1 bit 20 Page Expired 1 = Page not expired 0 = Page expired bit 19 Page Current 1 = Page not current 0 = Page current bit 18 Page Available 1 = Page available 0 = Page not available bit Unimplemented: Read as 1 bit 15-0 Page Erase/Write Count: umber of Page Erase/Write Cycles 2009 Microchip Technology Inc DS01095C-page 5 A1095 REGISTER 2: PAGE STATUS FOR PIC18 ALGORITHM (START OF PAGE) U-1 U-1 U-1 U-1 U-1 U-1 U-1 U-1 bit 15 bit 8 U-1 U-1 U-1 U-1 U-1 R-1 R-1 R-1 Page Expired Page Current Page Available bit 7 bit 0 Legend: R = Reserved bit U = Unused bit, read as 1 -n = Value prior to initialization 1 = Bit is in erased state 0 = Bit is in programmed state bit 15-3 Unimplemented: Read as 1 bit 2 Page Expired 1 = Page not expired 0 = Page expired bit 1 Page Current 1 = Page not current 0 = Page current bit 0 Page Available 1 = Page available 0 = Page not available REGISTER 3: PAGE STATUS FOR PIC18 ALGORITHM (START OF PAGE + 2) R-1 R-1 R-1 R-1 R-1 R-1 R-1 R-1 Page Erase/Write Count bit 15 bit 8 R-1 R-1 R-1 R-1 R-1 R-1 R-1 R-1 Page Erase/Write Count bit 7 bit 0 Legend: R = Reserved bit U = Unused bit, read as 1 -n = Value prior to initialization 1 = Bit is in erased state 0 = Bit is in programmed state bit 15-0 Page Erase/Write Count: umber of Page Erase/Write Cycles DS01095C-page Microchip Technology Inc A1095 IITIALIZATIO OPERATIO The initialization routine, DataEEInit, must be called before any other data EEPROM operation can occur; this initializes all the EEPROM banks If the routine determines that program memory has not been initialized for emulation, it will find the first allocated page of program memory and initialize its status information Thereafter, the read and write functions may be called as needed The routine may also determine whether data EEPROM emulation is already underway If so, one of three scenarios may occur: If only one active page is found, the routine assumes a Reset occurred o action is taken and the routine exits normally Any read or write operation that may have been active during the Reset should be repeated If two active pages are found, the routine assumes that an unexpected Reset occurred during a pack operation The routine will erase the second active page and call the pack routine to permit the refresh to complete If more than two active pages are found, the routine assumes program memory has been corrupted by the application code and sets the pagecorrupt flag It is important to monitor the page status bits as well as the RCO and VMCO (PIC24/dsPIC33F) or EECO1 (PIC18) registers By doing so, the application can respond appropriately to Resets and supply voltage changes For a flowchart of the initialization routine, see Figure 1 FIGURE 1: EMULATIO DATA EEPROM IITIALIZATIO Select First EEPROM Bank Find an available page Are all pages expired? Set expiredpage Count umber of Active Pages Are no active pages found? Erase First Allocated Page of Program Memory Mark First Page as Active and Assign E/W Count to 0 Is 1 active page found? Are all the EEPROM banks initialized? Select ext EEPROM Bank Are 2 active pages found? Erase Second Active Page Pack First Active Page Set pagecorrupt 2009 Microchip Technology Inc DS01095C-page 7 A1095 READ OPERATIO The DataEERead function is used to retrieve data EEPROM information It returns the data associated with the data EEPROM address If the provided address is equal to or greater than the amount of defined data EEPROM, the illegaladdress flag is set and a value of all 1 s is returned This return value mimics the response of dedicated data EEPROM, where an unwritten address returns an erased value The routine then searches for the active page in the EEPROM bank corresponding to the address Once located, the active page is searched for an address match, starting from the last location in the page For details on how data EEPROM information is stored in program memory, see Table 1 and Table 2 Since the page is filled sequentially, the latest data EEPROM information will be the first location found with the reverse search Once found, the routine returns the data EEPROM data value associated with the data EEPROM address If an active page is not found, the pagecorrupt flag is set For a flowchart of the read operation, see Figure 2 FIGURE 2: READ OPERATIO Is data EEPROM address valid? Set illegaladdress Select the EEPROM Bank Corresponding to the Address Is active page found? Set pagecorrupt 0xFF or 0xFFFF Set Table Pointer to End of Current Page Does data EEPROM address match? Data EEPROM Data Has entire page been read? Set addrotfound 0xFF or 0xFFFF Decrement Table Pointer DS01095C-page Microchip Technology Inc WRITE OPERATIO FIGURE 3: WRITE OPERATIO A1095 To write emulated data EEPROM, the application uses the DataEEWrite function Like the read function, it verifies that the data EEPROM address is between 0 and one less than the size of the emulated data EEPROM If an unimplemented address is supplied, the illegaladdress flag is set and write operation is aborted The routine then searches for the active page of the EEPROM bank corresponding to the address After the active page is located, a read operation is performed To minimize the number of erase/write cycles, the value is programmed only if it has changed If an active page is not found, the pagecorrupt flag is set and a non-zero value is returned A forward search of the active page returns the offset for the next available address If the next available address is equal to, or greater than, the last address in the page, the packskipped flag is set and the write operation is aborted Otherwise, the data EEPROM information is written to the next available address in the page If the information does not verify, the writeerror flag is set and a non-zero value is returned The user can attempt to rewrite the data or respond as needed The algorithm is designed to maintain at least one available location in the active page for the next write operation After a successful verification of the write operation, the pack routine is called if no available locations remain After the routine completes successfully, a zero value is returned For a flowchart of the write operation, see Figure 3 Is data EEPROM address valid? Select the EEPROM Bank Corresponding to the Address Is active page found? Set Table Pointer to Start of Current Page Read Current Data EEPROM Value Did data EEPROM value change? Find ext Available Address in Page Is page full? Set illegaladdress Set packbeforeinit Set packskipped Write and Verify Data EEPROM Address and Data Does data verify? Set writeerror Find ext Available Address in Page Is page full? Pack Active Page 2009 Microchip Technology Inc DS01095C-page 9 A1095 PACK OPERATIO The pack routine, PackEE, is called from either a DataEEWrite after the current page is filled, or by DataEEInit to initialize program memory for data EEPROM emulation It can also be called by the user, which may benefit timing-sensitive applications Because the routine performs multiple Flash operations which stall the CPU, it can be executed at a time more convenient for the application The disadvantage in doing so is that effective endurance is reduced since unwritten program memory locations are spent The function begins by reading the Page Current status bit, for each page of program memory allocated,
Recommended
View more...
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks
SAVE OUR EARTH

We need your sign to support Project to invent "SMART AND CONTROLLABLE REFLECTIVE BALLOONS" to cover the Sun and Save Our Earth.

More details...

Sign Now!

We are very appreciated for your Prompt Action!

x