Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Storing Calibration Data

Status
Not open for further replies.

Omar.M

Member
Hello. For my line following, instead of having static values for the line and off the line sensor readings, I was thinking of having a button for the on-line reading and off line reading, so when I press each individual button: I could get the value and store it.

This way, my robot would be better in different conditions without having to reprogram every time.

I was wondering, is it possible? Can PICs store such data? Would anyone have any snippets?

Thanks a lot,
Omar
 
That is exactly what the EEPROM is for.

Reading and writing EEPROM varies from chip to chip. Which Pic are you using?

Mike.
P.S. I think Nigel has a tutorial on this for the 16f628.
 
Also, the data sheet contains example code for reading and writing.

Mike.
 
Here’s an example of interfacing with 4 EEPROM’s on an I2C network;

**broken link removed**

Code:
Device = 16F876
XTAL 20

ALL_DIGITAL = True
Declare SCL_PIN PORTB.0
Declare SDA_PIN PORTB.1

    

Dim TX As PORTB.2

Dim DATA_OUT As Byte
Dim DATA_IN(20) As Byte

Dim Address As Word ' 16-bit address required

For Address = 1 To 20

     DATA_OUT = Address
     BStart                                                             ' Send the start command on I2C
     BusOut %10100010,Address,[DATA_OUT]        ' Send the byte to the EEPROM
     BStop                                                            ' Send the stop command on I2C
     DelayMS 5                                                      ' Allow time for allocation of byte

Next Address

For Address = 1 To 20
    
     BStart                                                             ' Send the start command on I2C
     BusOut %10100010,[Address]                          ' Send the address to read
     Brestart                                                          ' Send a restart command on I2C
     BusIn %10100011, [DATA_IN[Address]]            ' Grab data at the above address
     BStop                                                             ' Send the stop command on I2C

Next Address

Stop

Of course you could just use one big EEPROM, but I wanted to kill 2 birds with one stone and describe I2C in my model.

**broken link removed**
 
Why complicate things? The OP wanted to know how to store 2 bytes. This can easily be done in the internal EEPROM of most Pic chips. Did you not realise that Pic's have internal EEPROM?

Mike.
 
Wow

That simple, huh?
Thanks so much.

I should have been more clear-- I am using a 16f684 microcontroller.
Just one more question-- which address would I write the data to?

-Omar
 
It's only that simple if you are using basic. If you are using assembler then copy the routines out of the data sheet - there still pretty simple. You can write to any of the locations from zero to however many bytes of EEPROM are available - 256 in the 684.

Mike.
 
Note that EEPROM has a limited write endurance. It's unlikely you would ever run into endurance problems with user-entered button presses, however for other cases where you may write them more often the write endurance can be a real issue which may limit the lifespan of the product.
 
Oh

Oh. Well, I do not think I will exceed that limit-- this is merely me just experimenting with robotics; it isn't going to be in competitions or anything.

I just have a few questions. Does the data which I store in the EEPROM get erased when I power off the PIC? Or is it permanent? Is it better to get a few sensor readings and finding the average between them... or just two basic readings ?

Thanks,
Omar
 
Whatever you put in the EEPROM should stay there for at least 40 years if you believe the data sheet.
I would average a few readings and store that. End of the day you are going to compare against the average of the 2 readings. The actual readings are probably not too important.

Mike.
 
There's normally a limit to the number of write cycles though.
 
One Question rise in my mind,
When we erase PIC from MPLAB ICD2, it also erase ROM!! Yes or Not?????

I have Program my PIC16F877A approximate 30 times using ICD2...
It means my EEPROM 30 write cycles decreases????
 
Last edited:
Ayne, the PIC you mentioned uses flash memory not ROM, and the flash and eeprom write endurance is different.

According to the information I found from Microchip, the eeprom endurance is a minimum 100k cycles, but it says typically 1 million.
The flash endurance is only a minimum of 10k and 'typically' 100k

Not even the most dedicated of programmers could wear out the flash writing test code by hand in a sane period of time. You'd have to program your PIC 100 times a day every day for 4 months straight before it would fail (garunteed) and going by the 'typical' rateing it would take three years doing 100 programming sessions a day.
If you program your PIC like you did 30 times every day it's minimum write endurance means it won't wear out till next year.

Problems really only occur when you have self modifying code, like storing buffers or frequently updated table information in FLASH or EEPROM where 100's or even 1000's of write cycles could occur in a short period of time.
 
Last edited:
By the looks of things, every time you program your PIC, it writes to the eeprom too.

I've just tried a program that writes to the EEPROM, then out the PIC back in the programmer & read the PIC data, sure enough the EEPROM has data stored in it, Then re-programmed the PIC, and the EEPROM data is over written
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top