Microcontrollers: 1 Microcontroller Components
Microcontrollers: 1 Microcontroller Components
1 Microcontroller components
Credit: Bolton, Mechatronics: Electronic control systems in mechanical and electrical engineering
2 Microprocessors
Credit: Bolton, Mechatronics: Electronic control systems in mechanical and electrical engineering
1
The microprocessor processes data by fetching instructions from the memory, decoding them,
and executing them. The architecture of the processor varies based on its application, but
there is a general form and some common components:
Arithmetic and Logic Unit (ALU): This unit performs the data manipulation.
Control Unit: This determines the timing and sequence of operations by generating
a timing sequence. For example, a microprocessor with a frequency of 1 MHz has a clock
period of 1 µs and instructions take multiple (2-12) clock cycles. The cycle is the time unit
of the processor.
Registers: Internal data on the CPU, a kind of temporary memory. These registers
may have different functions, some of which are listed below
Accumulator register (A): This register is where data for input to the ALU is stored.
First, the processor supplies an address of the desired memory bit-word to the address bus,
and this address is used so that the CPU can read that data and load it into the data bus.
Since operations may involve more than one number, the first number may be loaded into the
accumulator, while the second number is accessed directly from memory. Then, the output
is loaded into the accumulator.
Status register: This register contains individual bits which each represent a special
information or status. These bits are called flags. For example:
Flag 1 0
Z Result is zero Result is not zero
N Result is negative Result is not negative
C Cary is generated Carry is not generated
V Overflow No overflow
I interrupt ignored interrupt processed
some notes: carry indicates that the addition of two numbers causes the carry of the
most significant bits: 111 + 001 = (1)000. This also occurs in subtraction: 000 - 001 =
111. overflow Is in effect with signed numbers. In these numbers, the leftmost bit indicates
whether a number is positive or negative. If two numbers with the signed bit off are added,
and the signed bit is on (or vice-versa) it indicates the addition overflowed into he sign bit,
and the overflow flag is activated.
Program counter register (PC) or instruction pointer (IP): This address is used
for the processor to keep its place in the program its running. Each instruction has an
address, and as they’re executed, this register is updated to point to the new instruction.
It’s normally incremented unless the instruction points it to a new point in the program.
Memory address register (MAR): This contains the address of data, such as the
second number during an addition.
Instruction register (IR): This stores an instruction for execution. This is known as
the fetch-execution cycle.
General-purpose registers: Temporary storage for data, addresses, or other informa-
tion shuffling.
Stack-point register (SP): The stack is a special area of the memory in which program
counter values can be stored when a subroutine part of a program is being used. This register
sets the address which defines the top of the stack.
2
2.1 Example registers
These are examples from the Motorola Freescale M68HC11
Credit: Bolton, Mechatronics: Electronic control systems in mechanical and electrical engineering
Port A is a data register with three input lines, four output lines, and one line that can
be either. There is a complimentary control register with a variety of functions.
Credit: Bolton, Mechatronics: Electronic control systems in mechanical and electrical engineering
The C register can be in or out, and includes a direction register where the bits in the
direction register determine the direction of each bit in the main register.
Credit: Bolton, Mechatronics: Electronic control systems in mechanical and electrical engineering
The E port is input only, and can be used as the input to an internal ADC, when the
ADC is active.
Credit: Bolton, Mechatronics: Electronic control systems in mechanical and electrical engineering
3
2.2 Multiplexer
The way that signals are controlled by the processor and other elements is through logic
gates. One particular form of this is the multiplexer, which can receive multiple signals, and
select one to output.
Credit: Bolton, Mechatronics: Electronic control systems in mechanical and electrical engineering
Credit: Bolton, Mechatronics: Electronic control systems in mechanical and electrical engineering
4
3 Memory
Credit: Bolton, Mechatronics: Electronic control systems in mechanical and electrical engineering
Memory elements are essentially large numbers of storage cells which each can hold a bit. The
storage cells are grouped into locations, with each location storing a bit-word and having an
address. So, with a 4-bit address, you have 16 addresses and 16 different memory locations.
Credit: Bolton, Mechatronics: Electronic control systems in mechanical and electrical engineering
5
Programmable ROM (PROM): This is ROM that an be programmed once by a user.
Each bit starts at 0, but can be permanently fused open.
Erasable and programmable ROM (EPROM): Like EPROM in function, but they
can be erased with ultraviolet light and reprogrammed.
Electrically erasable (PROM): Similar to EPROM, but erased with ultraviolet light.
Random-access memory (RAM): Temporary data, for current operations.
ROM is sometimes referred to as firmware, and RAM is called software.
Credit: Bolton, Mechatronics: Electronic control systems in mechanical and electrical engineering
A generic form of the microcontroller can be seen above, and the application of this controller
to a washing machine below.
6
Credit: Bolton, Mechatronics: Electronic control systems in mechanical and electrical engineering
4 Input/output
Microcontrollers often include ports so that the processor can communicate with peripheral
devices. These often have varying speeds and characteristics, so these controllers often have
interface chips, which can synchronize data transfers.
• Timing control
• Code conversion
7
4.1 Buffers
Credit: Bolton, Mechatronics: Electronic control systems in mechanical and electrical engineering
A buffer connects two parts of a device and prevents unwanted interference. A common
form is the tri-state buffer, which can enable 0 or 1 to pass through, or be disabled for a
high-impedance. These are often used to hold data until the CPU requests it, or multiplex
data to different peripherals.
Credit: Bolton, Mechatronics: Electronic control systems in mechanical and electrical engineering
8
4.2 Handshaking
Credit: Bolton, Mechatronics: Electronic control systems in mechanical and electrical engineering
Unless two devices are operating at exactly identical rates, they must use a handshake to
share data. For parallel data transfer, microcontrollers commonly use strobe and acknowl-
edge:
3. the CPU reads data from the in/out section and sends an INPUT ACKNOWLEDGED
signal
4. The peripheral reads the INPUT ACKNOWLEDGED signal and can send more data
In the below example, the processor sends either a pulse or an interlock signal over STRA,
and waits for the peripheral to respond by sending either a rising or falling signal over STRB.
At that point, the processor can send its data.
Credit: Bolton, Mechatronics: Electronic control systems in mechanical and electrical engineering
a full handshake occurs when two signals are sent, the first indicating the processor is
ready to receive, and the second to indicate the data has been read.
9
4.3 Polling and interrupts
Credit: Bolton, Mechatronics: Electronic control systems in mechanical and electrical engineering
Credit: Bolton, Mechatronics: Electronic control systems in mechanical and electrical engineering
synchronouse transmission is when the receiver and transmitter share a clock signal,
so it is straightforward to synchronize transmission and reception.
10
4.5 Peripheral interface adapters
Credit: Bolton, Mechatronics: Electronic control systems in mechanical and electrical engineering
These are programmable devices which can be used as adapters for peripherals.A typical
PIA will contain:
peripheral interface register: Output ports operated differently from input ports
because they must be able to hold the data for the peripheral. The register is latched (ie
connected) when used for output, and unlatched when used for input.
data direction register indicates whether the lines are inputs or outputs.
control register determines the active logical connections
control lines, used for interrupts
11
Credit: Bolton, Mechatronics: Electronic control systems in mechanical and electrical engineering
Credit: Bolton, Mechatronics: Electronic control systems in mechanical and electrical engineering
To change data from a serial form to a parallel form, microcontrollers use a Universal
Asynchronous Receiver/Transmitter (UART). The common form of this devices is
the Asynchronous Cummunications Interface Adapter (ACIA). Data flow between
microcontroller and ACIA occurs over an 8-bit bus, and controlled by a read/write signal
to the ACIA. Chip select lines are used to select a particular ACIA, and the register select
line is used to select the register within the ACIA; if high, the data transmit and receive
lines are selected, otherwise the control and status registers are selected. The peripheral side
includes two serial data lines: one for tranmission, one for reception; and three control lines:
clear-to-send, request-to-send, and data-carrier detect (which can be used to detect whether
incoming data is valid, for instance in a modem to see if the connection has been broken).
12
One example is the control of an LED display, shown below. Four input signals determine
what character is displayed on each panel. Note that RBI stands for ripple-blanking input,
and can be used to turn off the display if, for instance, you don’t want a left-hand zero.
Credit: Bolton, Mechatronics: Electronic control systems in mechanical and electrical engineering
Credit: Bolton, Mechatronics: Electronic control systems in mechanical and electrical engineering
Credit: Bolton, Mechatronics: Electronic control systems in mechanical and electrical engineering
13