After completing this AVR microcontroller tutorial readers should be able to:
- Give a technical definition for the program counter.
- Determine the size of an AVR microcontroler program counter.
Introduction to the Program Counter
What is the program counter?
The Program Counter (PC) is a register that is apart of all central processing unit (CPU) or microprocessor. All microcontrollers contains a microprocessor and thus has a program counter. The purpose of the program counter is to hold/store the address of the next instruction to be executed by the microcontroller's microprocessor.
The size (width) of the program counter of a microcontroller is measured in bits and is directly related to the size of the microcontroller's program memory.
Determining the size of the AVR Program Counter
As mentioned above the purpose of the program counter (PC) is to hold the address of the next instruction to be executed by the CPU. Instructions are stores in the program memory of a microcontroller and thus the PC width is directly related to the size of the micorcontroller program memory. As an example lets determine the width of the program counter for the ATMega16
The width(size) of the program counter (PC) is basically the smallest possibly number of bits necessary to address the microcontroller program memory based on its organisation. Lets say n
is the width of the PC then n would be related to the size of the program memory by the following equation:
2n = size of program memory
n = log(size of program memory)/(log2)
For the ATMega8515 microcontroller the program memory is 8k-Bytes organised as 4k-Words. As such the width of the ATMega8515 microcontroller Program Counter n is given by:
2n = 4k = 4x1024
n = log(4096)/log(2) = 12bits
For the ATMega16 microcontroller the program memory is 16k-Bytes organised as 8k-Words. As such the width of the ATMega16 microcontroller Program Counter n is given by:
2n = 8k = 8x1024
n = log(8192)/log(2) = 13bits
AVR Tutorials hopes this tutorial on the AVR program counter was beneficial to you and looks forward to your continued visits for all your microcontroller tutorial needs.