Embedded System: Single-chip Microcomputer (, MCUs) z Embedded Systems are specialized or dedicated computers used to control appliances, devices and machines z Platforms that use embedded systems include consumer appliances, IT devices and industrial/commercial machines z Consumer: PDAs, game consoles, set top boxes, automotive control systems, home appliances z IT: Printers, copiers, faxes, teller machines, telecom switches and routers, modems, videoconferencing, disk controllers z Industrial/commercial: robotics, data acquisition, manufacturing control, process control, medical imaging and monitoring, aerospace, satellite systems, radar systems

Steer-by-wire: a next-generation steering system in which there is no mechanical link between the vehicle's steering wheel and the front-wheel directional actuator. A “steer-by-wire” system has only electrical signal connection between the steering wheel sub-system and the steering power sub-systems. This approach has both advantages and disadvantages compared to conventional steering systems. Steer-by-wire advantages: - Modular steering sub-system design, simplifies the assembly, lower manufacturing cost - Software customizable to fit different machine needs - The injury risk caused by the steering column being thrust toward the driver in an accident will be diminished. - Interference with the driver during stability control and automatic steering can be avoided. The main disadvantage of SBW system: there is no direct mechanical feedback to the operator about the steering conditions, which must be emulated by an active control system.

Other automobile applications include:

• entertainment system • theft deterrent systems • climate control • dashboard display • traction control • navigation systems

Electronic components and software will, to a large extent, shape tomorrow‘s vehicles (90% of vehicle innovations).

Smart Kitchen z 1/3 of European consumers want technology to make home life easier and more fun z Two most desired smart products: - One-button washing machine - Intelligent oven z Consumers want technology to: - Reduce environmental waste - Save energy costs

Smart Technology in the kitchen

Smart tags play a crucial role, with every item of foodstuff identified through a tag. The system enables the kitchen's PC to recognise food as you take it out of the fridge or larder. The tags are used to supply information through which the smart kitchen can look up recipes from a centrally stored database, offering instructions through a display that is embedded in the counter or through a text-to- speech system. Other uses for the tags include providing packets that can deliver information to ovens or microwaves about cooking times, to bread maker to prepare bread and cake mixes according to the package instructions.

Smart refrigerators can automatically replenish their stock. Bread Maker starts at a certain time of day, making it possible to wake up to freshly baked bread every morning! And network-enabled appliances to simplify kitchen and meal preparation tasks.

Online Gaming

z Online gaming set to become a significant part of the total games market z Console-based online gaming passed PC-based online gaming in 2003-2004

A Typical : Global positioning system (GPS):

Growth of Embedded Devices

Embedded devices will be pervasive. On average, 3 embedded devices/person on the planet by 2011. As the following figure shows, the cumulative annual growth rate is 10.3%.

What will be embedded? z Everything that is Now Electro-Mechanical, Machines (Nano-Machines) z Anything that communicates z Lots of stuff in our cars z Our Bodies: Pacemakers, De-Fibrillators, Insulin Dispensers z All sorts of interfaces, analog, speech, DNI (digital network interface), etc.

Computers are, and will be, everywhere. The world itself is becoming more intelligent. Our infrastructure will have major software content and most of our access to information will be through embedded systems. Economics will inexorably drive deployment of more embedded systems. EVERY technology-driven and manufacturing business will need to become good at embedded system. The Internet is obviously another important factor in this trend

Micro-controllers

Micro-controllers includes CPU, ROM, RAM. It also integrates other peripherals such as timers, graphic displays, PWM, digital I/O, ADC, DAC, etc. as well as buses for communication: Ethernet, Firewire, USB, PCI etc.

The goal is to have the whole system on chip (SoC) and no external hardware, i.e. to fit the application “perfectly” z CPU Bitwidths: 4 to 64 bits – Most common: 8 bit (4G units) , with 32-bit CPU growing fastest z Frequency: DC to 2 GHz (sometime the clock is run down to DC to save power) z Memory on chip: From 0.5 kB to 5 MB z Power: mW (and up)

Example: Atmel AT91M42800A Example: Microchip PIC 12CE674

z ARM7TDMI 32-bit core z Memory arch: Harvard z Static design: 0 to 33 Mhz z Program memory: 2048 x 14 z Memory (OTP/Flash) – 8 kB SRAM on chip z EEPROM: 16 – External memory interface, 8/16 bit z RAM: 128 bytes interface z ADC channels: 4 (8 bits) z Devices: 6 timers, 2 serial ports z I/O ports: 6 z JTAG debug interface z Timers: One 8-bit, One WDT z About 0.5 W power (watchdog timer) z About $18 USD z Clock: onchip crystal, 10MHz z 144 Pin package z Package: 8 pins (Pentium 4: 700 pins) z One of 13 AT91variants z Cost: <$1.00 (Pentium 4:>$200.00)

JTAG started as a method of testing ICs. Eventually, the uses of JTAG expanded to include things like debugging software for embedded microcontrollers, thus reducing the need for in-circuit emulators.

Common microcontrollers: , Motorola 68hc11, or Microchip PIC ƒ a full set of development tools ƒ at the price you can afford, ƒ and good documentation. Good for hobbyists.

Intel 8051 and 8096 Family

ƒ 8051: 8-bit math and control applications 8096: 16-bit high speed/high performance applications ƒ Piles of software, both commercial and free, are available for the 8051 line. ƒ Many manufacturers supply what must be a hundred different variants of this chip for any requirement. ƒ Includes ROM, RAM, I/O on a single chip, in addition to the processor Hardware features of 8051

- 64 KB Program memory address space - 64 KB Data memory address space - 4 KB on-chip ROM, 128 bytes of on-chip RAM - 12 MHz clock rate - serial I/O interface - Two 16-bit timer/counter - Extensive single-bit logic processing capabilities (210 bit-addressable locations)

The 8051-family includes the ROM-less 8031, 8751 which has on-chip EPROM. Many other variations. Siemens’ 80515 is a superset of 8051 that includes additional timers, ports, and RAM along with an A/D converter. The 8052/8032 are enhanced version of 8051/8031, with additional on-chip RAM and an additional timer with powerful features.

Hardware features of 8096

- Fast arithmetic capabilities (6.25 us Multiply and Divide) - High speed I/O (perform function relative to the timers without CPU intervention) - Pulse-width Modulated Output - 10-Bit A/D Converter with S/H - Maximum clock rate: 12MHz

The 8096-family includes the 8796 (8 KB on-chip EPROM), 87196 (16 KB on-chip EPROM).

The 8096 is designed for applications such as closed-loop servo control that requires high-speed I/O and computation capability. The PWM output is generated with no software intervention. This provides an effective motor speed control with very little software or hardware overhead.

Development Processes

Macro-assemblers (ASM-51, ASM-86, ASM-96) - language translators that produce relocatable object modules

Linkers (RL-51, Link86/Loc86, RL-96) - link all the various object modules together - assign absolute addresses to segments

Object to Hexadecimal converter (OH utility) - converts object code to standard HEX format that can be read by most EPROM programmers. - Burn your EPROM, pluck into your circuit and start up…

Simulation − Instead of running a program in the actual MCU, you can run it using a computer program (such as on your PC) that simulates the CPU. − Can freely modify your program, examine and modify registers and data, set breakpoints. − However it only tests software. Critical time relationship between the program and the external hardware not tested

In-circuit emulation - this involves a board that simulates the or - able to see what’s happening in the various registers, etc. - need a special card for each kind of processor: expensive!

Note:

• The programmers in the Lab can programme the following devices: Eproms (27xxx), EEPROMS (28xxx), microcontrollers (87xx), Proms, PLDs , FPGAs etc.. The lab only has the 48pins DIP adaptors. • The lab has the Emily51 simulator and the V'NICE52 emulator. Both are for the 8051 and 8052 families of processors (including 8031 and 8032). • Previous year students used the Atmel 8952 chip (some pieces left in the lab), which is compatible with the industry standard 80C51 and 80C52 instruction set and pin-out. SURVEY OF OTHER FAMILIES

TABLE 15.3 SOME MANUFACTURERS OF 8-BIT MICROCONTROLLERS

Manufacturer Web Site

Advanced Micro Devices http://www.amd.com/ California Micro Devices http://www.calmicro.com/ Dallas Semiconductor Group http://www.dalsemi.com/ Fujitsu Microelectronics, Inc. http://www.fujitsu.com/ Harris Semiconductor http://www.semi.harris.com/ America, Inc. http://www.hitachi.com/ Intel Corp. http://www.intel.com/ Mitsubishi Electric http://www.mitusbishi.com/ Motorola, Inc. http://www.mot.com/ National Semiconductor Corp. http://www.national.com/ NEC Electronics, Inc. http://www.nec.com/ Oki Semiconductors, Inc. http://www.oki.com/ Philips Components http://www.philips.com/ Rockwell International http://www.rockwell.com/ SGS-Thompson Microelectronics, Inc http://www.st.com/ Siemens Components, Inc. http://www.siemens.com/ Signetics Corp. http://www.signetics.co.kr/ Texas Instruments http://www.ti.com/ Toshiba America http://www.toshiba.com/ Zilog,Inc. http://www.zilog.com/

Look out for the annual edition of the EDN microprocessor directory. This directory is an invaluable aid for designers. The latest: Aug 2004 Vol 49, issue 16.

• Zilog - taken an application-specific approach. Their core 8-bit MCU is the Z8. • The Z86CXXCCP (Consumer Control Processor) family is designed especially for automotive and consumer applications. The family is based on a Z8 CPU core. The MCUs can be powered from 2.5 to 5.5V. An example is the Z86C27, a digital TV controller. This IC controls all the functions necessary for a digital color TV set. It provides the necessary analog outputs, such as volume and brightness control by using PWM outputs. External low-pass filters convert the PWM outputs to analog signals.

• Texas Instruments offers the TMS370 family, which has found much use in automotive applications. ‰ The Programmable Acquisition and Control Timer(PACT) module executes the timing functions. The PACT can provide eight PWM outputs and six input captures. ‰ The A/D subsystem can select one of the eight input channels as a high-reference voltage. ‰ The TMS370 family also includes a built-in EEPROM. It has two power saving modes and a watchdog timer. ‰ The memory subsystem reserves 256 RAM bytes for use as general- purpose registers. The instruction set has 14 addressing modes.

• NEC supplies the μCOM- series with a minimum instruction cycle of 333ns. To achieve this, an MCU uses a fetch and prefetch function. It can also transfer data between memory and peripherals using a dedicated channel.

• Hitachi offers the H8/300 family based on an 8/16-bit core. It has a register file set up to have sixteen 8-bit words. The processor can use any register as an accumulator. This allows easier use of the C language. The H8/310 is useful for security-sensitive application because of its 8- kilobyte EEPROM. Servomotor control applications would use the H8/350 because of its A/Ds, D/As, and a waveform generator.

• Mitsubishi offers the series 740, which includes PWM outputs, LCD drivers, VFF drivers, and 3-V battery operation. One family member, the M37450, can handle 15 interrupts and has stepper motor control.

• Dallas Semiconductor supplies the DS5000 soft microcontroller series which is built on an 8051 core. This series features a built-in lithium battery to provide nonvolatile registers and RAM. The MCU has automatic power down. It resumes operation gracefully when power returns. Note that this is not a reset, which starts execution from the beginning. Although attractive for power critical applications, these MCUs cost more than others.

• SGS-Thompson offers the ST6 family, which is based on an MC6804 core. Inputs are programmable for CMOS or TTL levels. SGS-Thompson also offers the ST-9 family, which is based on a Z80 core. It features a multichannel DMA. To reduce noise problems, an MCU can shut down high-current outputs when they are not being used.

• National Semiconductor’s COP800 family emphasizes industrial ruggedness. The MCUs are more resistant to CMOS latch-up. They also have an electrostatic discharge immunity exceeding 2kV.

• Siemens, Philips, and Signetics offer families based on the 8051 core. Philips has the most feature-rich collection of 8051-based microcontrollers of any vendor. Atmel versions of the 8051 use EEPROM technology for control store and nonvolatile data storage, which makes the 8051 useful for education and hobbyists to experiment with.

CHOOSING A MICROCONTROLLER

Costs. MCU manufacturers compete fiercely to sell their products. The following will give you an idea of the competition. If an OEM (Original Equipment Manufacturer) intends to develop a product to be sold in high volumes, a price difference of 10 cents per MCU is significant. As a result, software support is a significant factor. For instance, what emulators, simulators, assemblers, and compilers are available? To reduce writing new software, OEM companies tend to use MCUs belonging to the same family whenever possible.

Analyzing the application. Before choosing an MCU, you will have to analyze the requirements of the applications. Generally, you will have to look at the data processing, I/O, power consumption, and memory requirements.

Data Processing. For data processing, the processor must be able to perform critical calculations. These are calculations that must be completed within a time limit. If the application is engine control, the MCU must calculate when to fire the spark and send the signal before the piston reaches the firing position. In this case you have to be sure that the CPU instruction set is fast and powerful enough. Another consideration is the precision and range of data to be processed. This determines the bit size of the data. In an antenna positioning system, it may only be necessary to rotate the antenna in one-degree increments. Then, for full rotation, only 180 points are required. Hence 8-bit data is sufficient to specify antenna position. Now, consider a robot whose arm must be positioned within a few seconds of . Sixteen-bit data can represent increments of 20 seconds of arc. For very high resolutions (fractions of seconds of arc), it will be necessary to use floating-point. One question is whether to use an MCU with 16-or 32-bit instructions. The alternative is to use subroutines for 16- or 32- bit math using an 8-bit MCU. If most of the calculations are low resolution, it may be better to use subroutines to perform the higher-resolution calculations. This is cheaper than using floating-point hardware.

I/O. To determine I/O requirements, you will need to identify the quantity, amount, and type of signals. Also, you should consider the mechanical needs of the system to be controlled.

Some designs use a main processor to offload some tasks to other processors, e.g. a serially linked network of a 68HC11 with four or five 68HC05 may be cheaper than one 16-bit CPU.

Power. Some OEM products are powered by battery. The security system in an automobile is one example. It must function when the car is not being used. The MCU can run in low-power mode to minimize current drain from the car battery. When an intruder breaks into the car, he or she activates a sensor that wakes up the MCU to switch it to normal mode. Then the MCU executes the appropriate alarm sequence. To conserve battery power, most MCUs include low-power modes of some kind. Even some general-purpose offer this feature. They have it because it is necessary to conserve power in portable (laptop or notebook) computers.

Memory. When considering an application’s memory requirements, break it down into program and data memory. This categorizes it into nonvolatile (ROM, EPROM, OTP(one-time programmable)) and volatile (RAM) components. There is a hybrid category of customization. This would be nonvolatile or rarely modified data that is specific to a piece of equipment, such as serial number, calibration, and maintenance history. An EEPROM is a good candidate for this kind. Newer technologies, such as , may allow other economic options.

Flash memory is a non-volatile memory device that retains its data when the power is removed. The device is similar to EPROM with the exception that it can be electrically erased, whereas an EPROM must be exposed to ultra-violet light to erase. Flash memory does not need a constant power supply to retain its data and it offers extremely fast access times, low power consumption, and relative immunity to severe shock or vibration. These qualities combined with its compact size, make it perfect for portable devices like scanners digital cameras, cell phones, pagers, handhelds and printers. Flash chips have a lifespan limited to 100,000 write cycles, which means flash will never replace main memory in computers.

The volume of product expected to be sold determines what kind of program memory to select. In any case, and EPROM-based MCU is best suited for the product prototype. When the product is completely designed and produced, the production model may use a different kind of program memory. In order of small to large volumes, the choices are EPROM, OTP, and ROM. Careful economic analysis will decide which to use in any application. It is a speculative decision because the OEM has to forecast how many products will be sold. To determine the size of memory, you can initially write a first-pass pseudocode for the application. This will give you an idea of the memory requirements. Still, this is a difficult estimate to make, and past experience may be the only guide. You will also need to estimate RAM space for variables, stack size, and scratchpad area for intermediate result of calculations. Some application software writers estimate RAM requirements by taking a percent of their estimated ROM (program memory) requirement. The language chosen will also be a factor. Assembly language may require 12 or more times as much ROM as RAM. A high-level language may require about 20 times as much ROM as RAM.

What Bit Size? MCUs are available in 4-, 8-, 16- and 32- bit types. When developing and MCU system, one factor in keeping the cost down is the bit size of the MCU. Those with a smaller bit size are cheaper per chip and require less expensive development tools and support chips. On the other hand, it is necessary for the MCU to be able to perform the necessary tasks. For this reason it may be necessary to use an MCU with a larger bit size. To make the decision, it is necessary to analyze the application as described previously. Still we will risk the following generalizations. Note that there are exceptions. Use 4-bit MCUs when cost is the main consideration (for example, an electronic thermostat). Use 8-bit MCUs in applications that involve movement of date (for example, a computer disk drive). We will say more about I/O throughput later. Other reasons are 16-bit math and better features for C programming. Use 32-bit MCUs when a very large addressing space is required (for example, a laser printer). In fact, some laser printers use two of them.

I/O Throughput. This refers to how fast I/O requests from external devices can be handled. Another term is I/O bandwidth. When too much of the processor’s time is spent handling I/O, we call the situation an I/O bottleneck. An I/O bottleneck will prevent an MCU from executing other tasks. Most real-time control systems rely on interrupts to handle I/O. When many I/O subsystems are being used, multiple interrupt requests can occur. This may increase latency times beyond what is acceptable in the application. This is an I/O bottleneck. For instance, in an automobile engine control system, the MCU spends much of its time monitoring crankshaft revolution and generating spark timing pulses, which is time-critical.

To minimize the possibility of an I/O bottleneck, the designer can choose a 16-bit MCU. Some 16-bit MCUs have reserved registers for use by the interrupt service routine. This eliminates the overhead in saving other register values onto the stack. It is also not necessary to restore the registers after completion of the service routine.

PC Compatible Controller. Computers based on the 80386, 80486, or Pentium microprocessor are very popular. You may want to use a control system that can also run personal computer (PC) software. There are several third-party suppliers, such as National Instruments, who offer software to interact with popular data acquisition boards and instrumentation. At the time of writing, Intel plans to introduce an embedded controller version of its 80386 microprocessor, the Intel 386EX. It will be a fully static chip (can run at any speed up to its maximum) running on 3V. The embedded controller will have an intermodule bus with power management circuits. This controller will be able to run PC software such as Windows and its applications. This means that it will be relatively easy to build systems with graphical user interfaces. Visual programming environments such as Visual Basic can make this easier. Another advantage will be the capability to reuse existing software. This is a big plus since software development is very expensive.

WATCHDOG TIMER Embedded systems may be subject to all sorts of EMI, ESD, RFI, power spikes, brownouts, shorts on I/O pins, and general abuse. This can lead to unexpected failure modes in both hardware and software. For example, assume a single bit is corrupted in the CPU’s status register by EMI generated from a nearby ESD event. Perhaps a subsequent test of that bit will cause an errant branch in the kernel or application.

An equally likely scenario is that of a single corrupt bit in the program counter. The CPU will begin to fetch instructions out of the sequence intended and the application framework will become unrecoverably corrupt.

WHAT IS A WATCHDOG TIMER? A watchdog circuit in its simplest form is just a counter. When an overflow happens, the watchdog asserts the system RESET line and the controller resets. Under normal operation, the code running in the controller will periodically clear the watchdog counter (hit the watchdog) so that it will not overflow. When the controller enters an infinite loop, or gets lost executing an unintended sequence of instructions, the controller will fail to hit the watchdog. After a while, the watchdog will overflow and reset the controller. And the controller will shortly be back on duty, running properly. A common method for implementing watchdogs now is to select the system’s microcontroller or microprocessor that already has an integrated watchdog on the same dice. HANDLING WATCHDOGS IN SOFTWARE A commonly touted principle says, "for reliability, systems should be made as simple as possible." At first glance, this appears to imply that the application should talk to the watchdog hardware directly. However, on closer examination, we will see that this is exactly the wrong approach for system reliability. For the sake of our discussion, hitwd () will be the simplest function possible to hit and reset the watchdog. Typically, applications that talk to the hardware watchdog directly have calls to hitwd () sprinkled throughout the code. It’s easy for programmers to lose sight of the watchdog’s intended function and only be concerned about hitting the watchdog often enough to keep the system from resetting. Now, when the system is subjected to EMI, ESD, or power upsets, the contents of CPU registers, RAM, EEPROM, flash memory, and EPROM can become unpredictably corrupt. These events don’t usually cause the CPU to stop executing code. Most often the CPU continues to execute the code, but with out-of-sequence or unintended instructions. Another common failure mode is for the CPU to execute properly sequenced instructions but operate on corrupt data, say from an upset PIO. If the application is calling hitwd () frequently, the watchdog reset may never trip. We need to check the integrity of the system’s application before hitting the watchdog. People often consider it a bad idea to hit a watchdog in an ISR. In this situation, the main application may fail, but a periodic interrupt may still cause the ISR to reset the watchdog. Thus the embedded system crashes, but the watchdog doesn’t reset the system as long as the periodic interrupt is still functioning. However, this situation only occurs if the ISR doesn’t perform an adequate sanity check on the application(s), which can be accomplished by setting up virtual or software watchdogs. To do so, we make use of a virtual watchdog. A virtual watchdog is simply a software counter that the application increments and the ISR decrements. If the virtual watchdog reaches zero, the ISR determines that the main application is not functioning properly, then the ISR disables interrupts and enters an infinite loop to wait for the hardware watchdog to reset the processor. On the other hand, if the software watchdogs indicate that applications are running properly, the ISR resets the hardware watchdog. A single virtual watchdog is no more effective than simply scattering hitwd () calls throughout the code. However if an array of virtual timers is set up, the ISR then has to check on multiple points in the main application. If multiple tasks are running concurrently, an array of virtual watchdogs can be used to verify the sanity of each task. If any task fails, the ISR can determine if the hardware watchdog should be tripped or if the kernel should be notified of the failed task so that the kernel can deal with the errant task. An array of virtual watchdogs is much less likely to be properly serviced by a corrupt application framework than code with multiple direct accesses to the watchdog hardware. Therefore, the overall system reliability is enhanced. An addition to software watchdogs, the ISR can perform a sanity check on the stack pointer(s). One common symptom of a rampaging CPU is a corrupt or overflowed stack. It’s a good practice to bound-check the stack pointers before hitting the hardware watchdog in an ISR. Depending on the specific application, other system checks may be made by the ISR—for example, checking the status of critical I/O or doing a CRC in data in SRAM. There are two ways an errant CPU can execute instructions from the ISR. One is for the errant CPU to execute instructions while linearly approaching the ISR code. The second is for the errant CPU to branch the execution path into the middle of the ISR code. There are two safeguards that should be used to prevent this from happening. First, the instructions immediately before the ISR should be an infinite loop. If a rampaging CPU linearly approaches the ISR, the infinite loop will execute and the CPU will hang. Eventually, the ISR will see that the virtual watchdogs are not being serviced, and the hardware watchdog will reset the system. The second safeguard mitigates the problem of a rampaging CPU jumping into the middle of the ISR and incorrectly hitting the watchdog. To complete this safeguard, a mechanism must be in place for the ISR to do a sanity check on itself. The first instructions in the ISR should fill a fixed memory location with a sentinel value. Just before the ISR hits the watchdog, the memory location is checked for the proper sentinel value. If this sentinel value is not found, the watchdog is not hit. The last thing the ISR should do is clear the ISR’s memory location, lest the sentinel value remain. CONCLUSION The idea is to only hit the watchdog in a single place in the code and then jealously guard that small piece of code. If the application doesn’t jump through all the right hoops or if the stack, data structures, or I/O appears to be corrupt, the watchdog is not hit.

Input Capture Functions (available in 8032/8052, 6811)

- records the time (TCNT value) when an active transition occurred. - transition can be rising, falling, or either. - useful for applications that require measuring the time between edges. - can calculate period, frequency, or other related quantity, such as speed. - can measure pulse width by capturing the 1st edge and then the 2nd edge.

Automobiles have many uses for timer input captures. The traveling speed of the automobile is measured by sensors attached to the wheels. This can be used by the MCU for cruise control (maintain constant speed). It can also warn drivers who tend to have a heavy foot to slow down. An antiskid braking system is another automobile example. The system senses wheel rotation to determine the braking pressure to apply.

Other applications are turbine flowmeters. They use spinning turbines to measure fluid flow. A similar device is a propeller airspeed sensor. The MCU measures flow rate by measuring the frequency of the sensor pulses. It can also keep track of total flow by counting the pulses since each pulse represents a unit of fluid.

The input capture functions can also serve as general-purpose edge-sensitive inputs. This is useful because they can be programmed for any type of edge. For example, two input captures can be used to sense the data available (DAV) input of an IEEE-488 interface. One is configured to react to a rising edge, the other for a falling edge. In this case the captured time information is not required. Figure. Input Capture Sequence

Sequence of Operations

The 68HC11A8 and other A-type versions have three capture pins—IC1, IC2,and IC3—at port A pins 2, 1,and 0, respectively.

As specified by timer control register 2 (TCTL2), an input capture can react to a rising, falling, or either type of edge. It can also be disabled altogether. When an edge is detected by the input capture pin, the value of the timer counter register (TCNT) is latched into the corresponding input capture register (TICx). The function also sets the input capture flag (ICxF) in timer flag register 1 (TFLG1). If the corresponding input capture interrupt enable bit (ICxI) in timer mask register 1 (TMSK1) is set, the detected edge also generates an interrupt. The Figure above shows this as a logical AND operation.

Typically, the application program reads the value in the timer input capture register (TICx). Then it clears flag ICxF so as to rearm itself to capture the next edge. To detect whether a flag is set, the program can poll register TFLG1 or respond to an interrupt.

Pulse Width Example

We will consider the example of measuring the width (time duration) of a high pulse using pin ICI. First we will show the pseudocode to illustrate the basic algorithm (Listing below).

Figure. Optoelectronic Position/Motion Detection

*Listing *Pseudocode to measure pulse width of high pulse Configure: capture on rising edge Clear capture flag Wait_for_rise If flag == 1, then rise_time = capture time Else repeat wait_for_rise Configure: capture on falling edge Clear capture flag Wait_for_fall If flag == 1, then fall_time = capture time Else repeat wait_for_fall Pulse_width = fall_time-rise_time

There are limitations. If the pulse is too short, the second edge occurs before the software can capture it. One way to remedy this is to use two input capture functions. One is configured for a rising edge and the other is configured for a falling edge. If the pulse is longer than 65,536 TCNT cycles, overflow will give erroneous results. The program will have to count how many times the timer overflow bit (bit TOF in register TFLG2) has set.

Motion Detection

Other situations require that only motion is detected. This is the case for an antiskid braking system. To prevent skidding it is necessary to prevent any of the wheels from locking up. If any of the wheels stop turning while the brake pedal is pressed, the system adjusts the braking pressure to compensate. A wheel is considered to have stopped rotating when a time limit expires before the next edge is detected. Motion detection can also be used to prevent wheel slippage such as in a locomotive. The rotary speed of the wheels should match that required for the locomotive’s true speed.

Pulse Accumulator

The pulse accumulator is an 8-bit counter that can count input edges or measure pulse width depending on the operating modes used. Some typical pulse counting applications are monitoring tape position in a VCR or automobile odometer, and monitoring total volume of fluid flowing through a flowmeter. The pulse accumulator can identify a wide pulse from a narrow pulse much more easily. This makes it useful for decoding signals that use pulse width as part of its code.

Gated Time Accumulation mode

In this mode the pulse accumulator counts up once every 64 clock cycles when its input pin (PAI) is at the active level. It does not count edges. The next Figure illustrates this mode of operation. Setting the pulse accumulator mode bit (PEDGE) specifies the input that will inhibit time accumulation. For example, If PEDGE is 0, the counter will not increment as long as input PAI is low. When PAI is high, it increments once every 64 clock (E) cycles. If PAI changes level, it continues counting from where it left off once input returns to the enabling level again.

Pulse-Width Discriminator.

A common use for the aforementioned mode is to discriminate a wide pulse from a narrow pulse. This is done by writing a value to counter PACNT that is halfway between the values of the narrow and wide pulse widths. When a narrow pulse arrives, the counter accumulates and the trailing edge is detected before an overflow occurs. When a wide pulse arrives, the counter accumulates and overflows before the trailing edge is detected. Thus if the edge flag (PEDGE) sets first, the pulse was narrow. If the overflow flag (PAOVF) set first, the pulse was wide. Figure. Pulse Accumulator in Gated-Time Accumulation Mode

Application specific integrated/standard processor (ASIP/ASSP)

Application specific integrated/standard processors are domain specific accelerators, targeting a particular niche market. They are more targeted than microcontrollers, and are usually more upscale and higher performance. Often they have 32 bit processors, multiprocessors, and expensive peripherals.

Example: Motorola PowerQUICC III

Target market z Communications z Third generation (3G) z mobile network

Processing z PowerPC e500 z 666-1000 Mhz z 256 kB cache

Networking z CPM module, RISC-based microcode

About 160 USD

Example: Infineon C167CS

Target Market z Automotive control

Processing z 16-bit C16x core z 4-stage simple pipeline z 40 Mhz operation z 16 MB memory space, including ROM, RAM,

144 pin package z Tolerates -40 C to +125 C

About 25 USD

DIGITAL SIGNAL PROCESSORS

A digital signal processor (DSP) is a specialized processor. It is designed to execute arithmetic instructions faster than can a general-purpose processor. A DSP application is more math intensive. Their programs use a higher proportion of arithmetic instructions compared to data moving and I/O instructions. The following provides a brief introduction to DSPs since more control systems are using them. This will give you an idea as to what they are and what they can do. Also, it will show you a limitation of general- purpose microcontrollers such as the 68HC11.

Typically, a DSP samples analog inputs after being passed through a low- pass filter. Then they calculate new outputs, which in turn may be sent to D/A converters. It must do this at high speeds. For this reason they are designed to execute arithmetic instructions quickly. The main arithmetic operations is the multiply and accumulate. Soon we shall see why this is important.

DSP applications include machine vision used for parts identification in a factory, position control of robot arms, and detection of telephone tone signals. Common DSP calculations are PIC control loops, digital filters, and fast Fourier transforms (FFTs).

Matrix Multiplication. Equation (*) shows the calculations required for each matrix C element when matrices A and B are multiplied. Equation (+) shows an alternative expression. c ij = a i 1 b 1 j + a i 2 b 2 j + " + a in b nj (*) n (+) c ij = ∑ a ik b kj k = 1 where i = row index j = number of columns in matrix A = number of rows in matrix B aij = element of matrix A, the multiplier bkj = element of matrix B, the multiplicand cij = element of matrix C, an accumulated sum of products

Many graphic processors manipulate the picture elements (pixels) using matrix multiplication. Typical operations for graphic objects on a screen are scaling (expanding and shrinking), rotating, moving, and overlapping with other objects.

An audio example: the following figure illustrates the basic audio effects that can be implemented digitally:

Figure —Here you can see the basic audio effects— delay, echo, chorus, and reverberation.

All the effects can be accomplished with a variation of this algorithm: get the most recent ADC result, store it, retrieve an older result, multiply it by some gain value M (if needed), add the results together (if needed), and send the result to the DAC. Although it sounds like the multiplication by some gain value M is designed to increase the signal level, the intent is really to reduce its amplitude. Therefore, M is generally much smaller than 1. If allowed to be larger than 1, the maximum value may be 1.5 or 2 but not much larger. If M is greater than or equal to 1 in the case of reverb, positive feedback is present, and the ADC values keep getting larger and larger until digital saturation results. At a minimum, the ADC conversion rate must be 32 kHz and provide a resolution of 16 bits. I don’t believe that any lower conversion rate or resolution will provide adequate quality. As a side note, most commercial effects units use 44.1- or 48-kHz ADCs with resolutions of 20 bits or higher.

I think M should probably be at least four bits (providing 16 different volume levels). Six bits would be better (64 levels), but it should not be necessary for M to be larger than eight bits. Unfortunately, human hearing is not linear, and a simple approach to M is not adequate. For example, many volume controls change in increments of 1 or 0.5 dB. But, if M is changed from 1 to 2, then the signal level doubles, which is a 6-dB increment.

For simplicity, I will assume that M will be 8 bits and provides a possible range of 0 to 255. However, some settings may not be allowed. I will also limit M to provide gains of less than one. The Table below shows the major values of M and associated volume levels.

Value of M Multiplier Volume (dB relative to original)

255 0.996 –0

128 0.500 –6

64 0.250 –12

32 0.125 –18

16 0.063 –24

8 0.031 –30

4 0.016 –36

2 0.008 –42

1 0.004 –48

0 0.000 –Infinity

Table —Here you can see the values for M and volume levels.

So, how much storage is needed? Common delay times that are used in commercial guitar multi- effects processors seems to be in the 100-ms range, at the most. I’ll assume an absolute worst- case delay time of 250-ms, just to be conservative. For 250 ms of storage, a 32-kHz conversion rate, and 16-bit ADC results, 16 KB of storage is needed.

Multiply and Accumulate Operations. Equations (*) illustrates the fundamental DSP operation, multiply and accumulate. Elements aik and bkj are multiplied and added to form element cij. A MCU such as the 68HC11 would take a long time to perform many multiply and accumulate operation. (The best that can be done for multiplying 2 numbers together for a microprocessor lacking a built-in multiplier is about 200 instructions.) The 68HC11 could only do real-time DSP operations for very low-frequency signals. Thus it makes more sense to use a DSP chip for signal processing.

To illustrate a chip with a built-in DSP, we use the 68HC16. This is a Motorola microcontroller with more processing capability. It can execute 68HC11 programs as well as make use of its expanded instruction set. In other words, the 68HC16 is source code upwardly compatible with the 68HC11. It has instructions and associated internal hardware for DSP capability.

Multiply and Accumulate Using the 68HC16. The 68HC16 has extra registers, some of which are dedicated to multiply and accumulate operations. The H register is a 16-bit multiplier register. The I register is a 16-bit multiplicand register. Register AM (the MAC accumulator) is a 36-bit multiply and accumulate register. The 68HC16 has several extra instructions, including MAC (multiply and accumulate) and RMAC (repeat MAC).

The MAC instruction multiplies the contents of registers H and I and adds the product to register AM. After this, it loads registers H and I with the next elements to be multiplied. The RMAC instruction repeats MAC the number of times specified by the contents of register E, another new 16-bit register. The 68HC16 can run with a maximum clock of 16.78 MHz. Like other DSPs, its main speed improvement is the reduction of clock cycles required to execute a multiply and accumulate. It executes MAC in 12 cycles. RMAC requires six cycles plus 12 cycles for every time it executes a MAC. Even so, this is still modest performance by DSP standards. The DSP56000 can do 24-bit multiply, 56-bit accumulate, and load data for the next operation during one clock cycle at 33MHz.

SOME RECENT TRENDS

1. Low End

One of the more dramatic changes for the 8-bit community is the level of integration that parts have obtained. The Sharp (www. sharpsma.com) LZ87010 is a case in point. The device uses the 8051 processor as a foundation, an architecture introduced more than 20 years ago. The core processor is almost dwarfed, however, by all the additional functions included on-- chip. As shown in the figure, the processor contains blocks of RAM, eight timer and I/O ports, AID and dual D/A converters, Flash memory, and a debug interface. This level of complexity is now relatively easy to achieve, adding considerably to the functional level of these older architectures. Vendors are producing devices with a range of peripheral offerings, sometimes broad-based, sometimes targeted at a narrow market niche (See Application-Specific Microcontrollers).

Not all 8-bit devices are embracing the complexity trend, however. Some are aiming at being as basic as possible, squeezing into small packages to keep costs down. The PIC12 family from Microchip (www.microchip.com) falls into this category, packing the processor, memory, a timer, and an ADC into an 8-pin package. Flash Shifts Design Low-cost Flash memory has increased the amount of memory a processor has on-board as well as shifted the memory mix being used in high volume production. Flash has started to ease ROM-based and one-time programmable (OTP) versions into the background. The ROM based units are still the lowest-cost option in high volume, but the flexibility that Flash offers is gaining converts. Further, the lowering cost of Flash is shifting the break-even price point for mask programming to greater numbers of units.

The movement to Flash also provides an opportunity for vendors to differentiate their processors through software. Companies, such as Philips (www.philips.com), are providing chips pre-programmed with application-specific software. Because the programming is in Flash, users can alter the programming to suit their specific situation and Philips can use the same basic part to meet a variety of application needs. Both parties win. Regardless of the growing appeal of 32-bit architectures, then, the 8-bit processors are going strong. They provide a wide range of alternatives: general to application-- specific, simple to highly complex, and package sizes from 8-pin to 40-- pin and greater. 2. High End Throughout the history of embedded processing there has been a steady progression in processor size from 4-- bits to 32. The industry is wavering on the next step, however. A number of devices are indeed available. PMC-Sierra (www.pmc-sierra.com), for instance, offers the RM-9000x2. Toshiba (www.toshi ba.com/taec) also offers a 64-bit device, the TMPR4955, and NEC (www.nec.com) has its VR7701. But these devices are not in the mainstream of embedded processors. They typically target the network processing niche where the word width offers performance advantages. The 64-bit width, for example, allows the processor to hold an entire Internet address packet in one word for examination and manipulation. There are also applications, such as color printers and storage area networks, where the extended memory addressing allowed by the 64-bit width is desirable. For most high-end applications, though, the cost in power and packaging to run a 64-bit embedded processor outweighs the advantages. Instead, the embedded industry has sought ways of expanding 32-bit architectures to satisfy high-end performance requirements. Speeds Climb The most straightforward approach to boosting processor performance is to increase its clock speed, and that certainly has been happening with 32-bit embedded processors. A year ago, a processor was considered high-end if its clock speed was above 400 MHz. Now, 500 MHz to 600 MHz clocks are considered the threshold, and the value keeps rising. Recent achievements in the high-clockspeed approach include Motorola's (www.motorola.com) PC7447 Power PC, clocking in at 1.3 GHz, and Intrinsity's (www.intrinsity.com) FastMIPS processor, which achieves a full 2 GHz. Vendors are also increasing 32-- bit performance by integrating a host of peripherals on- chip with the processor core (See Application-Specific Microcontrollers).

Programmable Integration In the last year or so, a new variation on the theme of highly integrated designs has appeared on the market. This variant has been called a programmable system-on-chip (PSOC). It consists of a hard-wired processor core with some hard-wired peripherals, supplemented with a substantial amount of programmable logic. These PSOCs represent an alternative to designing an ASIC around a processor core, although they typically run at clock speeds well below 500 MHz. Several companies now make these PSOCs available, each with a different processor core. For example, the Virtex II Pro from Xilinx (www.xilinix.com); Altera (www.altera.com): the Excalibur; QuickLogic (www.quick logic.com): the QuickMIPS.

3. Application Specific Microcontrollers Application specific microcontrollers have proliferated, with virtually every processor vendor offering one or more families of parts tailored for specific use. Infineon (www.infineon.com), for example, has the XC164 and XC167 families with peripherals tailored for motor control and industrial networking. Similarly, Fujitsu's (www.fujitsu.com) FR series handles industrial networking and motor control along with applications such as television remote control. Fan and motor control is a particularly popular product. Microchip (www. microchip.com), STMicroelectronics (www.stm.com), and Philips (www. philips.com) all have motor control families in their 8-bit lines. All these sophisticated controllers handle a variety of motor types, including DC, brushless DC, stepper, switched-reluctance, and AC induction motors (See the course website for online resources and tutorials on motor control in general). By incorporating DSP capability, the controller can calculate load conditions and make adjustments to the motor drive to compensate. This range of options has made motor control practical in not only high-end applications, but also mid-range consumer systems, such as washing machines, dryers, and vacuum cleaners. The performance tuning available helps prevent the need to overdesign the system, improves power efficiency, reduces vibration, and maintains speed consistency. The 8-bit processors aren't the only ones that have joined the game, though. NEC (www.nec.com) offers a 32-bit microcontroller geared for electronic metering instruments. Motorola (www.motorola.com) has a 32-bit device aimed at industrial networking. Samsung's (www.sam sung.com) 32-bit families target disk drives, digital television, and printers, among other applications.

Growing Catalogs The result of all this customization is an increasing portfolio of products, making it hard for designers to keep track of their options. The Hitachi (http://semiconductor.hitachi.com) H8 family is a case in point. Hitachi's H8 microcontrollers have evolved into eight separate families, some 8-- bit and some 16-bit, of which only one is marketed as a general-purpose device. One family targets lowpower applications needing built-in displays such as handheld meters, security devices, and home electronics. Another family includes a smartcard controller and DMA, covering applications such as CD/RW drives and printer cards. A third family adds in an LCD controller to make it suitable for PC peripherals, diagnostic monitors, and bar code scanners. The result is a product catalog of more than four hundred variations on the H8 theme. Other companies have similarly extensive product offerings. They can afford to have such diversity because the products fit into large markets and require little ongoing support. Philips, for instance, has most of its application-specific devices in the television and consumer markets. Samsung is more heavily into computer peripheral devices, while STMicroelectronics concentrates on automotive and smart-card reader applications. In general, microcontroller vendors use the cores they developed for other products to turn their generic devices into cost-effective specialty products rather than create something entirely new. This trend gives design engineers about the only clue they have for finding what specialty products are available. Designers need to look for a company that is strong in related markets, ones that have chips using functional blocks that fit the application. Then, they need to go to the company web site and start looking at its microcontroller families. The vendor's on-line catalogs are the only information source that has a chance of keeping up with the rapid proliferation of family members If no product exists that matches the application needs, designers aren't necessarily out of luck. If their application is representative of a large market, the vendors may be open to spinning out a new product.

Download from course website for an article on the exciting embedded applications in today’s car design. SOME FUTURISTIC IDEAS 1. It’s a small world High-end research is struggling with the best way to churn through mountains of data and miles of networks with huge chips. By contrast, the Smart Dust challenge is to come up with the tiniest gadget that can do something useful. Ultimately, the goal of shrinking everything (processing, sensing, communication, power) onto a single chip calls for fundamental advances that will combine the capabilities of digital, analog, optical, MEMS, and so forth in a single cubic millimeter. Envisioned applications are no less like science fiction. [1] Take, for example, the possibility of seeding forests with a layer of dust to instantly detect and pinpoint the start of a forest fire. Everything you own will have a tiny ID tag that’ll scream over the radio if it’s stolen. While the manufacturing challenges associated with the ultimate dust are overcome, there’s a lot of work that can be done in the interim. Here’s where the so-called COTS Motes come in. COTS highlights the use of commercial off-the-shelf technology. While a standard-chip solution doesn’t come close to achieving the minuscule form-factor goal of true dust, the result is nevertheless slick (and small and low-power) enough to be interesting. MOTES WENT TO BATTLE After nine months of work, a UCB team journeyed to the Marine Corps Air/Ground Combat Center in the California desert with a mission in hand: to air drop a half dozen motes to survey a road. An unmanned aerial vehicle (UAV) made the run separately using a plotted course, altitude, and drop sequence at an altitude of 150 (see Photo 3). The UAV, a BAT built by MLB Company, has a 5 wingspan, navigates with built-in GPS, has a range of 15 miles, and a top speed of 60 mph. After the motes were deployed on the ground, they independently established a time- synchronized, multi-hop RF network. Using their built-in magnetometers, the motes were able to track vehicles on the road (see Photo 4). A clever twist is that the motes fine-tune their position estimate over time as the vehicle traffic is monitored (presuming a constant vehicle velocity). Finally, the UAV made another pass, gathered the vehicle tracking information from the motes and then sent the data back to the base camp.

Photo 3—A half dozen motes were airdropped next to a road to monitor traffic. If you are interested, video of the drop is available at http://www- bsac.eecs.berkeley.edu/~pister/29Palms0103/motedrop.mpg.

Photo 4—Motes were able to detect vehicle traffic using their built-in magnetometers. The green trace is the raw sensor output. It’s signal-processed to produce the red trace with spikes, which indicate the presence of a vehicle. REFERENCES [1] K. Pister, "Sensor Networks in 2010," http://robotics.eecs.berkeley.edu/~pister//SmartDust. [2] S. Hollar, "COTS Dust," Masters Thesis, University of California, Berkeley, http://www-bsac.eecs.berkeley.edu/~shollar/shollar_thesis.pdf. [3] P. Buonadonna, J. Hill, and D. Culler, "Active Message Communication for Tiny Networked Sensors," http://tinyos.millennium.berkeley.edu/papers/ammote.pdf . [4] J. Kymissis, et al, "Parasitic Power Harvesting in Shoes," Procceding of the Second IEEE International Conference on Wearable Computing (ISWC), Institute of Electrical and Electronics Engineers, Inc., October 1998.

2. Embedded Internet There’s a lot of talk about embedded Internet being the next wave, and how wonderful it will be when we can remotely access and manage the electronic devices we use every day. However, this wonderful vision will be a long time in coming if we rely on the current direction of the industry. For example, if you want to Internet-enable your device, conventional wisdom would have you upgrade your processor, buy an expensive RTOS, add megabytes of RAM, purchase an embedded web server, and then pay huge royalties just to get an IP address on your device. By far, the majority of the devices we would like to enable will remain isolated simply because networking them would cost too much to develop, produce, and purchase. Where’s the sense in putting a Pentium in a thermostat? For the embedded Internet to become anything more than a ripple, there needs to be an appropriate solution for the millions of devices that have 8- and 16-bit MCUs.

EMIT emWare The Leading Provider of Remote Device Management Solutions www.emware.com

ATMEL Atmel and Wave Systems Corp. Partner to Provide Advanced "E-commerce on a Chip" Solution (Search for “internet transaction” or “e-commerce”).

Microchip Using PICmicro MCUs to Connect to Internet