| Intro To AVR Microcontrollers | |
|---|---|
| Description: This portion of the site provides some detailed information on the Atmel AVR series of microcontrollers, beginning with this introduction. | |
|
|
| AVR Microcontrollers | |
Welcome to the cAVeRn: AVR Microcontroller SectionThis portion of the site provides some detailed information on the Atmel AVR series of microcontrollers. An entire section is devoted to information on creating, building and managing AVR uC projects using our favorite development platform: Linux. Get started on the AVR Projects with Linux page. Most of the information therein also applies to other Unix platforms and lots of it, such as the AVR Programmer HOWTO, has a great deal of (development) platform-independent information. TOCAVR AdvantagesMicrocontrollers will often allow an optimal solution, combining complex functionality with reduced part count. A whole section of this site has been devoted specifically to the AVR microcontroller. Its advantages include:
AVR Microcontroller PrimerThis mini tutorial focuses on the AVR microcontroller architecture. It is meant as an introduction to the AVR platform in particular but will also (very briefly) introduce a few microcontroller-related topics--be warned that it may be a little abrupt for the absolute microcontroller newbie, but it should be a good intro for everyone nonetheless.
The AVRs are 8 bit RISC platforms with a Harvard architecture (this means that program and data memory are separate). They are microcontrollers: basically, complete computers on one integrated circuit. This means that they combine, on a single chip, a number of the elements you might find separately within a microcomputer. These include:
The processor core, depicted here towards the center of the image on the left side of the data bus, includes elements to read the program memory, decoding and executing the instructions within. The CPU can also fetch and store data to and from the EEPROM, SRAM and the 32 registers. The registers act as extremely efficient storage for 8 bit values (1 byte) and the ALU (arithmetic/logic unit) can operate on each of the 32 registers directly. The AVR processor features a real life stack and its instruction set was designed and optimized for use with high level languages--it is easy to program these chips using C. Note that certain implementations don't provide any SRAM, so the stack is actually hardware based (limiting the stack depth to three). It is interesting to note that most instructions only take a single clock cycle to execute and there is no internal clock division. Also, the CPU will fetch and decode the next instruction as it is executing the current instruction (i.e. in parallel). All this means that AVRs will reach performances of nearly 1 MIPS (Million Instructions Per Second) per MHz--they are fast and efficient. Another advantage of reaching comparable performance at reduced clock rates (e.g. an AVR at 4 MHz will execute about as many instructions as a PIC microcontroller running at 16MHz) is reduced power consumption and lower electro-magnetic noise from high frequency signals. MemoryThe program memory is a contiguous block of flash memory. It may be programmed and reprogrammed numerous times easily. In fact, using the In-System Programming, you can design your system to allow chip firmware upgrades in-place. Program memory is 16 bits wide and can usually be erased/re-written at least 1000 times. All AVRs have some EEPROM and most have SRAM available. Both are 8 bits wide. The EEPROM is programmable during execution (to retain data even without power) or directly during programming (which is very useful for things like production line calibration), see our AVR Programmer HOWTO for details. Using EEPROM is slower than storing data in SRAM but, unlike the volatile RAM, once written the data will remain available indefinitely (even when the power source has been removed). The EEPROM is said to withstand 100,000 erase/write cycles. I/O and Peripherals
Peripherals are where the members of the AVR family distinguish themselves. They all have the same core and support a basically uniform instruction set, which means you can easily develop for all of them. However each has its own particular blend of peripherals and extras. All AVRs, from the tiny 8 pin DIPs to the 44 pin Megas, have at least one data port. Data ports allow for input or output of logic level (binary, HIGH or LOW) data. The AVR ports are bi-directional, allowing you to set them for input or output on a pin-by-pin basis. The AT90S8535 depicted here has four 8-bit ports available. Often, the external pins which make up a port will serve dual (or triple!) purposes, and how the pins are used will depend on how you've configured the controller. For instance, you can see from the diagram that all pins for port A (upper left) are also used as separate channels to the ADC (analog to digital converter) while certain pins of port D (lower right) are used for communication through the UART. Other peripherals which communicate with the outside world are, as discussed above, the ADC and UART. The Analog to Digital Converter included with some AVRs is normally multiplexed; this means that you can monitor multiple analog values, through different pins, one at a time. The UARTs allow asynchronous serial communication, directly with other chips or with computers systems using an RS-232 interface. Analog comparators and other peripherals are available on certain chips, check the relevant datasheets for details. Internal peripherals include timers and counters (8 and 16 bit, with optional overflow interrupts), a watchdog timer (to automatically reset the chip after a preset delay of 16ms to 2s), RC oscillators and more. ProgrammingAVR microcontrollers may be programmed using assembly or a higher level language, such as C. Learning to code assembly is a good idea, as it gives you in depth understanding of the process under the hood. With this type of "bare metal" programming, you manipulate the CPU registers directly and can optimize their use according to your specific needs. The process can, however, become tiresome--at least for programmers accustomed to letting a compiler handle all the dirty work. Using a high level language can allow you to code much more efficiently. Here is a very simplistic program in C: #include All it does is add all the integers between 0 and 99 and store the result in the variable j. Here is part of the same program, as transformed into AVR assembly by the AVR-GCC compiler (corresponding C code has been inserted): #include Each line here is composed of, in order:
Whichever language you choose to use, the next step is to write and build your program (compiling, linking and translating it to a suitable format) and finally transfer it to the microcontroller using a suitable programmer. |
|
| Level: | Article |
| Additional Article Data | |
| Level: | Article |
| Comments |
|---|
|
|
|
The comments are owned by the poster. We aren't responsible for their content.
|
| Jump to section |
|---|


This represents the architecture for the AT90S8535 chip but many of the elements are common to the entire
AVR family.