Microcontroller Operation:Instruction Register and Decoder

Instruction Register and Decoder

To execute an instruction, the processor copies the instruction code from the program memory into the instruction register (IR). It can then be decoded (interpreted) by the instruction decoder, which is a combinational logic block which sets up the processor control lines as required. These control lines are not shown explicitly in the block diagram, as they go to all parts of the chip, and would make it too complicated. In the PIC, the instruction code includes the operand (working data), which may be a literal value or register address. For example, if a literal (a number) given in the instruction is to be loaded into the working register (W), it is placed on an internal data bus and the W register latch enable lines are activated by the timing and control logic. The internal data bus can be seen in the manufacturer’s block diagram (Figure 1-1 in the PIC 16F84A data sheet).

Timing and Control

This sequential logic block provides overall control of the chip, sending signals to all parts of the chip to move the data around and carry out logical operations and calculations (see Appendix C). A clock signal is needed to drive the program sequence; it is traditionally derived from an external crystal oscillator, which provides an accurate, fixed frequency signal. More recent chips have an internal oscillator, which saves on external components.

A maximum frequency of operation is always specified; most current PIC 16 chips run at a maximum of 20 MHz, although newer designs reach 32 MHz. All can operate at any frequency below this maximum, down to 0 Hz. This is referred to as a static design: the clock can be stopped and the current MCU status will be retained. It takes four clock cycles to execute one instruction, unless it involves a jump, when it is eight. However, the execution of successive instructions overlaps to double the effective speed (pipelining; see data sheet).

The program starts automatically at program location zero, as long as the reset input is connected high (power-on reset). If required, a push button reset can be connected, which takes this input low for a manual reset. This should not normally be needed, but if there is a bug in the program or another system fault that causes the program to hang (get stuck in loop), a manual reset is useful, particularly during prototyping.

The only other way to stop or redirect a continuous loop is via an interrupt. Interrupts are signals generated externally or internally, which force a change in the sequence of operations. If an interrupt source goes active in the PIC 16, the program will restart at program address 004, where the sequence known as the ‘interrupt service routine’ (or a jump to it) must be stored. More details are provided in Chapter 6.

Leave a comment

Your email address will not be published. Required fields are marked *