ECE 252 Introduction to Electrical Engineering

Lesson 16. Computer Circuits

Base Conversion by Example

Many calculators can do base conversions, but you should also know how to do it by hand.

Binary to Decimal

101101012 = 1x27 + 0x26 + 1x25 + 1x24 + 0x23 + 1x22 + 0x21 + 1x20 = 128 + 0 + 32 + 16 + 0 + 4 + 0 + 1 = 18110

Decimal to Binary

235/2 = 117 with a remainder of 1
117/2 = 58 with a remainder of 1
58/2 = 29 with a remainder of 0
29/2 = 14 with a remainder of 1
14/2 = 7 with a remainder of 0
7/2 = 3 with a remainder of 1
3/2 = 1 with a remainder of 1
1/2 = 0 with a remainder of 1

String the remainders together, starting from the last one:
23510 = 111010112


A typical computer consists of a central processing unit (CPU) that takes care of math and executing the instructions, memory that stores data and program code, and input/output (I/O) that allows communication with the outside world through such devices as printers, keypads, and video displays.  A basic building block of most computers is the metal-oxide semiconductor field-effect transistor (MOSFET).  A simplified diagram of a MOSFET is shown below.

You should see an image here instead of this text.

If the gate-to-source voltage is zero, the drain and source are disconnected - the MOSFET acts like an open switch.  When a voltage is applied to the gate, the drain and source are connected - the MOSFET acts like a closed switch.

This simple property makes the MOSFET ideal as a computer building block.  One simple circuit that can be made is a NOT gate (an inverter), as shown below.

You should see an image here instead of this text.

VDD is the supply voltage.  Its value will depend on the technology of the digital circuitry.  Typical values are 5 V and 3 V.  When Vin is low, corresponding to a logic 0, the transistor will be off (non-conducting from the drain to the source).  If Vout draws little current (which is common), then there is little voltage drop across the resistor, and Vout is approximately the same as VDD.  This makes the output high, a logic 1.  When Vin is high, corresponding to a logic 1, the transistor will be on (conducting from the drain to the source).  This means that Vout is essentially shorted to ground through the MOSFET.  This makes the output low, a logic 0.  To summarize:  Vout is the opposite logic state from Vin; thus the circuit is a NOT gate or inverter.

Although the above circuit is fully functional, a typical NOT gate is actually made with two MOSFETs.  AND, OR, NAND, NOR, other logic circuits, memory cells, and registers can also be made from MOSFETs.


Computers store data and program steps in memory.  Sometimes this memory is on the same chip as the CPU, and sometimes it's on external chips.  Microprocessors typically don't have much on-chip memory, but microcontrollers do.  It is convenient to divide semiconductor memory into two types: random access memory (RAM) and read only memory (ROM).

RAM is volatile.  That means that it will lose its data when the power is switched off.  For this reason it is only used for temporary storage.  It may be significantly higher in speed than ROM.

RAM can be subdivided into various types:

  1. SRAM - Static RAM.  SRAM is the fastest version of RAM, which is why it is used in a microprocessor for registers and cache.  It also doesn't use much power.  It has the disadvantage that it takes up a lot of chip real-estate; it takes four transistors to make an SRAM cell.
  2. DRAM - Dynamic RAM.  DRAM is not quite so fast as SRAM, but it has a distinct advantage:  A DRAM cell can be made with but one transistor, as shown in the diagram below, which is simplified for illustrative purposes.

    You should see an image here instead of this text.

    In order to write a bit to a DRAM memory cell, the logic level is placed on the I/O line, and the gate (Read or Write in the diagram) of the transistor is triggered.  The capacitor will either charge up for a logic 1 or discharge for a logic 0.  To read a bit, the gate of the transistor is triggered, and the bit is read on the I/O line.  A great disadvantage of DRAM is that the logic level stored on the capacitor leaks off over time.  Therefore DRAM requires that the data stored be periodically read and rewritten.  This process is called refresh, and requires additional circuitry.  Many DRAM chips require that all their memory cells be refreshed every 64 ms.  The above explanation has been simplified.  Because of its high density and low cost, DRAM is the main memory in most computers. 
  3. Other more exotic forms of RAM exist.

ROM is non-volatile.  It retains its data after the power is shut off.  This makes it ideal for storing data and programs that must be retained when the computer is powered down.  A hard disk drive also serves this function.  The "read only" feature of ROM implies that it is intended to be permanent.  This type of memory might be used in a device such as a four-function calculator to hold the code for doing the math.  There would never be any expectation that the code would be changed.

ROM can be subdivided into various types:

  1. Mask ROM - ROM that is created at the factory with a photographic mask.  The data on a mask ROM cannot be changed by the user.  This is the type of memory that might be in a four-function calculator.  Mask ROM is gradually being replaced by newer technologies.
  2. OTP ROM - One-time-programming ROM.  Data can be written to the ROM by the user exactly once.  This type of ROM is frequently found on some general-purpose microcontrollers.  Typically, the user would debug a program using a development system, then, when the program is perfect, store it in the OTP ROM.
  3. EEPROM - Electrically-erasable programmable read only memory.  The bits in an EEPROM can be erased electrically, either in blocks or by erasing the entire chip at once.  Writing new data to an EEPROM is extremely slow (perhaps a few milliseconds per data word), so it is not used in applications where data must be frequently changed.  Some general purpose microcontrollers have EEPROM for storing programs or data.
  4. Flash memory.  Flash memory is technically a type of EEPROM, but it can be erased and rewritten much faster than ordinary EEPROM.  It isn't as fast as RAM, but it has the advantage that it is non-volatile.  Like the ordinary EEPROM, the flash memory cells must either be erased all at once or erased in blocks before new data can be stored.  In contrast, RAM can be overwritten one word at a time (a faster process).  Flash memory has many important applications:


Computers rely on buses to communicate and distribute data.  A bus is a collection of circuit paths, typically 8, 16, 32, or 64 bits wide.  Examples: the data bus and the address bus of a computer.  The address bus allows the CPU to tell memory what location to store data to or retrieve data from.  The data bus allows data to be passed among the computer's modules.  A bus must allow many devices to take control of the bus lines.  To avoid bus contention, only one device at a time may control the bus.  The three-state buffer, also known as the Tri-state® buffer, is a very useful device to control bus access.  A three-state buffer is shown in the diagram below.

You should see an image here instead of this text.

Data at the input will be transferred to the output if the gate is on.  With the gate off, the output has no defined logic level.  It is said to be "floating" or in the "high impedance" or "hi-Z" state.  The three-state buffer can therefore produce three different outputs: logic 0, logic 1, or hi-Z.  It is this hi-Z state that is useful for making a bus.  Several of these devices can be connected together as shown in the diagram below.

You should see an image here instead of this text.

If, for example, the CPU has its gate enabled while the Memory and the Hard Disc Controller are disabled, the CPU's data will appear on the Data Bus Line.  If no device has its gate enabled, the Data Bus Line will be in the Hi-Z state.  A well-designed computer will never allow more than one gate to be turned on at the same time.

Analog-to-Digital Converters

Much of the information in the real world is in analog form.  For example, the current from a solar cell is a continuous, non-discrete, analog value dependent on the amount of sunlight falling on the solar cell.  In order to analyze such information with a computer, it is necessary to convert the analog data into digital form.  The analog-to-digital converter (A/D converter) does this.  Many microcontrollers have built-in on-chip A/D converters.  Stand-alone microprocessors require the A/D converter as a separate device.  A simplified diagram of an A/D converter is shown below.

You should see an image here instead of this text.

vin is the analog voltage to be converted to digital.  Vref+ and Vref- are DC reference voltages.  They should be set just outside the maximum and minimum values expected from vin.  For example, if vin goes from 1.2 V to 4.6 V, then 1 V would be an appropriate value for Vref- and 5 V would be an appropriate value for Vref+.

D0-D7 are the bits of the digital output, with D0 being the least significant bit.  The above A/D converter has a resolution of 8 bits.  A/D converters can be found in other resolutions, such as 12-bit and 16-bit, but 8-bit is probably the most common.  The 8-bit A/D converter has a base 2 output ranging from 00000000 to 11111111.  In decimal, this would be 0 to 255.  It's up to the computer to decide what these bits mean.

The A/D converter needs to be told when to start converting an input to digital.  The Start Conversion pin takes care of that.  The CPU needs to know when the conversion is finished so that it can read D0-D7.  The Conversion Complete pin takes care of that.  One technique to get repeated conversions at the fastest possible rate is to connect the Complete Conversion output to the Start Conversion input.

Not shown on the above diagram are inputs for power, ground, and a system clock.  It may take 16 clock cycles, or so, to complete a conversion.

Frequently it is necessary to take multiple samples of an input signal to determine its behavior over time.  For example, it may be desired to store a song in digital form.  In such cases, the input must be sampled fast enough to capture all the relevant information.  To do this correctly, one must know the highest frequency present in the input signal.  A certain song may contain frequencies from 25 Hz to 15 KHz.  The A/D converter must be sampled fast enough to capture the 15 KHz component.  The Nyquist Sampling Theorem states that a signal containing frequencies no higher than fmax can be completely characterized by sampling it at a rate of 2fmax samples per second or higher.  For example, if the highest frequency in the song is 15 KHz, the input signal must be sampled at 30,000 samples/second or higher.  If the signal is sampled at less than this rate, aliasing will occur, distorting the signal.

The decimal value of the digital output for an 8-bit A/D converter can be calculated from the following formula:

vout = 255(vin - Vref-)/(Vref+ - Vref-)

If vin is exactly equal to Vref-, the result is 0 (00000000 in binary).  If vin is exactly equal to Vref+, the result is 255 (11111111 in binary).  It's important that vin be kept within the reference voltages.  The CPU can't tell the difference between a vin exactly at Vref+ and a vin that is 10 V higher than Vref+; they both produce 11111111 as an output.  Outputs of 00000000 and 11111111 cannot be trusted.

Microprocessor Facts

Although the microprocessor is the heart of a PC, there are far more microcontrollers in the world than there are microprocessors.  That's because microcontrollers are used in everything from automobiles to electronic toothbrushes.  Unlike a microprocessor, a microcontroller has onboard memory and I/O.  It's a computer on a chip.  Although there are several brands and types of general purpose microcontrollers, most microcontrollers are embedded.  An embedded system is a computer system intended to do just one, or a few, things.  This would be the case for the computer in your calculator, cell phone, digital camera, mp3 player, inkjet printer, copy machine, and the dozens of microcontrollers in your car.  Intel makes more microprocessors than any other company, but Motorola (and other companies) surpass Intel in microcontroller production.

The Intel 4004, the first microprocessor, was released in 1971.  Ever since, the speed and power of microprocessors has been on an exponentially increasing curve.  This continuing increase in processing power is called Moore's Law.  It takes various forms, referring to  such things as clock speed and device density.  One general statement is that processing power doubles every 18 months.  This has been more or less true over the last 40 years, although the curve seems to be flattening out.  To extend Moore's Law, Intel and others have now placed less emphasis on increasing clock speed and have instead opted to put multiple cores on the same chip.  This is roughly equivalent to having more than one microprocessor working in parallel.  So far, the increase in processing power, while real, has not translated into greatly increased speed in program execution.  This is because breaking up a process into parallel streams that can run independently is difficult, and not even possible for some tasks.  Development of improved parallel programming tools will help mitigate this problem.

Another trick microprocessor designers use to improve processing speed is pipelining.  This technique takes advantage of the structure of a machine language instruction.  A typical instruction may have the following parts: fetch the program instruction, decode it, execute it, write the result back to memory.  By dividing up the labor with a pipeline, the microprocessor may be able to fetch one instruction, decode a second, execute a third, and write back a fourth - all at the same time.

The memory bottleneck is a continuing problem with computers.  Microprocessors are blazingly fast, but the bus to memory is slow.  To address this problem cache was invented.  Cache is very fast (usually SRAM) memory that sits between the CPU and the main (DRAM) memory.  Frequently the cache is on the microprocessor chip itself, in which case it is called L1 cache (a computer frequently also has L2 cache and L3 cache).  The cache stores recently-used program code and data.  When, for example, the processor wants another line of code, it first looks in the cache.  If the data is there, access is fast - main memory does not have to be accessed.

As the transistors on a chip become smaller and more dense, problems crop up, notably power density and quantum tunneling.  With more and faster transistors packed into a smaller space, getting rid of the heat produced is a challenge.  Fans and heat sinks help, but they are insufficient to fully address the problem.  Quantum tunneling is a quantum mechanical phenomenon that results from the circuit elements being very close together.  To oversimplify, an electron that is supposed to be in one circuit element jumps over to another circuit element resulting in a logic error.  Both of these problems can be reduced by decreasing the operating voltage.  Power is proportional to V2/R, so cutting the voltage by half (all other things being equal) will cut the power to one quarter.  Lowering the voltage also reduces the effect of quantum tunneling.  It is therefore not surprising that operating voltages of microprocessors have been steadily decreasing over the last 40 years.

Many microprocessors use CISC (complex instruction set computer) architecture.  Intel's Pentium series is an example of CISC.  Such processors have many complex instructions, which may be of various lengths (a few bytes to many bytes), and may execute in various amounts of time (a few instruction cycles to many instruction cycles).  Other microprocessors, such as the Power PC and ARM, use RISC (reduced instruction set computer) architecture.  RISC is characterized by fewer, simpler instructions, which may all be of the same length and may all execute in the same amount of time.  RISC processors are typically faster and smaller than CISC processors.  The real estate saved by the RISC architecture is frequently used for extra registers and cache memory.  Assembly language RISC programs are frequently much longer than their CISC counterparts.


Computers use flip flops for registers and for algorithmic state machines.  A flip-flop is a device that has two stable states and that can be used to store information.  The simplest kind is the D flip-flop, shown below.

You should see an image here instead of this text.

The basic operation is as follows:  A data bit (either a 1 or a 0) is placed on the D input.  A clock pulse triggers the clock input (the triangular input on the figure).  The data on D is copied to Q, and its complement is placed on Q'.  The data on Q and Q' will remain stable until another clock pulse arrives.  A diagram of this process is shown below.

You should see an image here instead of this text.

The logic level on the D input must be stable for a time before the clock pulse arrives.  This is called the setup time, and it will be found in the specifications for the particular D flip-flop chosen.  The 74F74 D flip-flop has a setup time of 3 ns.  If the logic level on D is not stable for at least the setup time, the output value on Q may not be valid.

The logic level on the D input must remain stable for a time after the clock pulse arrives.  This is called the hold time, and it will be found in the specifications for the particular D flip-flop chosen.  The 74F74 D flip-flop has a hold time of 1 ns.  If the logic level on D is not stable for at least the hold time, the output value on Q may not be valid.

There will be a small delay before the new logic levels are latched into Q and Q'.  For the 74F74, it's a maximum of 8 ns after the clock pulse arrives.

Some CPUs use microcode to decode and execute machine language instructions.  Others use algorithmic state machines.  The D flip-flop can be the basis of an algorithmic state machine.  Each state is associated with a single D flip-flop.  Logic levels are circulated through the states in such a way that the D flip-flop of the active state is the only one set to a logic 1.

At this time you should complete Tutorial 16 on computer circuits.