Input, output and storage

How barcode readers, cameras, laser printers and RFID work; magnetic, optical and flash storage; RAM, ROM and virtual storage.

A9.9Computer architectureA level25 min

Do this lesson in the simulator

At GCSE (F9.6 and F9.7) you compared RAM with ROM and magnetic, optical and solid state storage by their characteristics. At A level you must also explain how some devices work: how a barcode reader turns stripes into digits, how a camera turns light into numbers, how a laser printer puts toner on paper, and how an SSD stores bits with no moving parts. You also need to choose devices for a given problem and justify the choice, and to know what virtual storage is.

Input and output devices

Barcode reader

A 1D barcode is a row of black bars and white spaces of different widths. A laser barcode scanner sweeps a laser beam across it, usually with a moving mirror. White spaces reflect the light and black bars absorb it. A photodiode measures the reflected light, producing a pattern of high and low signals whose timing matches the widths of the bars. The reader converts the widths into binary and then into digits, and checks the check digit to catch a misread.

A camera-based (CCD or CMOS) reader instead takes a picture of the whole code and finds the bars by image processing. It needs no moving parts and can also read 2D codes such as QR codes, which a sweeping laser cannot.

Digital camera

A lens focuses light onto an image sensor, a grid of millions of light-sensitive cells (photosites), made as a CCD or, in almost all modern cameras, a CMOS sensor. Each photosite builds up a charge in proportion to how much light hits it during the exposure. Over the sensor sits a colour filter array, usually a Bayer pattern, so each photosite measures only red, green or blue light. An analogue-to-digital converter turns each photosite's voltage into a number, and the camera's processor combines neighbouring values to give every pixel a full colour, then compresses and stores the image.

BugBot's camera is a CMOS sensor of this kind. The simulator's camera_image() hands you the result: rows of pixels, each a red, green and blue value from 0 to 255.

Laser printer

  1. A rotating drum is given an even electrostatic charge.
  2. A laser, switched on and off as it sweeps across the drum, discharges the drum wherever the page should print, leaving an invisible image in charge.
  3. Toner, a fine charged powder, sticks to those parts of the drum only.
  4. The paper is given a charge that pulls the toner off the drum onto the page.
  5. A fuser melts the toner into the paper with heat and pressure.
  6. The drum is cleaned of leftover toner and charge, ready for the next page.

A colour laser printer does this four times, with cyan, magenta, yellow and black toner. Laser printers are fast and cheap per page for large volumes of text.

RFID

Radio frequency identification uses a tag, a microchip joined to an antenna, and a reader. The reader sends out radio waves. A passive tag has no battery: the reader's radio waves induce a current in its antenna, which powers the chip long enough to send its data, such as a unique ID number, back to the reader. Passive tags are cheap and small but work only at short range, from a few centimetres to a few metres. An active tag has its own battery, so it can transmit further. Unlike a barcode, a tag need not be in sight of the reader, so it suits contactless cards, stock tracking and pet microchips.

Secondary storage

Magnetic: the hard disk drive

A hard disk has one or more platters, coated in a magnetic material, spinning at thousands of revolutions per minute. Read/write heads on an actuator arm move across the platters, floating just above the surface. To write, a head magnetises tiny regions one way or the other to store 1s and 0s; to read, it senses the direction of magnetisation. Data is laid out in circular tracks divided into sectors. To reach data, the arm must move to the right track (seek time) and wait for the right sector to spin round (rotational latency), so access is slow compared with an SSD, especially for data spread across the disk.

Optical: CD, DVD and Blu-ray

A disc stores data along one long spiral track. On a read-only disc the track is a series of pits and lands (flat areas). A laser shines on the track as the disc spins, and a sensor detects the reflected light. Light reflects differently at the edge between a pit and a land, and these changes represent the bits. Recordable discs use a dye layer that a stronger laser marks instead of pits. Blu-ray's shorter wavelength laser reads smaller pits, so more data fits on a disc.

Flash: the solid state drive

An SSD has no moving parts. It is made of NAND flash memory chips and a controller. Each flash cell is a transistor with a floating gate that can trap electric charge, and the trapped charge stays there without power; whether or how much charge is trapped represents the bits. Cells are organised into pages, which are grouped into blocks. Data can be written a page at a time, but can only be erased a whole block at a time, and each cell survives only a limited number of erase cycles. The controller hides this: it keeps a map of where each piece of data really is, spreads writes evenly across the chips (wear levelling) and manages erasing in the background.

Hard disk drive Solid state drive Optical disc
Capacity very high, cheapest per gigabyte high, but more expensive per gigabyte low (up to tens of GB per disc)
Speed of access slow: seek time and rotational latency very fast: no moving parts slowest
Durability moving parts can be damaged by knocks robust, but cells wear out after many writes discs scratch, but are light and cheap
Typical use bulk storage, backups, servers holding large files laptops, phones, boot drives, embedded devices distributing software, films, archives

RAM and ROM

RAM (random access memory) is main memory: it holds the programs and data currently in use, it can be read and written, and it is volatile, so its contents are lost when the power goes off. ROM (read only memory) is non-volatile and its contents are normally not changed in use. It holds the code a computer needs when it first powers on, such as the bootstrap loader. In many modern devices that job is done by flash memory, which is non-volatile like ROM but can be rewritten, so firmware can be updated. BugBot's firmware lives in flash; the values your program uses while it runs live in RAM.

Virtual storage

Virtual storage presents storage spread across many physical devices, perhaps in different places, as if it were one single storage device. The user or program sees one drive and does not know, or need to know, which physical disk holds their data. Cloud storage is the most familiar example, and organisations do the same with a network of pooled drives. It is easy to expand by adding devices to the pool, and files can be reached from anywhere, at the cost of depending on the network. Do not confuse it with virtual memory, which uses secondary storage as an extension of RAM; module A10 covers that.

Choosing a device

Exam questions give a scenario and ask for a suitable device, with a reason linked to the scenario. For example:

  • a delivery robot logging sensor data should use flash storage: no moving parts to be damaged by vibration, low power, and small;
  • a video archive of many terabytes should use hard disks: the lowest cost per gigabyte, and fast access is not needed;
  • a library tracking books should use RFID: many books can be read at once without lining each one up with a scanner.

Task: how much flash does a camera need?

Use the robot's camera to work out storage needs. Take one frame with camera_image(32, 24), which returns a list of rows, each row a list of pixels, and each pixel a tuple of three bytes (red, green, blue).

  • Count the pixels from the image you took, by measuring the lists, and print pixels: 768.
  • Work out how many bytes one frame needs, uncompressed, at 3 bytes a pixel, and print bytes per frame: 2304.
  • Work out how many whole frames fit in a 16 MiB flash chip (1 MiB is 1,048,576 bytes), and print frames in 16 MiB: 7281.
  • The camera itself sees 320 by 240 pixels. Print how many whole frames of that size fit in the same flash, as full-size frames in 16 MiB: 72.

Do not type the answers in as numbers. The robot does not move.

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

image = camera_image(32, 24)

Challenges

  1. The robot must record 10 seconds of full-size, uncompressed frames into 16 MiB of flash. How many frames a second can it store? Give two changes that would let it store more.
  2. Explain why a robot that shakes as it moves, like BugBot, should not use a hard disk.
  3. A supermarket wants to know every item in a trolley without taking them out. Which input device would it use, and why?