Forum Discussion
Altera_Forum
Honored Contributor
13 years ago --- Quote Start --- thanks for the reply, yes there is some space in the EPCS device i am using. Could you basically explain how i can go about storing some data (say a 12 bit value) in memory for future use and change it during runtime ?? --- Quote End --- Read the data sheet for the EPCS device and it explains how you can read and write flash. Basically it involves a serial bit sequence involving a command and the data you want to write. Flash is erased in sectors. Since you only want to store a small amount of data, you'll want to be able to store multiple values before erasing the flash. Here's a simple scheme you can use; 1) Decide on the area in Flash you can write to (ideally a single sector of flash). 2) Erase it, so that its bytes are all 0xFF 3) Use two bytes for your 12-bit data, and decide whether you will store data in 16-bit big-endian or little-endian format. 4) Decide on a data format that you can distinguish from an erased 16-bit value. In your case, since you are only using 12-bit data, just use 12-bits of the 16-bits, and set the 4-bits of the MSB to zeros, i.e., in your code write_data(data & 0xFFF), where the mask sets the MSBs to zero. 5) When your code searches for the last valid value, it starts at the beginning of the flash sector where data is stored, loops through 16-bit values and looks for the first value where the MSB is set to 1. If the first entry in flash has its MSB set, then there is no value in flash, otherwise, the last value written is the value before the value with the MSB set. 6) When you go to write a new value, you use the same procedure to find an entry with the MSB set. If you reach the end of the data sector you have allocated for storing data, then you need to erase it, and write the value to the start of the flash. Simple eh? :) Cheers, Dave