Skip to main content
Engineering LibreTexts

16.2: Atmel AVR Core

  • Page ID
    35877
  • The Atmel AVR processor core uses Harvard architecture with simple pipelining. A block diagram of the AVR series core is shown below.

    AVR block diagram (Atmel 2014).
    Figure \(\PageIndex{1}\): AVR block diagram (Atmel 2014).

    The first thing to notice is that most of the blocks are interconnected via an eight bit data bus (i.e., a collection of parallel connections, in this case, eight of them). The data bus is bidirectional meaning that data can be placed onto it (written) by one block and pulled off (read) by another. Obviously, some form of “traffic control” needs to be applied and that is usually handled by appropriate timing signals and tri-state buffers1.

    The ALU, or Arithmetic Logic Unit, is responsible for basic computational functions such as integer addition and subtraction, bit operations, comparisons and the like. In association with this are 32 eight bit general purpose registers. The ALU performs operations on the values in the registers, not directly on values in general memory. For example, suppose you want to add two variables and place the result in a third variable. The ALU has to transfer values from memory to the registers where the computation is performed and then transfer the result back to the final location. A large number of registers is a common feature of RISC processors. Early CISC processors had very few registers (indeed, many had a single “accumulator” for these sorts of operations). There are also many specialized registers not shown here as they are associated with IO modules, timers and so forth (more on this in a moment). Three important specialized registers are the status register, program counter and stack pointer. The program counter (PC) keeps track of the currently executing instruction (i.e., the current location of the code flow). The stack pointer (SP) records the current memory address of the top of the stack (i.e., the location in memory used for temporary variables and such). The status register (SR) contains a series of bits reflecting the most recent results of an ALU operation and the general state of the processor. The AVR status register contains eight bits, all of which are read/write and initialized at 0:

    Table (\PageIndex{1}\): AVR status register (Atmel 2014).
    Bit 7 6 5 4 3 2 1 0
    Function I T H S V N Z C

    The bits are as follows from the Atmel documentation:

    Figure \(\PageIndex{2}\): AVR status register bits (Atmel 2014)

    Bit 7 – I: Global Interrupt Enable

    The Global Interrupt Enable bit must be set for the interrupts to be enabled. The individual interrupt enable control is then performed in separate control registers. If the Global Interrupt Enable Register is cleared, none of the interrupts are enabled independent of the individual interrupt enable settings. The I-bit is cleared by hardware after an interrupt has occurred, and is set by the RETI instruction to enable subsequent interrupts. The I-bit can also be set and cleared by the application with the SEI and CLI instructions, as described in the instruction set reference.

    Bit 6 – T: Bit Copy Storage

    The Bit Copy instructions BLD (Bit LoaD) and BST (Bit STore) use the T-bit as source or destination for the operated bit. A bit from a register in the Register File can be copied into T by the BST instruction, and a bit in T can be copied into a bit in a register in the Register File by the BLD instruction.

    Bit 5 – H: Half Carry Flag

    The Half Carry Flag H indicates a Half Carry in some arithmetic operations. Half Carry Is useful in BCD arithmetic.

    Bit 4 – S: Sign Bit, \(S = N \oplus \oplus V)\
    The S-bit is always an exclusive or between the Negative Flag N and the Two’s Complement Overflow Flag V.

    Bit 3 – V: Two’s Complement Overflow Flag

    The Two’s Complement Overflow Flag V supports two’s complement arithmetic.

    Bit 2 – N: Negative Flag

    The Negative Flag N indicates a negative result in an arithmetic or logic operation.

    Bit 1 – Z: Zero Flag

    The Zero Flag Z indicates a zero result in an arithmetic or logic operation.

    Bit 0 – C: Carry Flag

    The Carry Flag C indicates a carry in an arithmetic or logic operation.

    It is important to remember that the state of the status register is not saved when entering an interrupt routine or restored when returning from an interrupt. This must be handled in software. We shall see how this is handled in future chapters.


    1. A tri-state buffer simply repeats its input signal at its output like an ordinary buffer but also offers a third “high Z” state. When the high Z state is enabled, no output signal is present and the output impedance of the buffer goes to a very high value, effectively disconnecting the buffer from the bus.
    • Was this article helpful?