Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 19th March 2007, 03:47 AM   (permalink)
Default Storing Calibration Data

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
Omar.M is offline  
Old 19th March 2007, 03:55 AM   (permalink)
Default

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.
Pommie is offline  
Old 19th March 2007, 03:56 AM   (permalink)
Default

Also, the data sheet contains example code for reading and writing.

Mike.
Pommie is offline  
Old 19th March 2007, 07:04 AM   (permalink)
Default

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



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.

http://users.tpg.com.au/gramo/Site/eeproms.htm
__________________
Spency.

PIC Micro's - Your mind is the limit

PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net
gramo is offline  
Old 19th March 2007, 07:12 AM   (permalink)
Default

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.
Pommie is offline  
Old 19th March 2007, 07:51 AM   (permalink)
Default

I miss read that, sorry. In that case, just use the PIC's onboard memory as suggested;

Quote:
EWRITE 00, [Piece_Of_Data1]
EWRITE 01, [Piece_Of_Data2]
Quote:
Variable1 = EREAD 00
Variable2 = EREAD 01

Even easier
__________________
Spency.

PIC Micro's - Your mind is the limit

PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net
gramo is offline  
Old 19th March 2007, 01:09 PM   (permalink)
Default 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
Omar.M is offline  
Old 19th March 2007, 01:17 PM   (permalink)
Default

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.
Pommie is offline  
Old 19th March 2007, 01:25 PM   (permalink)
Default

Wow, that seems easy enough, thank you

And as for basic, in fact I am using BASIC!
Great Cow Basic, to be exact.
http://gcbasic.sourceforge.net/

Thanks a lot,
Omar
Omar.M is offline  
Old 19th March 2007, 09:57 PM   (permalink)
Default

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.
__________________
I thought what I'd do was I'd pretend I was one of those deaf-mutes.
Oznog is offline  
Old 20th March 2007, 07:28 AM   (permalink)
Default

This is about 1,000,000 writes, less in some cases
__________________
Spency.

PIC Micro's - Your mind is the limit

PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net
gramo is offline  
Old 20th March 2007, 01:32 PM   (permalink)
Default 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
Omar.M is offline  
Old 20th March 2007, 01:44 PM   (permalink)
Default

The EEPROM retains the data when the power is removed. Averaging readings really depends what they are, and what you're trying to do with them.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 20th March 2007, 01:45 PM   (permalink)
Default

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.
Pommie is offline  
Old 21st March 2007, 05:48 PM   (permalink)
Default

There's normally a limit to the number of write cycles though.
__________________
I also post at the following sites:
http://www.stop-microsoft.org http://www.heated-debates.com
Screen name: Aloone_Jonez
And http://www.silicontronics.com, same screen name as here.
Hero999 is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
Need some help with a code provided by ATMEL ikalogic Micro Controllers 1 23rd January 2007 03:46 PM
Hardcode a PIC by hand? (or 16F74 + par.port.prog = problem) smilen Micro Controllers 15 21st November 2005 10:23 AM
Oscilloscope storing data software xmat General Electronics Chat 10 14th August 2005 07:01 PM
Just Joined, Got some bugs I can't find. Thedoctorisin136 Micro Controllers 0 1st March 2005 07:07 PM
An error in pic16f84a, why? Zener_Diode Micro Controllers 6 11th April 2004 03:55 AM



All times are GMT. The time now is 02:50 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker