Putting together a microcontroller project involves several steps:
- Define the task
- Design and build the circuits
- Write the control program
- Test and debug
Sometimes the steps won’t follow exactly in this order. You may begin writing your program before you build the circuits, or you may build and test some of the circuits before you start programming. But however you go about it, each of the above steps is part of the process. To see what’s involved in each step, let’s look at each in more detail.
Defining the Task
Every project begins with an idea, or a problem that needs a solution. For example, How can I monitor light intensity at different locations and times of day to find the best location for a solar collector? Or how can I automate the process of drilling printed-circuit boards? Or how can I create a computer-controlled, animated display for a store window?
Once you know what you want to accomplish, you need to determine whether or not your idea is one that requires a computer at all. In general, a computer is the way to go when the circuits must make complex decisions or deal with complex data. For example, a simple AND gate can easily decide whether or not two inputs are both valid logic highs, and will change its output accordingly. But it would require many small-scale chips to build a circuit that stores a series of values representing sensor outputs and the times they occurred, and displays the information in an easily understandable form.
This type of application is where microcontrollers come in handy. Inside, microcontrollers are little more than a carefully designed array of logic gates and memory cells, but modern fabrication processes allow thousands of these to fit on a single chip. Since the basic functions of a microcontroller—performing arithmetic, logic, data-moving, and program branching functions—are common ones that are useful in many applications, it’s practical to design and market a chip that performs these functions. The user accesses the abilities of the microcontroller by writing a program that performs the desired functions.
On the other end of the scale, how do you know if an idea is suitable for a microcontroller, or whether you should use a full desktop computer? If your design requires users to enter or view complex commands, data, or graphical information, or if you need large amounts of data or program storage, then a system with keyboard, full-screen display, and disk drives makes sense. For simpler designs, a microcontroller with perhaps a keypad, small display, and solid-state memory (no disk drives) can often do the job, with less expense and smaller size.
In fact, recently the two extremes have been meeting. Some 32-bit microcontrollers are as capable as desktop systems, and notebook-size computers are available with solid-state, diskless storage. Also, expansion cards, other hardware, and software are now available for those who want to use desktop computers for monitoring and control tasks. So there’s something for everyone.
The 8052-BASIC chip described in this book is perfect for many simpler applications,
especially control and monitoring tasks. Because the chip is easy to use, it’s a good way to learn about microcontrollers and computers in general. Although you can’t do the most complex projects with it, you can do a lot, at low cost and without a lot of hassle.
Designing and Building
When you’re ready to design and build the circuits for a project, there are several ways to proceed. You can design your circuits from scratch, using manufacturers’ data books as guides; you can follow a tested design (a kit or project presented in a magazine for example); or you can buy an assembled single-board computer, adding only the interfaces and programming your application requires. This book presents designs that you can build yourself, but you can also use a kit or assembled board as a base if you wish.
Choosing a chip. Does it matter which microcontroller chip you use? All microcontrollers contain a CPU, and chances are that you can use any of several devices for a specific project. Within each device family, you’ll usually find a selection of family members, each with different combinations of options. For example, the 8052-BASIC is a member of the 8051 family of microcontrollers, which includes chips with program memory in ROM or EPROM, and with varying amounts of RAM and other features. You select the version that best suits your system’s requirements.
Microcontrollers are also characterized by how many bits of data they process at once, with a higher number of bits generally indicating a faster or more powerful chip. Eight-bit chips are popular for simpler designs, but 4-bit, 16-bit, and 32-bit architectures are also available. The 8052-BASIC is an 8-bit chip.
Power consumption is another consideration, especially for battery-powered systems. Chips manufactured with CMOS processes usually have lower power consumption than those manufactured with NMOS processes. Many CMOS devices have special standby or “sleep” modes that limit current consumption to as low as a few microamperes when the circuits are inactive. Using these modes, a data logger can reduce its power consumption between samples, and power up only when it’s time to take data.
The 8052-BASIC chip is available in both NMOS and CMOS versions. The original 8052-BASIC was an NMOS chip, offered directly from Intel. (Intel’s term for its NMOS process is HMOS.) Although Intel never offered a CMOS version directly, Micromint became a source by ordering a batch of CMOS 8052’s with the BASIC-52 programming language in ROM. The CMOS version, the 80C52-BASIC, has maximum power consumption of 30 milliamperes, compared to 175 milliamperes for the NMOS 8052-BASIC.
All microcontrollers have a defined instruction set, which consists of the binary words that cause the CPU to carry out specific operations. For example, the instruction 0010 0110 tells an 8052 to add the values in two locations. The binary instructions are also known as operation codes, or opcodes for short. The opcodes perform basic functions like adding, subtracting, logic operations, moving and copying data, and controlling program branching.
Control circuits often require reading or changing single bits of input or output, rather than reading and writing a byte at a time. For example, a microcontroller might use the eight bits of an output port to switch power to eight sockets. If each socket must operate independently of the others, a way is needed to change each bit without affecting the others. Many microcontrollers include bit-manipulation (also called Boolean) opcodes that easily allow programs to set, clear, compare, copy, or perform other logic operations on single bits of data, rather than a byte at a time.
Options for storing programs. Another consideration in circuit design is how to store programs. Instead of using disk storage, most microcontroller circuits store their programs on-chip. For one-of-kind projects or small-volume production, EPROM has long been the most popular method of program storage. Besides EPROMs, other options include EEPROM, ROM, nonvolatile (NV), or battery-backed, RAM, and Flash EPROM. The program memory may be in the microcontroller chip, or a separate component.
To save a program in EPROM, you must set the EPROM’s data and address pins to the appropriate logic levels for each address and apply special programming voltages and control signals to store the data at the selected address. The programming process is sometimes called burning the EPROM. You erase the contents by exposing the chip’s quartz window, and the circuits beneath it, to ultraviolet energy.
Some microcontrollers contain a one-time-programmable, or field-programmable, EPROM. This type has no window, so you can’t erase its contents, but because it’s cheaper than a windowed IC, it’s a good choice when a program is finished and the device is ready for quantity production.
Several techniques are available for programming EPROMs and other memory chips. With a manual programmer, you flip switches to toggle each bit and program the EPROM byte by byte. This is acceptable for short programs, but quickly becomes tedious with a program of any length. Computer control simplifies the job greatly. With an EPROM programmer that connects to a personal computer, you can write a program at your keyboard, save it to disk if you wish, and store the program in EPROM in a few easy steps. Data sheets for EPROMs rarely specify the number of erase and reprogramming cycles a device is guaranteed for, but a typical EPROM should endure 100 erase/program cycles, and usually many more.
EEPROMs are much like EPROMs except that they are electrically erasable—no ultraviolet source is required. Limitations of EEPROMs include slow speed, high cost, and a limited number of times that they can be reprogrammed (typically 10,000 to 100,000).
ROMs are cost-effective when you need thousands of copies of a single program. ROMs must be factory-programmed and once programmed, can’t be changed.
NVRAM typically includes a lithium cell, control circuits, and RAM encapsulated in a single IC package. When power is removed from the circuit, the lithium cell takes over and preserves the information in RAM, for 10 years or more. You can reprogram an NVRAM n infinite number of times, with the only limitation being battery life.
Flash EPROM is electrically erasable, like EEPROM, but most Flash devices erase all at once, or in a few large blocks, rather than byte-by-byte like EEPROM. Some Flash EPROMs require special programming voltages. As with EPROMs, the number of erase/program cycles is limited.
The 8052-BASIC uses two types of program memory. An 8-kilobyte, or 8K, on-chip ROM stores the BASIC-52 interpreter. For storing the BASIC-52 programs that you write, the BASIC-52 language has programming commands that enable you to save programs in external EPROM, EEPROM, or NVRAM.
Other memory. Most systems also require a way to store data for temporary use. Usually, this is RAM, whose contents you can change as often as you wish. Unlike EPROM, ROM, EEPROM, and NVRAM, the contents of the RAM disappear when you remove power the chip (unless it has battery back-up).
Most microcontrollers include some RAM, typically a few hundred bytes. The 8052-BASIC has 256 bytes of internal RAM. A complete 8052-BASIC system requires at least 1024 bytes of external RAM as well.
I/O options. Finally, input/output (I/O) requires design decisions. Most systems require interfaces to things like sensors, keypads, switches, relays, and displays. Most microcontrollers have ports for interfacing to the world outside the chip. The 8052-BASIC uses many of its ports for accessing external memory and performing other special functions, but some port bits are available for user applications, and you can easily increase the available I/O by adding support chips.
0 comments
Tambahkan Komentar Anda