Skip to main content

Microcontrollers

Section 2.5 Program Counter

The program counter (PC) contains the address of the next instruction to be executed by the microcontroller. It is incremented after every instruction. An example program counter is depicted schematically in Figureย 2.5.1.
Schematic of a program counter. MUX1 has a control bit corresponding to the branch control signal. The 0 input is 1 and the 1 input is the branch offset. The output of MUX1 is one of the inputs of the adder. The other input of the adder comes from memory. The output of the adder goes to the 0 input of MUX2. The 1 input of MUX2 is the jump target. The control bit of MUX2 is the jump control signal. The output of MUX2 goes to the input of a D flip-flop. The output of the D flip-flop goes to memory. The clock signal of the flip-flop comes from an external clock. The active-low reset signal is connected to system power.
Figure 2.5.1. Schematic of a program counter.
When the power is switched on, the program counter is forced to 0 and the instruction fetch starts from address 0 (~reset = 0 forces the flip-flops to a value of 0).
If the instruction is a conditional branch instruction (which is discussed in Sectionย 15.3), branch = 1 and the sum of the current PC value (Qs) is added to the branch offset (which is passed through MUX1) and that value is sent to Ds to update the PC value.
If the instruction is a jump instruction, then the value of jump target (which is passed through MUX2) is loaded into Ds to update the PC value.
If the instruction is not a program flow control instruction (i.e. it is not a branch or jump instruction), then the PC is incremented by 1 after each instruction is fetched.