Beruflich Dokumente
Kultur Dokumente
The term microprocessor first came into use at Intel in 1971 and, generally refers to the implementation of the central processor unit (CPU) functions of a computer in a single, large scale integrated circuit. The Intel 4004 was a four bit microprocessor and led the way to the development of the 8008 the first eight-bit microprocessor introduced in 1972. And from here the history of microprocessors starts..8080 in 74 and so on.
What Is a Microcontroller?
A microcontroller is a computer on a single chip; It contains a CPU (usually called the core) and a variety of peripherals which assist the application. By contrast a typical CPU, like the x86 in your PC, contains only the core - all peripherals, like timers and DMA controllers, are in external chips. Many microcontrollers can operate with no external components except an oscillator (a crystal or ceramic resonator) - some do not even require this, having an oscillator built in!
Almost all modern appliances include microcontrollers to support the friendliness and programmability consumers expect these days. Microcontrollers can have a very long life span - chips first offered in the late 70s are still chosen for many new designs today!
External Buses
Microcontrollers can be divided also into two major groups those with and without an external bus (EB). An external bus (offering address and data lines) enables a wide variety of peripheral chips to be connected in almost any quantity; this flexibility comes at the cost of board space, chip size, chip count, power consumption and RFI emissions.. A major advantage of EB microcontrollers for the beginner or hard-up developer is that EPROMs (in which code for EB micros is usually stored) are cheap and large in capacity; EPROM programmers and emulators are cheap and easy to use. Non-EB microcontroller, whose code is stored on-chip, require custom programming equipment, which may be cheap, or may be very expensive.
Program Storage
The next major distinctions between microcontrollers is the manner in which the program (usually called code) you create is stored. ROMless micros are those with an external bus, as discussed above, which require an EPROM , non-volatile SRAM or a Flash for code storage. An OTP (One-Time Programmable) microcontroller can be programmed exactly once. If the program isn't correct, you throw it away. OTPs are the most popular micro type for low-volume production, where the setup cost of masking (see next) can't be justified. In fact, an OTP is usually just an EPROM without that expensive windowed ceramic package.
Program Storage
A masked microcontroller contains ROM that is programmed by the factory from code you supply. Unless you work for a large company with deep pockets you'll probably never hear about masking again Flash micros are newer on the block. They operate similarly to OTPs, but can be re-programmed many times, usually at least 1000. This makes it feasible to use one chip to test code changes over and over again, and avoid wastage of chips. ROMless and Flash micros share the advantage that the micro does not need to be removed from its board for the code to be changed. This is very useful when developing with high-pin-count SMD microcontrollers, which generally cannot be socketed on the board.
Software Tools
Coding for micros is generally done in either the assembly language or C, although other high-level languages, notably BASIC, are available for some families. Assemblers are almost always supplied free by the micro's manufacturer or a third party, and vary widely in power, while C compilers vary from free to very expensive.
Software Tools
Although assemblers do a relatively simple job they are not bound by any ANSI standard, so they vary widely in syntax and power. A good assembler offers nested macros with local labels, nested conditional assembly and helpful error messages. An interesting variant of the assembler is the structured assembler, which allows you to use flow control construct typical of a high-level language, like if-then-else and switch statements, in assembly. Ultimately your software tools must produce a file for downloading to the micro or EPROM. This must be in a format recognized by the hardware tools (see next), usually binary(bin), hex. Hex file is probably the most common of these, and is a simple text file containing addresses and data.
Programming Tools
OK, you've written a program and have a hex file hot to trot how do you get it into the micro? The easiest category to deal with is ROM-less micros: you either program (burn) your code into an EPROM using an EPROM programmer, or download it to an EPROM emulator, which plugs into your board's EPROM socket and pretends to be an EPROM. For OTP and flash microcontroller a programmer specific to the micro family you're using is required.
Micro Features
Supply Voltage Range Most micros run optimally at the standard 5.0V, but some are designed specifically for lower voltages e.g. 3.3V. Operating micros at very low voltages (from batteries or backup capacitors) is fraught with danger - a well-tested external watchdog is the best safeguard against lockups due to unpredictable voltages. The Clock Like any computing device, a micro has a master oscillator. This can be a crystal or the cheaper but less precise ceramic resonator. Some small micros offer an internal clock, usually driven by an RC (resistor-capacitor) network, whose frequency can vary greatly with voltage, temperature. Typical clock frequencies are 4-16MHz. The frequency doesn't give any absolute measure of a microcontroller's computing power (throughput), which is measured in MIPS (millions of operations per second), since the number of clock cycles required to execute even the simplest instructions varies widely between cores, and some instructions take longer than others. A useful figure is MIPS/MHz, which indicates roughly how many MIPS of throughput are produced by each MHz of clock speed. Higher clock speeds increase power consumption and RFI emissions.
Micro Features
The Reset Input Most microcontrollers have a reset. Most small and newer microcontroller will start up when power is applied with RESET unconnected or tied to the inactive power rail, but some older families require that an RC delay or a clean pulse be applied after power-up. The Brown-Out Detector The brown-out detector resets the micro if the supply voltage falls seriously below the nominal value, and holds it in the reset state until it rises again. This prevents unpredictable operation at low voltages, including EEPROM corruption. EEPROM corruption is usually the most pressing reason to use brown-out protection; The Watchdog A watchdog is something very good micro-based circuit should have. Many microcontrollers include one on the chip, which must be regularly fed by your code or it will reset the micro. If your microcontroller doesn't have one, use an external watchdog chip such as the Dallas 1232 or equivalent. Most microcontrollers with watchdogs enable your code to tell if the last reset was caused by the watchdog.
Micro Features
I/O Ports All microcontrollers offer digital I/O ports, which you can use as digital input or output. An I/O port is generally a group of up to 8 I/O lines which are addressed together as a byte. Usually any line can be configured as an input or output, with optional weak pull-up (effectively a large resistors connected to VCC) often available for inputs It is common for I/O lines to have an alternate (special) function related to a peripheral; it's a choice whether that line is used by that peripheral or as standard digital I/O. Some I/O lines may have higher current capacity than others, for driving LEDs and other heavy loads; sinking 20mA (low output) is a typical figure for a high-current output.
Micro Features
Interrupts Interrupt is a fundamental concept in micros, and computers in general. Although your program generally follows a predictable linear path through your code, various conditions (both internal and external to the chip) can cause the micro to execute an interrupt handler, then return to your main program where it left off. Interrupts allow your code to respond to events that require urgent attention without the need to waste time checking for that event regularly. Interrupt handlers should be as short as possible to avoid introducing serious delays into your code, and preventing other interrupt handlers from executing. It's common for an interrupt handler to record whatever caused the interrupt (such as a byte received from a UART) and set a flag to indicate this to the main program. Interrupt handlers must save any registers or memory locations that they use whose corruption may affect the main program; the stack is usually used for this. Most microcontrollers allow interrupt handlers to be nested (ie an interrupt handler interrupted by another interrupt handler), although this may require special action on your part and may increase the stack usage of your program. All interrupts are disabled when your program starts, and must be enabled by your code.
Micro Features
Timers Timers are perhaps the most important standard microcontroller peripheral. A timer is a counter driven by some division of the clock. Timers are either 8 or 16 bits in length, and virtually all micros offer at least one 8-bit timer; both up and down-counting timers exist. You can usually start and stop a timer, read and set its value and generate a interrupt when it reaches zero (overflows), which allows you to generate accurate time intervals. More powerful 16-bit timers offer capture and/or compare, usually both. Also common are auto-reload timers, which automatically reload themselves with a specified value and start again when they reach zero, optionally generating an interrupt., which produce a pulse stream with a precisely defined duty cycle (relative low and high times).
Micro Features
Analog Input and Output Some micros, especially larger ones, have 8 or 10-bit A/D converters. Since a micro is a very noisy environment for A/D conversion many micros allow you literally switch off other peripherals while conversions are taking place. Most can generate interrupts when conversions are complete. A/D converters raise the cost of micros dramatically and limit your choice greatly, so consider using an off-chip A/D instead. If conversion speed is not important serial A/Ds like the TLC549 can do the job without consuming many I/O lines. A few micros also offer D/A converters for analog output.
Micro Features
Serial Interfaces A UART (Universal Asynchronous Receiver/Transmitter) is a peripheral that implements an asynchronous serial interface, as used in standard RS-232 connections, so they're very handy for talking to a PC, a terminal or another micro. They all offer the same facilities - the thing to sweat over is the baud rate. Some UARTs require a timer for this while others use a separate baud rate generator driven by the clock. 11.059MHz crystals are available simply because they allow an 8051 to offer the standard baud rates! Some micros offer an SPI (Serial Peripheral Interface) or I2C (Inter Integrated Connect) interface, both of which use a clock line rather than as assumed baud rate to regulate data movement, and are hence synchronous. Both standards allow connection to multiple peripheral chips.
Micro Features
EEPROM EEPROM (Electrically Erasable Programmable Read Only Memory) is non-volatile memory - it retains its contents when power is removed. Some micros include a small amount of EEPROM (often called E-squared) storage for use by your code. The use of EEPROM requires some care. Erasing and rewriting an EEPROM location takes some time, for which time your code must wait if writing multiple locations, and loss of power can corrupt an EEPROM write in progress if the micro doesn't have an internal or external brownout detector.
Micro Features
Analog Comparator The inclusion of analog comparators on micros is a fairly recent, but they can be very handy in circuits which have to interface with an analog world. Low-Power Modes Most micros can enter one or more low-power states, where your program does not run and very little power is drawn, for conservation of batteries, backup capacitors etc. The micro is "woken up" and execution resumed by a timer or external interrupt or an I/O line state change. These modes are typically called Wait, Idle, Sleep etc, and can reduce power supply current to several microamps, dependent on supply voltage and ambient temperature. Real-Time Clocks Some micros, especially those intended for consumer appliances, include a real-time clock, which helps you keep track of the time of day even when the micro is in a low-power mode, and runs from a separate crystal. Typically it generates an interrupt at 1/2 second intervals; the interrupt handler can increment time-of-day counters.
Micro Features
Specialized Display Drivers (ex HD44780 Hitachi) Micros targeted at modern appliances using LCD and gas plasma displays often include drivers to support them. External Peripherals These are the more common chips which can be easily connected to micros to support features they don't provide. Bus interface peripherals are best suited to micros with external buses, usually ROMless, due to the large number of connections they require. Bus peripherals are divided according to the bus design with which they are compatible, either Intel or Motorola. Both companies introduced bus peripherals suitable for their 8-bit CPUs in the 70s, and their later micros used compatible buses. Intel, Tundra and OKI offer Intel-bus peripherals; Motorola and SGS-Thompson offer Motorola-bus peripherals. Beware of NMOS versions of these parts, which can have very high power consumption. The original IBM PC was full of Intel-bus peripherals, which are still available and work with the 8051. Serial interface peripherals can be used with any micro, although some provide an easy-to-use hardware interface; code to emulate this is available for all popular micros
Micro Features
Timer (bus interface): Contains three separate16-bit timers which can be used in various ways. UART (bus interface): Contains one or more separate UARTs. May offer handshaking lines and FIFOs which allow bytes to be handled in groups, features not usually found in micro UARTS. May also be called an ACIA (Asynchronous Communications Interface Adapter). Quad and octal UARTs are UARTs capable of 3Mb/s are available for special communications needs. Peripherals supporting proprietary communications protocols (eg IBM networking) also exist. I/O extender (bus or serial interface): Provides more general digital I/O - typically 24 lines for a 40-pin package. A/D converter (bus or serial interface): Provides analog inputs. Many offer features not often found on micros, such as a settable voltage range or 12-bit conversion. They tend to work better than on-micro A/D converters because they're isolated from the noisy internals of the micro. Real-Time Clock (serial interface): A chip with its own crystal and backup battery support which keeps track the time of day and date. More capable than the peripheral of the same name found in some larger micros. Non-Volatile RAM (bus or serial interface): Flash or EEPROM memory which retains its contents when power is removed. The bus interface offers much faster access, but serial interfaces are cheaper and suit smaller micros. Many standard 74-series logic chips (most commonly 74HC CMOS) can work with micro buses or be used to reduce I/O requirements. For example, the 74HC574 octal latch can provide 8 digital outputs and the 74HC595 shift register can be used to drive any number of digital outputs from just three micro outputs, albeit
Micro Architecture
Basic Types There are two basic types of architecture to be found in micros: The Harvard architecture locates the code and data storage areas (memory spaces) on separate buses, which allows instructions and data to be fetched simultaneously by the core, improving efficiency. The Von Neumann architecture puts all memory spaces on the same bus, so every location in every space must have a unique address. This enables every space to be treated identically as instructions or data, which has some interesting possibilities, but is less efficient. PC architectures, where memory locations can't be pre-wired as RAM or ROM, are Von Neumann.
Micro Architecture
CISC and RISC In parallel with the interest in CISC (complex instruction set computer) for large CPUs came RISC (reduced instruction set computer) architectures for micros. The hallmark of a RISC micro is that instruction words are more than 8 bits long (eg 12, 14 or 16 bits) and most instructions only require one word, whereas conventional CISC micros have 8-bit instruction words and many instructions that require more than one of them. Generally RISC micros are designed for speed, and sacrifice some ease of use to that end, but the difference in ease of use isn't so great that it should influence your choice of micro. You're more likely to pick a PIC or AVR RISC micro for its speed than reject it because its instruction set is small or appears strange.
Micro Architecture
To Accumulate Or Not To Accumulate The major difference to be found when comparing the instruction sets of micros is that some require that most arithmetic and logical operations be performed on a single register, usually called the accumulator, while others allow any of a number of registers to be used. The advantage of the accumulator approach is that instructions using it can be short, mostly 8 bits, whereas non-accumulator cores require a longer instruction word or multiple instruction bytes to specify the operation. However, accumulator cores are poor at multibyte (eg 16, 24 or 32-bit) data operations because every byte must pass through the accumulator. Since non-accumulator designs suit the wider instruction words of RISC cores they'll probably become more common. They chew code space more quickly and don't make a major difference to performance unless a lot of multi-byte processing is required. The Atmel AVR and Zilog Z8 are examples of non-accumulator cores.
Micro Architecture
Spaces Some subset of the following spaces is found in all micros: Code: Where your program is stored. Data: RAM locations available to your program. The I/O space may be mapped into this space rather than separate. Registers: May be mapped into the Data space or made entirely separate in RISC-type architectures. Access to registers is faster and more capable than access to Data. I/O: Special locations which form the program's interface with Port I/O and peripherals. ROMless micros also possess an external space for access to the external bus, which may be separate or mapped into the single Data space. Understanding the spaces understood by a micro and their functions is the basic step in coming to grips with its architecture.The 8051 is an example of a core with a variety of spaces, all of which must be understood to make effective use of it.
Micro Architecture
The Stack All micros have a stack - a dynamic RAM area onto which return addresses are pushed when you call a routine or an interrupt handler is invoked, and off which they are popped when these routines finish. Some very small micros with very a small Data space implement a special small space for the stack (termed a hardware stack) which may be as small as 3 locations, severely limiting the nesting of routine calls and interrupt handlers allowed! Most micros require you to set a stack pointer at startup, which is then used as a base for the stack, which grows upward or downward (make sure you know which). If RAM space is tight, work out what the maximum possible stack size is, and reserve space for it accordingly. Corruption of the stack by other data (or vice versa) can be tough to track down, so it's better to be cautious here. Most micros allow you to push and pop data onto and off the stack yourself. Apart from saving registers in interrupt handlers, the stack can often be useful when you're short of registers and need to temporarily save their values.
Choosing a Micro
Picking the right micro for the job is something that thousands of engineers with many years of experience mull over every day - it can be a tough don't have time to learn something new. These are things to consider: Availability and cost: The micro must be readily available - most are from a single manufacturer, but multiple distributors depending on your location. And it must be sensibly priced - prices can vary insanely within a family depending on demand, supply and popularity. Support: Is the micro from a popular family? Ask people if they'd recommend it . Is the local distributor helpful and (ideally) willing to lend you tools to get you hooked on it? What's the manufacturer's website like? Be very cautious with Asian manufacturers - they have some wonderful micros, but they simply don't care about your problems unless you're using millions. NEC and Hitachi are exceptions to this.
Choosing a Micro
Tools Decide whether you want an emulator, which is usually far more expensive than a simple programmer. If tools cost is the driving factor serial programmers for flash micros (eg H8, AVR) are unbeatable. Variety: If you invest time and money in a new family, it's a bonus if they are useful down the track. Get an overview of all the micros that use that core and tools, and see if you like the view. The 8051 is untouchable for variety, with the HC05 doing well at the smaller end of town. Reliability: New families (and even new parts in established families) can have problems, usually in hardware rather than software. Don't use a new part if you can't accept some risk. Flexibility: If you want to leave room to add more memory or peripherals later, consider ROMless micros. You can hang anything off them you can think of. Package: It must be easy to handle given your manufacturing expertise and programming tools. Don't pick a QFP (quad flat pack) chip unless you have the equipment and knowhow to handle it. DIP and PLCC are both socketable and easy to handle (DIP more so). If you need a lot of I/O but want to avoid surface mount, ROMless micros with 24-line I/O expanders or HC574 latches are your guys. Unfortunately the level of micro power at which packages become surface mount is decreasing as industry demands miniaturisation, so your choice of newer parts may be limited. Noise Immunity: In the mains appliance industry, where I've spent some time, this is right up there with cost. Micros very greatly in their resistance to the electrical crud that enters at power supplies and cabling, sneaks through any attempts at filtering . The ST6 family is superb at this, the Z8 very poor, with most somewhere in between.
Debugging
It would be great if micro development was simply a matter of downloading the code, verifying that it works correctly and moving on to the next project. Unfortunately, bugs are inevitable. Some are due to simple coding mistakes (more common in assembly), some are due to interactions between tasks you didn't expect or too-large response latencies, and some are due to the hardware that the data book forgot to mention. Firstly, don't try to write all the code in one session. Work incrementally, getting things happening in small stages. That way you'll always have working code to fall back on when things go wrong. Step through newly written code in a simulator if possible to check that it works and doesn't have unwanted side effects. It's much better to write and verify a piece code slowly and carefully, before ever running it for real, than to try to fix it later when it's obscured by other functionality.