Pages

20180521

Designing Embedded Hardware by John Catsoulis


  • Embedded computers are far more numerous than desktop systems, but far less obvious.
  • Embedded hardware is often much simpler than a desktop system, but it can also be far more complex too.
  • All data is stored in the computer as numbers.
  • The bootloader is a special program run by the processor that reads the operating system from disk and places it in memory so that the processor may then run it.
  • A microprocessor is a processor implemented on a single, integrated circuit.
  • A microcontroller is a processor, memory, and some I/O devices contained within a single, integrated circuit, and intended for use in embedded systems.
  • There is no real difference between data and instructions. A processor can be directed to begin execution at a given point in memory, and it has no way of knowing whether the sequence of numbers beginning at that point is data or instructions.
  • Data has no inherent meaning. [...] Meaning comes from how these numbers are treated under the execution of a program.
  • Data and instructions share the same memory.
  • Memory is a linear (one-dimensional) array of storage locations.
  • The internal data storage of the processor is known as its registers. The processors has a limited number of registers, and these are used to hold the current data/operands that the processor is manipulating.
  • Interrupts (also known as traps or exceptions in some processors) are a technique of diverting the professor from the execution of the current program so that it may deal with some event that has occured.
  • Interrupts free the processor from having to continuously check the I/O devices to determine whether they require service. [...] The I/O devices will notify it when they require attention by asserting one of the processor's interrupts.
  • The interrupt vector is the address at which an interrupt service routine (ISR) lies.
  • There are two ways of telling when an I/O device is ready for the next sequence of dta to be transferred. The first is busy waiting or polling, where the processor continuously checks the device’s status register until the device is ready. A better way is for the device to generate an interrupt to the processor when it is ready for a transfer to take place.
  • The advantage of interrupt polling over ordinary polling is that the polling occurs only when there is a need to service a device.
  • Polling interrupts is suitable only in systems that have a small number of devices; otherwise, the processor will spend too long trying to determine the source of the interrupt.
  • A software interrupt is generated by an instruction. It is the lowest-priority interrupt and is generally used by programs to request a service to be performed by the system software (operating system or firmware).
  • One main disadvantage of CISC is that the processors themselves get increasingly complicated as a consequence of supporting such a large and diverse instruction set.
  • RISC processors implement what is known as a “load/store” architecture. This means that the only instructions that actually referenced memory are load and store. In contrast, many (most) instructions on a CISC processor may access or manipulate memory.
  • DSPs have special hardware well suited to numerical processing of arrays. They often have hardware looping, whereby special registers allow for and control the repeated execution of an instruction sequence. This is also often known as zero-overhead looping, since no conditions need to be explicitly tested by the software as part of arithmetic operations.
  • Many processors have instruction and/or data caches, which store recent memory accesses. These caches are (often, but not always) internal to the processors and are implemented with fast memory cells and high-speed data paths. Instruction execution normally runs out of the instruction cache, providing for fast execution.
  • The primary purpose of ROM within a system is to hold the code (and sometimes data) that needs to be present at power-up. Such software is generally known as firmware and contains software to initialize the computer by placing I/O devices into a know state.
  • It is common for many microcontrollers to incorporate a small EEPROM on-chip for holding system parameters. This is especially useful in embedded systems and may by used for storing network addresses, configuration settings, serial numbers, servicing records, and so on.
  • The address space of the processor can contain devices other than memory. These are input/output devices (I/O devices, also known as peripherals) and are used by the processor to communicate with the external world.
  • There are three main ways in which data may be exchanged with the external world: programmed I/O, interrupt-driven I/O, direct memory access (DMA).
  • Using DMA bypasses the processor by setting up a channel between the I/O device and the memory. Thus, data is read from the I/O device and written into memory without the need to execute code to perform the transfer on a byte-by-byte basis.
  • Single-Instruction Multiple-Data (SIMD) computers are highly parallel machines, employing large arrays of simple processing elements. In an SIMD machine, each processing elements has a small amount of local memory.
  • The other major form of parallel machine is the Multiple-Instruction Multiple-Data (SIMD) computer. These machines are typically coarsely grained collections of semi-autonomous processors, each with their own local memory and local programs.
  • MIMD computers can be one of two types: shared-memory MIMD and message-passing MIMD.
  • The most common I/O is digital I/O, commonly called general-purpose I/O, or GPIO. These are ports that may be configured by software, on a pin-by-pin basis, as either a digital input or digital output.
  • Most microcontrollers have other subsystems besides digital I/O but provide the ability to convert the other subsystems to general-purpose digital I/O if the functionality of the other subsystems is not required.
  • Registers are the internal (working) storage for the processor. The number of registers varies significantly among processor architectures.
  • Assembly-language instructions equate directly to their machine code counterparts. SInce machine code is difficult to read and write (for a human), a mnemonic is used to represent the opcode.
  • The inconvenience of little endian is that data appears “backwards” in the computer’s memory if you display a block of locations.
  • Disassembly is the conversion from a sequence of machine code back to the mnemonics that represent that code. This is done when we have a machine code program (perhaps written by someone else) and we want to know what it does and how it works.
  • Absolute addressing is used when we branch or jump to some code that we know will always be at a given address.
  • Many processors implement one or more stacks, which serve as temporary storage in external memory. The processor can push a value from a register on the stack to preserve it for later use. The processor retrieves this value by popping from the stack back into a registers. In some processor architectures, popping is also known as pulling.
  • Most processors have a special register known as a stack pointer, which references the next free location on the stack. Some processors implement more than one stack and so have more than one stack pointer.
  • A better way to provide a fixed delay is to use a hardware timer, either as an internal peripheral to the microcontroller (and most have them) or as an external device. The timer generates an interrupt to the processor, and this gives a much more precise, reliable, and portable way of implementing a timing delay.
  • Forth is an extensible, highly interactive, stack-based language. It is extremely efficient and extremely versatile. In addition, Forth is relatively easy to “bring up” on a virgin machine, and the structure and functionality of the language make it ideal for debugging bth system hardware and software. In fact, it is fantastic for debugging new hardware.
  • Forth is predominantly written in Forth and is interpreted by itself at runtime. The virtual machine running Forth is typically coded directly in the assembler both for speed operation and to take advantage of the characteristics of the target computer directly.
  • Forth is at once a compiler, an interpreter, and, in a fashion, an operating system too.
  • Forth uses threaded code, which is a list of subroutine identifiers (words). Each word within a program is called in turn, thus producing the sequence of running code. The interpreter is responsible for calling words as appropriate and is capable of only three operations.
  • Forth uses two stacks for its operation. The first stack is the parameter stack used to pass data between words. The second stack is the return stack and holds the return addresses for currently running words. Typically, the return stack is the system stack of the processor.
  • The beauty of Forth is its ability to build upon itself, allowing you to test as you go. To this end, keep your Froth words to three or four lines of code where possible.
  • Keep it simple and focus on what you’re trying to achieve. A simple Forth word that solves a specific, simple problem is better than a complicated do-all word that is difficult to write and hard to debug.
  • Most peripherals and memory chips have a chip-select input. Chip selects are important since there are many memory and peripheral chips within a computer system. It is through the chip select that the processor will enable the chip so that it can write data to it or read data from it.
  • Diodes are useful for removing negative voltages from a signal, a process known as rectification.
  • Most of the current usage of a digital system occurs during transitions of state--in other words, during the clock edges. The more frequent the clock edges, the more the average current usage goes up. Therefore, the faster a processor runs, the more power it consumes.
  • Ignoring device timing is a sure way of guaranteeing that your system will not work.
  • If you want to design and build reliable systems, remember that timing is everything.
  • A transition is never instant; it can be several nanoseconds in duration, and there is considerable variation between different devices.
  • If possible, a very useful thing to include in your design is a serial interface, even if you don’t need a serial port for the final application. A serial port is extremely useful for printing out diagnostic and statue information from the system, and can be an indispensible diagnostic tool.
  • The other mandatory debugging tool is the status LED. A flashing LED can tell you volumes about a machine being tested if the LED is used intelligently by the software and programmer. The more status LEDs you have, the better life will be.
  • Batteries are easy to use. The only caveat is to ensure that the battery (or batteries) you have chosen can supply enough current at the right voltage. WIth the right choice of battery and a carefully designed system, you can achieve extended operation over very long periods.
  • An embedded computer may need only an average supply of 20 mA but may require as much as 100 mA at peak loads. This is especially true of systems using flash memory, which may require high currents during write operations.
  • A voltage regulator is a semiconductor device that converts an input DC voltage (usually a range of input voltages) to a fixed output DC voltage. They are used to provide a constant supply voltage within a system.
  • There are three types of DC-DC converters: linear regulators, which produce lower voltages than the supply voltage; switching regulators that can step up (boost), step down (buck), or invert the input voltage; and charge pumps, which can also step up, step down, or invert the supply voltage, but with limited current-drive capability.
  • Digital systems are inherently analog in operation. Digital signals suffer degradation and nose due to analog effects present in the system. Spurious noise or reflections from nearby electrical machinery or radio transmission can induce signals within your circuit that can cause false events to occur, or even prevent a digital system from functioning at all.
  • A ground place is a large conducting surface that can serve as the current return path for all loops in the circuit. A ground plane is often implemented as a complete, internal PCB layer.
  • Capacitive coupling is the coupling of electric fields. A signal on one wire, through its associated electric field, can capacitley induce a phantom “signal” in an adjacent signaal line. This is known as crosstalk in digital systems. If not signed correctly, the magnitude of the crosstalk in a system can be significant and can easily cause a crash.
  • The decoupling capacitors should be placed as close as possible to the power points of the devices. Surface-mount capacitors have very low inductance connections, and so are preferable.
  • Ground bounce is ringing (oscillation) on signal lines caused when one or more outputs on the same device are being switched from high to low. This ring can be of significant amplitude and can adversely affect the system.
  • You need to consider the effect that several changing outputs may have on your circuit.
  • If you’re using a grounding mat, dont’ forget to take your embedded system off it before powering up. The grounding mat is conductive, and powering up a system while it is in contact with the mat can be disastrous.
  • When you’re developing your embedded system, it’s best to start with a development kit from the processor’s manufacture.
  • Soldering is very easy to do well, and very easy to do badly.
  • It is possible to build very simply circuits by just soldering the components together in free space. [...] This technique is variously referred to as a rat’s nest, bird’s nest, or “what the hell is that?”
  • As a general rule, breadboards are bad news, and their use should be avoided at all costs. They suffer from excessive capacitance, crosstalk, and noise susceptibility and, as such, are completely inappropriate for microprocessor system construction.
  • Wire Wrapping is a very fast prototyping technique and is very robust and reliable. [...] WIre wrapping is good for prototyping or for building one-off designs.
  • PCBs can be either single-sided (one layer), double-sided (two layers), or 4-layered, 6-layer, 8-layered, 12-layered, or more. The more layers you have, the easier it is to route your interconnections, but the costs of fabrication go up considerably with extra layers.
  • [PCB] Tracks are used to interconnect components. Track width is expressed in thousands of an inch (“mils”) of in millimeters. Tracks can be of varying thickness, and often a PCB will have different widths for different tracks. The fatter the track, the more current it can carry. The thinner the track, the easier it is to fit more tracks in a given space, and, therefore, the easier it is to route the PCB.
  • Tracks should always change direction by 45-degree turns.
  • The first thing to note when laying out a PCB is that someone is going to have to assemble it.
  • Whatever you decide about orientation, group related components together.
  • Any analog circuitry should be as far from the power connector and its support components as possible. By placing chips into functional groups, routing is made easier.
  • In high-speed systems, you need power and ground planes that are continuous. In other words, you need plans that cover the entire PCB with no breaks. Any break in the power or ground plane makes the current-loop area larger, and this can increase inductance and radiation. This means that for high-speed systems, you really need to use four or more layers on the PCB.
  • All power and ground traces should be as fat as possible, and, if feasible, separate power and ground planes (layers) should be used. The power ground (ground comping in with the power supply) should be separate from the signal ground or digital ground (the ground running to all your chips), and both should be separate from the analog ground (the ground for your analog components), if one is present. They should all be connected together, but only at one point. This helps isolate the digital and analog sections from each other’s noise, as well as from the power-supply noise.
  • Decoupling capacitors should be as close as possible to each power pin or each integrated circuit.
  • Good practice is to set your clearances to be equal to or greater than the minimum track width to which the PCB manufacturer can etch. Anything finer, and you’re asking for trouble.
  • Start construction by soldering in the power connector, voltage regulator, and its support components, including “power” LED if you’ve included one in your design.
  • Don’t try to be too adventurous at any stage of the building process. If everything suddenly stops working, it’s much easier to find the cause if you’ve only made on change or addition. Take things one step at a time.
  • Learning to debug is learning to think carefully and clearly.
  • The essence of debugging is establishing what works and what doesn’t work.
  • For any one problem, there is a multitude of possible causes. Debugging is therefore about isolating a fault, and this is best done by a “20 questions” approach. Divide and conquer to solve the problem.
  • The moral of the story: don’t assume anything, and check everything. If it still doesn’t work, you haven’t done the checking carefully enough.
  • The JTAG port allows for real-time debugging of hardware and software. It allows you to single-step or multi-step through code running directly on the target system.
  • I have found it good practice to give the processor control of the flash’s reset. As part of the processor’s initialization routines executed in its reset firmware, I get the processor to reset the flash, nudging it into reality. It’s a simple thing, but it makes all the difference for a reliable system.
  • I2C uses two wires to connect multiple devices in a multi-drop bus. The bus is bidirectional, low-speed, and synchronous to a common clock. Devices may be attached or detached from the I2C bus without affecting other devices.
  • The two wires used to interconnect with I2C are SDA (serial data) and SCL (serial clock). Both lines are open-drain. They are connected to a positive supply via a pull-up resistor and therefore remain high when not in use. A device using the I2C bus to communicate drives the lines low or leaves them pulled high as appropriate.
  • You can use I2C to add simple LCDs to your embedded computer. These LCDs are usually just a few lines of text high, but are useful for simple message display functions.
  • Serial I/O involves the transfer of data over a single wire for each direction. All serial interfaces convert parallel data to a serial bit stream, and vice versa. Serial communication is employed when it is not practical, either in physical or cost terms, to move data in parallel between systems.
  • For embedded computers, a simple serial interface is the easiest and cheapest way to connect to a host computer, either as part of the application or merely for debugging purposes.
  • In any transfer of data over a potentially noisy medium (such as a serial cable), the possibility of errors exists. To detect such errors, many serial systems implement parity as a simple check of the validity of the data. The parity bit of a byte to be transmitted is calculate by the sending UART and included with the byte as part of the transmission. The receiving UART also calculates the parity bit for the byte and compares this against the parity bit received. If they match, the receiver assumes that everything is fine. If they do not, the receiver then knows that something went amiss and that an error exists.
  • When two remote systems are communicating serially, there needs to be some way to prevent the transmitter from sending new data before the receiver has had a chance to process the old data. This process is known as handshaking, or flow control. The way it works is simple. After transmitting a byte, the transmitter will not send again until it has been given confirmation that the receiver is ready.
  • If an embedded system is to be permanently connected to a host computer via an RS-232C serial interface, it is possible to parasitically power the embedded system from the serial interface.
  • Unlike RS-232C, which is referenced to local ground, RS-422 uses the difference between two lines, known as a twisted pair or a differential pair, to represent the logic level. THus, RS-422 is a balanced transmission, or, in other words, it is not referenced to local ground. Any noise or interference will affect both wires of the twisted pair, but the difference between them will be less affected. This is known as common mode rejection.
  • The basic purpose of IrDA is to provide device-to-device communication over short distances.
  • SInce IrDA communicates using light, there must be some way to distinguish between a logic 0 and a logic 1 during transmission. To solve this problem, IrDA uses a bit-encoding scheme known as Return-to-Zero, or RZ.
  • Now, most UARTs are not capable of performing transmission in RZ or PPM encoding. Therefore, a special device, known as an EnDec (Encoder Decoder), converts the standard UART output to RZ, and vice versa.
  • FOr information an application (and remote control) IR protocols and programming, go to http://www.remotecentral.com.
  • Series A [USB] connectors are for upstream connections. In other words, a series A receptacle is found on a host or hub, and a series A plug is at the end of the cable that attaches to the host or hub.
  • A series B [USB] receptacle is found on a USB device, and a series B plug is at the end of the cable coming downstream from a host or hub.
  • One possible solution to implementing USB in your embedded system is to use a USB-to-SPI bridge.
  • CAN is a network for industrial applications, where a conventional network just won’t do. CAN is suited to electrically noisy and harsh conditions and is the network of choice in electrically severe environments.
  • Amplifiers are used to interface one analog circuit to another. An amplifier is a circuit that increases (or decreases) a given input voltage to produce an output voltage.
  • The waveform of the amplifier’s output signal should be identical to the input signal; only its amplitude will have changed. The amount of increase or decrease in the signal is known as the gain of the amplifier.
  • A differential amplifier multiples the difference between two input signals and is used to amplify small signals that may be subject to noise. By amplifying the difference between the signal of interest and a reference, any noise present is reduced (since the noise will affect both the signal and the reference equally).
  • The process of converting an analog signal to digital is known as sampling or quantization. ADCs have two principal characteristics: sample rate and resolution.
  • The faster the sample rate, the more accurate your sampled results will be.
  • Since your sampling is quantizing the signal both in terms of amplitude (ADC resolution) and time (sample rate), a quantization error will always result.
  • By placing three accelerometers orthogonally, you get an accurate 3-D motion recorder.
  • Pressure sensors work by measuring the deflection of a diaphragm separating two chambers. One chamber is exposed to the pressure that is being measured, while the other chamber holds a reference pressure. The pressure difference between the two chambers causes the diaphragm to deflect, and this deflection is converted into a voltage that is proportional to the pressure difference.
  • A low-pass (averaging) filter on the PWM output will convert the pulses to an analog voltage, proportional to the duty cycle of the PWM signal. By varying the duty cycle, we can vary the analog voltage.
  • If your hardware and software are responsible for moving a physical object, then a bug can easily cause physical damage too. So be careful.
  • Using PWM, you can get very slow mtor speeds and very fine control. The pulses can cause a jerkiness to the motor if the overall frequency is low, but by choosing a high frequency, the jerkiness is averaged out.
  • The easiest way to measure a motor rotational speed is to use an optical encoder module. The encoder consists of a light source (LED) and an array of photodetectors, separated from each other by a slotted disc known as a code wheel.
  • The PIC excels in applications for which size and power consumption are critical. Being able to drop a tiny computer system in to a design is a great bonus, and it is dial for battery-powered applications, since it can (almost) run off the field of a stray electron.
  • For many simple digital applications, a small microprocessor is a better choice than discrete logic, because it is able to execute software. It is therefore able to perform certain tasks with much less hardware complexity.
  • The AVR processors (and PICs too) included an internal circuit known as a brownout detector (BOD). This detects minor fluctuations on the processor's power supply that may corrupt its operation, and if such a lucutuation is detected, it generates a rest and restarts the processor.
  • Any sort of mechanical switch acts as a little inductor when pressed. The result is a rapid ringing oscillation on the signal line that quickly decays away.
  • A memory cycle is defined as the period of time it takes for a processor to initiate an access to memory (or peripheral), perform the transfer, and terminate the access.
  • Timing is probably the most critical aspect of computer design.
  • In all practical memory-management systems, words of memory are grouped together to form pages, and an address can be considered to consist of a page number and the number of a word within that page. The MMU translates the logical page to a physical page, while the word number is left unchanged. In practice, the overall address is just a concentration of the page number and the word number.
  • The MMU contains a translation table, which remaps the input address to different output addresses. To change the translation table, the processor must be able to access the MMU.
  • Digital Signal Processors (DSPs) are special-purpose processors designed for executing mathematically intensive algorithms.
  • The basic purpose of a DSP is to rapidly read in some data, perform a complex algorithm on it, and then move out the results. Manay DSPs have dual data spaces, known as X and Y. THey are able to access both data spaces simultaneously, retrieving two operands at once for processing.

No comments:

Post a Comment