Using Embedded EEPROM on an AVR chip

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
Alberta2012
Flowcode v5 User
Posts: 63
Joined: Fri Apr 19, 2013 2:18 am
Has thanked: 10 times
Been thanked: 14 times
Contact:

Using Embedded EEPROM on an AVR chip

Post by Alberta2012 »

Hi Everyone,

I'm using an ATMEGA8, and from the specs, I can see that it has 512 Bytes of EEPROM.

my application requires the user to modify a target value, using some Increment/decrement buttons. As long as the device is powered, that's fine.

When the device is powered down, then back ON, the current target value, is the default hardcoded one, not the last one saved....is there a way to save the last user's configuration, and recall it on the next power-on ? I would imagine that the 512 Bytes could be used for that , but how ????

Thanks folks !

Kenrix2
Flowcode v5 User
Posts: 211
Joined: Tue Feb 19, 2013 9:51 pm
Has thanked: 72 times
Been thanked: 177 times
Contact:

Re: Using Embedded EEPROM on an AVR chip

Post by Kenrix2 »

Using the EEPROM read/write component requires V5 Pro. If you don't have the Pro version you will have to create you own EEPROM read/write macro. I am not sure if you can still upgrade to the V5 Pro version, you will have to ask Matrix Multimedia about that.
To do your project, first you need a way for the user to enter into a program mode. A simple way to do that might be, on power-up, poll one (or both) of your buttons. If it is depressed then a program EEPROM routine is run. If it is not depressed, then your flowchart will skip the program mode and execute normally.
Then your going to need a way for the user to see what the value is so some type of display is needed like an LCD Display module. The user can then press the increment/decrement buttons to adjust the value. If the value can change by a lot, like 0-255, then a button "press and hold" scheme is needed to quickly increase or decrease the value. Now you need a way to write that value to EEPROM and exit the program mode. An "enter" button might be the easiest way to accomplish that.
IF your project doesn't need a display and there is only one "target" value, you might consider using a Dip switch or rotary Dip switch to set the value and then read the value on power-up. That way you don't need to use the EEPROM.

Alberta2012
Flowcode v5 User
Posts: 63
Joined: Fri Apr 19, 2013 2:18 am
Has thanked: 10 times
Been thanked: 14 times
Contact:

Re: Using Embedded EEPROM on an AVR chip

Post by Alberta2012 »

Kenrix2:

I don't have Pro, but the local college does (I'm friend with some teachers ... so I could potentially get access to it..)

Please clarify what you mean by the "program mode" ?

As for a display, my project is a count down timer (with other behavior), so there is a set of SSD display. The target time value can be changed and it's that value that I want to recall. If I always want to recall the last saved version, everytime I boot, do I still need to enter the program mode you were talking about ?

Anything I need to be worried about before dealing with that EEPROM ?

Thanks,

Jasmin

Kenrix2
Flowcode v5 User
Posts: 211
Joined: Tue Feb 19, 2013 9:51 pm
Has thanked: 72 times
Been thanked: 177 times
Contact:

Re: Using Embedded EEPROM on an AVR chip

Post by Kenrix2 »

Program mode is just a way to manually enter your "target value" and write it to EEPROM. The "target value" has to entered somehow. Maybe I just don't understand what your concept is.
The EEPROM component is one of the easiest components in Flowcode to use. It's either a "read from" or a "write to" a specific address. There is a potential problem with the EEPROM component write with PIC micros if an interrupt is enabled. A workaround is to disable the interrupt before a EEPROM write macro call and then re-enable it after. Or, another workaround is to just verify that the write is correct. I would assume, perhaps wrongly, that this might be an issue with AVR chips as well.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Using Embedded EEPROM on an AVR chip

Post by Benj »

Hello,
There is a potential problem with the EEPROM component write with PIC micros if an interrupt is enabled.
The code to drive the EEPROM should already disable any active interrupts just while it performs the write.

Alberta2012
Flowcode v5 User
Posts: 63
Joined: Fri Apr 19, 2013 2:18 am
Has thanked: 10 times
Been thanked: 14 times
Contact:

Re: Using Embedded EEPROM on an AVR chip

Post by Alberta2012 »

Kenrix2:

Ok, I think I see what you mean by "program mode"....I thought you were refering to some kind of mode, in the operation of the CPU itself, that could be executed BEFORE starting to execute the code....

Correct me if I'm wrong, but you were refering to some kind of configuration mode, within my main code, where the user can manipulate target values......

I will give it a try later this week..... are there any special addresses that need to be entered in that EEPROM configuration ?

Thanks all !

Alberta2012
Flowcode v5 User
Posts: 63
Joined: Fri Apr 19, 2013 2:18 am
Has thanked: 10 times
Been thanked: 14 times
Contact:

Re: Using Embedded EEPROM on an AVR chip

Post by Alberta2012 »

Kenrix2 & Benj:

if I understand well, prior to do any Read or Write from/to an EEPROM, I need to disable any interrupt, Read or Write, then re-enable the interrupt ?

why is that so ?


Jasmin

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 474 times
Been thanked: 458 times
Contact:

Re: Using Embedded EEPROM on an AVR chip

Post by dazz »

hi Alberta
The eeprom component should take care of the interrupts for you, ie switch off int, write eeprom, re enable int etc
not sure with avr but with pic we dont write to address 0 in the eeprom start from 1, so if you get wierd things happen with an avr when writing to eeprom addr 0 then start at 1.
some where on the forum i wrote a simple flowchart to read write display the eeprom contents for a pic if you can find it import it into avr and it should work with a bit of tweaking as if you slow the sim down you can watch what's going on

Regards
Dazz
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

Alberta2012
Flowcode v5 User
Posts: 63
Joined: Fri Apr 19, 2013 2:18 am
Has thanked: 10 times
Been thanked: 14 times
Contact:

Re: Using Embedded EEPROM on an AVR chip

Post by Alberta2012 »

Hi Everyone...

Tried the EEPROM tonight.....

Kenrix2: you were right: the EEPROM object is one of the easiest to deal with ....almost sorry I asked for help...

As mentionned by Dazz, I used address 1 (did not even bother to try 0.....)

Thanks everyone !

Jasmin

Post Reply