Файл: Embedded Controller Hardware Design (Ken Arnold, 2001).pdf
ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 13.06.2025
Просмотров: 2656
Скачиваний: 0
38EMBEDDED CONTROLLER
Hardware Design
Internal memory locations from 20 to 2F hex, are accessible either one byte at a time, or one bit at a time. That makes it easy to convert inherently serial information to parallel and vice versa, and to perform Boolean logic functions. This bit-level processing is one of the most unique and powerful features of the 8051 family architecture, and is one of the features that differentiate it from other microcontrollers.
Register Banks
The four register banks within the internal data RAM each contain eight registers named R0-R7.
128 Addressable Bits
There are 128 addressable software flags in the internal data RAM. They are located in the 16 byte locations starting at byte address 20h and ending with byte location 2Fh of the RAM address space.
I/O Ports
There are four 8-bit ports. When using external program or data memory, only Port 1 (P1) is available for general purpose I/O. External memory uses Port 0 (P0) for the multiplexed data bus and address bits 0-7, and Port 2 (P2) for address bits 8-15, while Port 3 (P3) contains special control signals, such as the read and write strobe pins. In addition to the basic parallel I/O bits on the four ports, some of the port bits have alternate functions. The alternate functions include the serial I/O port signals, timer and interrupt inputs.
Timer/Counter
The 8031 has two timer/counters and the 8032 has three.
Serial I/O
The serial I/O port that is built into the 8031 can be used to transmit and receive asynchronous (un-clocked) serial data, as is used on a PC’s serial port. It can also be used for synchronous (clocked) serial data transfers.
39CHAPTER TWO
Microcontroller Concepts
Reset Circuitry
The reset input pin should be connected to an external resistor and capacitor, so that the processor will be properly initialized upon initial application of
power. There is a capacitor between the reset pin and the power supply, and |
||||||||||||||||||||
a resistor from the reset pin to ground. |
Vcc |
|||||||||||||||||||
When power is first applied, the capaci |
||||||||||||||||||||
tor has no voltage across it, forcing the |
SW |
|||||||||||||||||||
+ |
8051 |
|||||||||||||||||||
processor to reset. After resistor R1 |
||||||||||||||||||||
C |
||||||||||||||||||||
charges the capacitor C, the reset signal |
R2 |
|||||||||||||||||||
goes low (inactive), and the processor |
Reset |
|||||||||||||||||||
begins executing the program beginning |
D |
R1 |
(active high) |
|||||||||||||||||
at location 0 in program memory. The |
||||||||||||||||||||
recommended reset circuit is shown in |
||||||||||||||||||||
Figure 2-12: Recommended |
||||||||||||||||||||
Figure 2-12. |
||||||||||||||||||||
reset circuit for the 8051. |
||||||||||||||||||||
When power is first applied, capacitor C has zero voltage across it, and reset is held high until the current that flows through R1 charges C. Once the capacitor is charged, the reset pin is at zero volts and inactive. The diode allows the capacitor to discharge when Vcc goes to zero, even for a short period. If there was no diode, and there was a brief power loss, the CPU state would be indeter minate, and would not be reset. Optionally, the processor can be reset by closing switch SW through a series resistor R2, which limits the current through the switch. The current flowing through the switch discharges the capacitor. If resistor R2 was not present, very high currents could flow through the switch. These high currents that flow very briefly while the capacitor is shorted and can cause the switch contacts to fail or even weld the contacts together.
The R1*C time constant must be long enough to guarantee that the processor will be completely reset to a known state upon power up. The delay must allow the oscillator to start up and stabilize, as well as the time it takes the processor to reset after the oscillator is stable. Different processors require different numbers of clock cycles to reset themselves, and the oscillator start-up time can vary widely depending on the frequency reference, voltage, capacitive loads, and other factors. If the processor reset is not long enough, the processor may behave in unpredictable ways, and it may not be apparent that the problem is due to an incomplete reset operation. In most cases, it’s better to have a relatively long reset time constant, on the order of hundreds of milliseconds, to be sure that the processor has been completely reset. External peripherals can also
40EMBEDDED CONTROLLER
Hardware Design
exhibit this problem. During the initial development of the SDK, we experienced occasional problems with the external serial port chip used on the board. The problem turned out to be related to the length of the reset pulse and the period of time after the reset when the chip must be left alone to pull itself together! This sort of problem can be very difficult to trace down, since it is difficult if not impossible to determine when a chip has not been completely reset.
The 8051 is unique in that its reset signal is active high. Other processors use active low reset signals, so the reset circuit must be adjusted to perform the equivalent function with the reset pulse going low at power up and when the capacitor is charged, the reset goes high. The circuit configuration except R and C1 are swapped, as are D1 and the SW/R2 pair.
The circuit in Figure 2-12 is good enough for most applications. However, it is not foolproof. Even with the above precautions, it is possible that the processor state can be jumbled by power transients that are too short to cause a reset. When a processor is used in a critical or long term unattended application, that probably won’t be good enough to meet the need for reliable operation. To deal with this, processor supervisory chips are available to monitor the power supply voltage for out of tolerance fluctuations and automatically reset the processor when the power supply falls out of tolerance. Some of these supervisory chips also have a special “watchdog” timer circuit that expects to be “fed” by a pulse that resets the watchdog counter periodically by a correctly functioning program running on the processor. If the watchdog timer is not “fed” with a pulse periodically, the counter will overflow and it will “bark” by pulling the reset pin active. That way if the processor goes off in the weeds, due to a hardware glitch or a program bug, the CPU will be reset. This is a simple method of obtaining tolerance to fault conditions, but it also requires careful design to avoid undesired reset conditions. It is also the designer’s responsibility to assure that the processor can’t get stuck in a loop while feed ing the watchdog timer.
When designing a microcontroller that must operate in high noise environ ments, or where correct operation is safety critical, special care must be taken to ensure that electromagnetic noise does not cause problems. This noise can come from other parts of the system and environmental conditions such as electromagnetic fields from other devices such as wireless communication devices. With the rapid increase in the number of electronic and wireless devices, this problem is becoming more and more serious. The field of electromagnetic
41CHAPTER TWO
Microcontroller Concepts
compatibility (EMC) covers this noise, as well as others such as electrostatic discharge (ESD). A good summary of EMC concepts as they relate to microcontrollers can be found in the Intel application note AP-125, “Designing Microcontroller Systems for Electrically Noisy Environments.”
Oscillator and Timing Circuitry
Timing generation is completely self-contained on the 8051, except for the frequency reference (which can be a crystal or external clock source). The on-board oscillator is a parallel anti-resonant circuit with a frequency range of 1.2 MHz to 12 MHz for the original 8051. There is a divide-by-12 internal clock counter that gives the standard 8051 an instruction cycle of 1 S with a 12 MHz crystal. Higher speed versions of the processor are also available, which use fewer than twelve clocks per instruction cycle. The Dallas 80C320 uses only four clock cycles for most instruction cycles, so it is three times faster than the original CPU using the same clock frequency. The XTAL2 pin is the output of a high-gain amplifier while XTAL1 is its input. A crystal connected between XTAL1 and XTAL2 provides the feedback and phase
shift required for oscillation. For stability and |
|||||||||||||||||||
consistent oscillator start-up, two capacitors |
8051 |
||||||||||||||||||
in the range of 10 to 20 picofarads should be |
XTAL2 |
||||||||||||||||||
connected from the XTAL pins to ground. If |
|||||||||||||||||||
XTAL1 is being driven by an external frequency |
|||||||||||||||||||
source, XTAL2 should not be connected. An |
C |
C |
XTAL1 |
||||||||||||||||
external clock can also be applied to XTAL1 |
|||||||||||||||||||
to allow the use of a separate clock frequency |
|||||||||||||||||||
source, such as an oscillator module. Figure |
Figure 2-13: Standard |
||||||||||||||||||
2-13 shows a standard oscillator configuration. |
oscillator configuration. |
||||||||||||||||||
The oscillator circuit consists of a crystal connected between the XTAL1 and XTAL 2 pins of the processor, along with two capacitors, one from each XTAL pin to ground to improve stability and start-up characteristics of the oscillator. The internal amplifier and quartz crystal form a series resonant oscillator which operates at the at the crystal’s resonance frequency. The amplifier in the original 8051 was an inverting amplifier, but other variants and other processor families make use of non-inverting amplifiers in some cases. All of the processor’s timing is derived from this oscillator. For the standard 8051 compatible parts,
42EMBEDDED CONTROLLER
Hardware Design
each instruction cycle requires a multiple of 12 clock cycles. For the Dallas high-speed CPU versions, four clock cycles are used for most instruction cycles.
In most 8051 designs, the capacitors connected to the crystal should be in the 10 to 50 picofarads range, with 30 picofarads being a typical value. The crystal should be an “AT cut” series resonant device. The “AT” designation refers to the way the quartz crystal is cut from the blank with an orientation relative to the crystal lattice that reduces the crystal’s frequency dependence on temperature changes. The crystal is manufactured so that it is series resonant at the specified frequency. A given crystal will resonate in a series or parallel mode. A parallel resonant crystal will still operate in the circuit, but it will operate at a slightly different frequency. Actual operating frequency depends on the load capacitance, and is subject to temperature, and will drift over time.
Selection of the capacitors is a trade-off between oscillator start-up time and stability. Specification of a crystal depends upon the specific design require ments and the processor being used. Even parts with the same number may have different requirements, especially for parts from different manufacturers.
There’s much more information available from the crystal and processor manufacturers on the proper design and operation of crystal oscillators. Other frequency references, such as ceramic resonators and even simple R-C circuits can be used for many processors. Some microcontrollers even include on-chip oscillators that can be calibrated to operate at a specific frequency, albeit with less accuracy and greater drift. Application note AP-155, “Oscilla tors for Microcontrollers” from Intel Corporation, is a very useful reference and describes the characteristics of both the crystal and ceramic resonator’s operation as well as the processor’s oscillator amplifier.
The 8051 Microcontroller Instruction Set Summary
The following description of the instruction set is not a complete list, but serves to introduce the general character of the standard 8051 instructions. The instruc tion set utilized by the 8051 microcontroller consists of a total of 111 instructions, which may be divided up into several different categories. These are:
1.Arithmetic (24)
2.Logical (25)
43CHAPTER TWO
Microcontroller Concepts
3.Data transfer (28)
4.Bit (Boolean) variable manipulation (17)
5.Program branching and control (17)
Each of these categories is comprised of instructions that utilize mnemonics as shown below:
Arithmetic
ADD, ADDC, SUBB, INC, DEC, MUL, DIV, DA
Logical
ANL, ORL, XRL, CLR, CPL, RL, RLC, RR, RRC, SWAP
Data Transfer
MOV, MOVX, MOVC, PUSH, POP, XCH, XCHD
Bit (Boolean) Variable Manipulation
CLR, SETB, CPL, ANL, ORL, MOV, JC, JNC, JB, JNB, JBC
Program Branching and Control
ACALL, LCALL, RET, RETI, AJMP, LJMP, SJMP, JMP, JZ, JNZ, CJNE, DJNZ, NOP
Direct and Register Addressing
While the number of mnemonics is clearly smaller in number than the total of 111 instructions, a given mnemonic may be used in several different ways to make up a valid 8051 instruction. These different ways of forming instructions are classified by the types of arguments that a given mnemonic takes. A mnemonic can refer to data in a number of ways. One can refer to data located in particular address in the data memory space either by specifying its address directly, or indirectly by using a data pointer register. In this case, the data pointer register contains the address of the memory location we seek. The 8051 looks in the data pointer register, and then retrieves the information located in the location referred to (or pointed to) by the data pointer. Additionally, the 8051 has 32 bytes of internal memory divided up into four register banks of eight bytes each. These register banks may be referred to in an 8051 instruction by either their direct address (which ranges between 00h and 1Fh), or by their register