|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: Saving a variable in between runs.
There are 2 ways to store data permanently:
1.)Flash memory(AKA: program memory) 2.)EEPROM memory The first is ridiculously complicated and i'm not going to bother to explain it. EEPROM is relatively simple. EEPROM Is a special 1kilobyte region of memory. It cannot be read or written to through conventional methods. There are special procedures for this (detailed in the PIC datasheet). It must be read/written to one byte at a time. You will need to either devise your own file system to keep track of where you put things or be very careful not to put things in the same place. We have written both a library which has basic read buffer/write buffer functions as well as a basic file system. Neither has been been tested yet but their testing is on our agenda of thigns to do this week. Once we are sure they work i would be more than happy to post the code for the basic read/write. I won't post the file system because its rather specific to our robot, but if you need any help I will be more than happy to give it. The best resources i have found about writing to the EEPROM are the PIC18F8520 datasheet (available from the microchip website. It assumes you are programming in assembly but still VERY helpful) and the following thread: http://www.chiefdelphi.com/forums/sh...d.php?t=22655& One thing worth mentioning: *EEPROM can be read from instantaneously but writing takes time.... Enough time that the robot can easily time out if you try to write too much data at a time. The good thing is that this writing can be handled in the background. You can initiate a write and set up an interrupt to be called when writing is finished. You know what... screw it.. I will post my untested code. I can't guarentee it works( and it probably doesn't), but i will release a version that does soon. It can be found here: http://geargrinders.pictar.net/EEPROM.zip I will explain the basics of how to use it: *during your initialization or sometime before using my EEPROM library, you must call EEInit. *add the following to the end of the function InterruptHandlerLow () in user_routines_fast.c: HandleEEPROMInterrupts(); *include EEPROM.h in any files that use the EEPROM library. Other than that, I think the methods are pretty self explanatory. If not just let me know and i will explain them. Look in EEPROM.h for a list of them. Last edited by Rickertsen2 : 12-09-2004 at 22:35. |
|
#2
|
|||
|
|||
|
Re: Saving a variable in between runs.
Does the EDU bot have the same functionality with using the EEPROM memory?
|
|
#3
|
|||||
|
|||||
|
Re: Saving a variable in between runs.
Quote:
|
|
#4
|
||||
|
||||
|
Re: Saving a variable in between runs.
There were a few bugs in my original code. If anybody is interested i will post the working version.
|
|
#5
|
||||
|
||||
|
Re: Saving a variable in between runs.
Am I mistaken by saying if you initialize a static variable such as static int inBetween and it will store the varaible into the program, instead of the RAM. That is the ANSI C standard AFAIK, I'm not sure if its different on PIC chips... Can someone clarify?
Jake |
|
#6
|
|||
|
|||
|
Re: Saving a variable in between runs.
Quote:
I'm using it to store p1_x values that a gyro calculated to make it go strait. Then next time I hit forward on the joystick it would start off with the calculated p1_x value instead of default 127. This (hopefully) will eliminate any beggining turning while the gyro is building up error. Last edited by colt527 : 15-09-2004 at 16:49. |
|
#7
|
||||
|
||||
|
Re: Saving a variable in between runs.
Quote:
|
|
#8
|
|||||
|
|||||
|
Re: Saving a variable in between runs.
Quote:
1) "static int x;" uses RAM or data space just as "int x;" does. You can change the value of x from within your program while it's executing (e.g. "x=y+2;"), but the value only lasts as long as the RC is on. All data is lost or returns to initialized values when the RC is turned off or reset. 2) "rom const int x=10;" uses ROM or program space. You cannot change the value of x from within your program as it's running (the compiler will reject "x=y+2;" as an error). The value at program load is permanent and unchanging, only by downloading a new program can x be modified. I believe this is what you were thinking of. 3) EEPROM requires special read/write commands to access as noted above. The value can be changed from within the program while it's running and the latest value is still there after the RC has been turned off or reset. This retention of a changable value is the reason people go to so much trouble to use the EEPROM r/w commands. Last edited by Mark McLeod : 15-09-2004 at 17:41. |
|
#9
|
||||
|
||||
|
Re: Saving a variable in between runs.
Quote:
|
|
#10
|
|||||
|
|||||
|
Re: Saving a variable in between runs.
Quote:
|
|
#11
|
||||
|
||||
|
Re: Saving a variable in between runs.
Quote:
*Anything you write to flash will be erased if you upload a new program *It is difficult to both read and write from *It can cause VERY odd errors if you are not careful (you are writing to the same space as your program is executing from and if you overlap bad things will happen) *you can only write blocks of 8 bytes at a time *you can only erase in blocks of 64 bytes at a time *Flash memory is only rated for 100,000 write/erase cycles. EEPROM is rated for 1,000,000 If you really have your heart set on it, the datasheet will tell you how. Quote:
Last edited by Rickertsen2 : 16-09-2004 at 19:34. |
|
#12
|
|||||
|
|||||
|
Re: Saving a variable in between runs.
Quote:
The big issue isn't how to do the physical write, but how to avoid clobbering your code while doing so. Your code changes size and placement in memory every time you modify it. Even if you place the bytes to be modified at the high-end of memory there is no self protect mechanism that will prevent the linker from claiming that space for code on some future date. Just wait until you try executing your variables! ![]() |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| MPLAB Variable Simulator? | Chris_Elston | Programming | 3 | 18-02-2004 12:08 |
| Interrupt Handlers and Variable Scope | kaszeta | Programming | 2 | 14-02-2004 18:30 |
| variable? | manodrum | Programming | 11 | 01-04-2003 17:20 |
| Dashboard programs and the char variable | Ian W. | Programming | 13 | 26-06-2002 02:07 |
| what teams have a variable transmissions? | Greg Perkins | Technical Discussion | 4 | 06-03-2002 06:10 |