Monday, July 25, 2011

EEPROM


EEPROM (Electrically Erasable Programmable Read Only Memory) is one of the three memory types of AVRs (the other are the Flash memory and SRAM). EEPROM is able to retain its contents when there is no supply voltage. You can also change the EEPROM contents on runtime, so, EEPROM is useful to store information like calibration values, ID numbers, etc.
Most AVRs have some amount of EEPROM (the exceptions are ATtiny11 and ATtiny28). You must check the corresponding datasheet to know the exact amount of memory of your particular device.
To write in the EEPROM, you need to specify the data you want to write and the address at which you want to write this data. In order to prevent unintentional EEPROM writes (for instance, during power supply power up/down), a specific write procedure must be followed. The write process is not instantaneous, it takes between 2.5 to 4 ms. For this reason, your software must check if the EEPROM is ready to write a new byte (maybe a previous write opeartion is not finished yet).
The address of the byte you want to write is specified in the EEPROM Address Register (EEAR). If the AVR you are using has more than 256 bytes, the EEAR register is divided in the EEARH and EEARL registers. The EEPROM Data Register (EEDR) contains the data you want to store.
The EEPROM Control Register (EECR) is used to control the operation of the EEPROM. It has three bits : EEMWE, EEWE and EERE. The EERE (EEPROM Read Enable) bit is used to read the EEPROM and is discussed later. In order to issue an EEPROM write, you must first set the EEMWE (EEPROM Master Write Enable) bit, and then set the EEWE (EEPROM write enable) bit. If you don't set EEMWE first, setting EEWE will have no effect. The EEWE bit is also used to know if the EEPROM is ready to write a new byte. While the EEPROM is busy, EEWE is set to one, and is cleared by hardware when the EEPROM is ready. So, your program can poll this bit and wait until is cleared before writing the next byte.


settings for EEPROM is very nicely explained in the PDF of atmega16. I know laziness rocks so i have updated it here..

While writing a code for EEPROM settings, we require some basic knowledge of its registers.
So, first register is the address register. We know that EEPROM has 512 bytes of storage. Thus to access each bit, we have a separate address defined. now, 512 numbers can be associated with 9 binary bytes. But we have 8 bit registers. So to solve this problem, we have 2 address registers, EEARH & EEARL represnting high and low registers respectively.


As we can see, bits 9 to 15 are reserved. Hence they are of no use as of now.  The 9 bit address can be represented in bits 0 to 8, linearly between 0 to 511..as simple as that! Initially the value of EEAR is undefined.

this was all for addressing EEPROM. Now lets store some data..!!
EEDR is the eeprom data register. Now we have two operations in EEPROM, reading and writing data..so when EEDR is read, it contains data stored in the address specified by EEAR i.e. the address register. When EEPROM is written, values provided by us is stored in EEDR on the address specified by EEAR. So, we can see that data register and address registers go hand in hand.

Now, lets move on to the final register the control register! its bit tricky..but once you understand it, its a piece of cake..:)
7 to 4 bits are reserved!! so no need to care about them..!!
EERIE generates interrupt when it is set to 1. The EEPROM Ready interrupt generates a
constant interrupt when EEWE is cleared. Now, what is EEWE??? EEWE is EEPROM write enable. By setting this to 1, we set EEPROM in write mode. Previous data in EEDR would be replaced by new data provided. Now, coming to EEMWE,

The EEMWE bit determines whether setting EEWE to one causes the EEPROM to be
written. When EEMWE is set, setting EEWE within four clock cycles will write data to the
EEPROM at the selected address If EEMWE is zero, setting EEWE will have no effect.When EEMWE has been written to one by software, hardware clears the bit to zero after
four clock cycles.
EERE is simply read enable. Enable this bit while reading values in EEDR.


Few random points,
1. EEPROM reading and writing is slower than SRAM reading/writing process,
it waits 4 clock cycles for reading EEDR & 2 clock cycles for writing to EEDR.!!
2. Programming steps..
 a) Wait until EEWE becomes zero.
 b) Write a logical one to the EEMWE bit while writing a zero to EEWE in EECR.
 c) Within four clock cycles after setting EEMWE, write a logical one to EEWE.

with this, i think you can make a password recognization system very easily..and since we know about touchscreens, maybe try making a numpad on a resistive touchscreen...;)

Sunday, July 24, 2011

importance of flowchart!

Flow charts are a graphical representation of code, Program states or even SRAM contents, if used in a creative way. Once you know how to use them for code you'll quickly develop your own style to create flow charts for almost anything.
When you think about implementing a special algorithm or peripheral driver it might be better to have a flow chart already done before you start hacking code. And trust me, that will save lot of time. If you have code that is not sufficiently commented or just BIG, analyse it by making up a flow chart. Very often that helps, especially when you got it from the web.
Especially when writing code in assembler they are a great help, because assembler instructions are not always self-explanatory and even well-structured code will get hard to read once it has grown to a certain size.

You can find a good program for editing flow charts at www.rff.com. But a piece of paper will do the job too if you need to make up one.

lets start from the scratch

I found the blog very nerdy..and not at all helpful for people who have to learn from the scratch. So, I think this post will be a little more helpful.
ok...so the basic question...
What is a Microcontroller?
Microcontroller can be termed as a single on chip computer which includes number of peripherals like RAM, EEPROM, Timers etc required to perform some predefined task.
But, it is not a computer!
Wikipedia provides further details about AVRs.
we are talking about ATMEGA 16...
 

Also, Architecture can be seen in the datasheet.
Now coming to the programming part, the ASSEMBLER. Here is a link for it.
I hope this helps. This post will be further updated.
For PCB designing please follow this link . It is very helpful.

Friday, July 22, 2011

ATMEGA 16/8535

The basic difference between atmega 16 & 8535 is their clock frequency. Also,
1.8535 has 8kB of Flash Progam Memory while atmega 16 has 16kB.
2.8535 has 512 bytes of SRAM and Atmega 16 has 1kB
You can download datasheet of atmega 16 by following this link,
download PDF

Now, go through the features of atmega 16 listed on the first page of the datasheet. Intersted ppl cn also view the pin diagram and the block diagram given in the next few pages of the data sheet..

AVR-for beginners!!

HELLO everyone! this is first post on introducion to AVR family..so to start things, first of all I would like to tell you differences between a microcontroller and microprocessors.


A microprocessor is the heart of computer systems.
A microcontroller is the heart of an embedded system.
Most communication, digital entertainment and portable devices, are controlled by either of them.

A designer should know what types of components he needs, ways to reduce production costs and product reliable!!


Now, there are huge variety of microcontrollers! They can be classified as, 

Memory:
     FLASH, EEPROM, SRAM….         




CPU’s:
  4bit, 8bit, 16bit, 32bit…
  C.I.S.C., R.I.S.C.
  Harvard, Von Neumann
  Clock frequency range.