Counter/timer 2 of the 83C552 microcontroller

Similar documents
o The 9S12 has a 16-bit free-running counter to determine the time and event happens, and to make an event happen at a particular time

o The 9S12 has a 16-bit free-running counter to determine the time and event happens, and to make an event happen at a particular time

TV Synchronism Generation with PIC Microcontroller

RS flip-flop using NOR gate

Microcontrollers. Outline. Class 4: Timer/Counters. March 28, Timer/Counter Introduction. Timers as a Timebase.

M68HC11 Timer. Definition

NS8050U MICROWIRE PLUSTM Interface

RS flip-flop using NOR gate

Design and Implementation of Timer, GPIO, and 7-segment Peripherals

3 Flip-Flops. The latch is a logic block that has 2 stable states (0) or (1). The RS latch can be forced to hold a 1 when the Set line is asserted.

Digital Systems Based on Principles and Applications of Electrical Engineering/Rizzoni (McGraw Hill

CHAPTER1: Digital Logic Circuits

FLIP-FLOPS AND RELATED DEVICES

Logic and Computer Design Fundamentals. Chapter 7. Registers and Counters

SEQUENTIAL LOGIC. Satish Chandra Assistant Professor Department of Physics P P N College, Kanpur

Point System (for instructor and TA use only)

Counters

Figure 30.1a Timing diagram of the divide by 60 minutes/seconds counter

Experiment 8 Introduction to Latches and Flip-Flops and registers

Chapter 5 Flip-Flops and Related Devices

BUSES IN COMPUTER ARCHITECTURE

UNIT V 8051 Microcontroller based Systems Design

Chapter 6. sequential logic design. This is the beginning of the second part of this course, sequential logic.

Flip-Flops. Because of this the state of the latch may keep changing in circuits with feedback as long as the clock pulse remains active.

Last time, we saw how latches can be used as memory in a circuit

Decade Counters Mod-5 counter: Decade Counter:

ADC Peripheral in Microcontrollers. Petr Cesak, Jan Fischer, Jaroslav Roztocil

Laboratory Exercise 7

UNIT IV. Sequential circuit

Hello and welcome to this presentation of the STM32L4 Analog-to-Digital Converter block. It will cover the main features of this block, which is used

IT T35 Digital system desigm y - ii /s - iii

Logic Design Viva Question Bank Compiled By Channveer Patil

Logic Devices for Interfacing, The 8085 MPU Lecture 4

Objectives. Combinational logics Sequential logics Finite state machine Arithmetic circuits Datapath

Name Of The Experiment: Sequential circuit design Latch, Flip-flop and Registers

Digital Systems Laboratory 3 Counters & Registers Time 4 hours

Logic Design. Flip Flops, Registers and Counters

Sequential logic. Circuits with feedback. How to control feedback? Sequential circuits. Timing methodologies. Basic registers

6. Sequential Logic Flip-Flops

AN2577 Application note

Synchronous Sequential Logic

COSC 243. Sequential Logic. COSC 243 (Computer Architecture) Lecture 5 - Sequential Logic 1

UNIT-3: SEQUENTIAL LOGIC CIRCUITS

cascading flip-flops for proper operation clock skew Hardware description languages and sequential logic

Introduction. NAND Gate Latch. Digital Logic Design 1 FLIP-FLOP. Digital Logic Design 1

2.6 Reset Design Strategy

DT9834 Series High-Performance Multifunction USB Data Acquisition Modules

Fast Quadrature Decode TPU Function (FQD)

Long and Fast Up/Down Counters Pushpinder Kaur CHOUHAN 6 th Jan, 2003

A MISSILE INSTRUMENTATION ENCODER

ELE2120 Digital Circuits and Systems. Tutorial Note 8

NI-DAQmx Device Considerations

Side Street. Traffic Sensor. Main Street. Walk Button. Traffic Lights

D Latch (Transparent Latch)

Read-only memory (ROM) Digital logic: ALUs Sequential logic circuits. Don't cares. Bus

Advanced Devices. Registers Counters Multiplexers Decoders Adders. CSC258 Lecture Slides Steve Engels, 2006 Slide 1 of 20

Digital Logic Design Sequential Circuits. Dr. Basem ElHalawany

Vignana Bharathi Institute of Technology UNIT 4 DLD

Counters. The simplest circuit for binary counting is a multibit divider.

Solutions to Embedded System Design Challenges Part II

THE ASTRO LINE SERIES GEMINI 5200 INSTRUCTION MANUAL

Sequential Digital Design. Laboratory Manual. Experiment #7. Counters

Chapter. Synchronous Sequential Circuits

Product Update. JTAG Issues and the Use of RT54SX Devices

CS8803: Advanced Digital Design for Embedded Hardware

Contents Circuits... 1

Digital Fundamentals: A Systems Approach

Switching Theory And Logic Design UNIT-IV SEQUENTIAL LOGIC CIRCUITS

Low Power VLSI Circuits and Systems Prof. Ajit Pal Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

The outputs are formed by a combinational logic function of the inputs to the circuit or the values stored in the flip-flops (or both).

Chapter 4. Logic Design

NH 67, Karur Trichy Highways, Puliyur C.F, Karur District UNIT-III SEQUENTIAL CIRCUITS

82C55A CHMOS PROGRAMMABLE PERIPHERAL INTERFACE

DIGITAL SYSTEM FUNDAMENTALS (ECE421) DIGITAL ELECTRONICS FUNDAMENTAL (ECE422) COUNTERS

Laboratory Exercise 7

TSIU03, SYSTEM DESIGN. How to Describe a HW Circuit

EMT 125 Digital Electronic Principles I CHAPTER 6 : FLIP-FLOP

A25L512A Series. 512Kbit Low Voltage, Serial Flash Memory With 100MHz Uniform 4KB Sectors. Document Title. Revision History. AMIC Technology Corp.

Chapter 6. Flip-Flops and Simple Flip-Flop Applications

Flip-Flops and Related Devices. Wen-Hung Liao, Ph.D. 4/11/2001

Previous Lecture Sequential Circuits. Slide Summary of contents covered in this lecture. (Refer Slide Time: 01:55)

COSC3215. Input Capture Output Compare

Design and Implementation of an AHB VGA Peripheral

Sequential Logic Basics

Flip Flop. S-R Flip Flop. Sequential Circuits. Block diagram. Prepared by:- Anwar Bari

YEDITEPE UNIVERSITY DEPARTMENT OF COMPUTER ENGINEERING. EXPERIMENT VIII: FLIP-FLOPS, COUNTERS 2014 Fall

Module for Lab #16: Basic Memory Devices

T 2 : WR = 0, AD 7 -AD 0 (μp Internal Reg.) T 3 : WR = 1,, M(AB) AD 7 -AD 0 or BDB

Training Note TR-06RD. Schedules. Schedule types

Rangkaian Sekuensial. Flip-flop

Microcontrollers and Interfacing week 7 exercises

Synchronous sequential circuits

MODULE 3. Combinational & Sequential logic

Laboratory Exercise 4

Generation and Measurement of Burst Digital Audio Signals with Audio Analyzer UPD

Experiment # 9. Clock generator circuits & Counters. Digital Design LAB

Microprocessor Design

CHAPTER 4: Logic Circuits

California State University, Bakersfield Computer & Electrical Engineering & Computer Science ECE 3220: Digital Design with VHDL Laboratory 7

Dynamic Animation Cube Group 1 Joseph Clark Michael Alberts Isaiah Walker Arnold Li

Transcription:

INTODUCTION TO THE 83C552 The 83C552 is an 80C51 derivative with several extended features: 8k OM, 256 bytes AM, 10-bit A/D converter, two PWM channels, two serial I/O channels, six 8-bit I/O ports, and four counter/timers. The architecture of the 83C552 is identical to that of the 80C51, making the two devices fully code compatible. The additional peripheral functions are added to the 80C51 pecial Function egister space, and the interrupt structure is modified accordingly. This information is detailed in other references on the 83C552. The focus of this application note is on one of the timers of the 83C552, Counter/Timer 2. This counter/timer includes capture, compare, and high-speed output capabilities which facilitate many control oriented tasks. The objective of this note is to make users of the 83C552 aware of this counter/timer subsystem and assist the use of this subsystem by a detailed explanation of its operation supported by actual application examples. TIME 2 OF THE 83C552 Timer 2 of the 83C552 is in fact a timing controller and has an associated programmable array. The Timer 2 subsystem consists of three parts: 1. The time base consists of a 16-bit timer with a 3-bit prescaler. The master clock for the subsystem can be derived from the on-chip oscillator (fosc) or an external input, T2. It has an external reset, T2, by which a signal applied to this input can reset the timer if the external reset is enabled. 2. A capture system consisting of four capture registers and four capture inputs which can be used for a wide variety of time measurements on external signals. 3. A compare system consisting of three compare registers and eight associated high-speed outputs which can be activated upon a match between the 16-bit timer and one of the compare registers. For reference a complete block diagram of the 83C552 Counter/Timer 2 subsystem is shown in Figure 1. 16-BIT COUNTE/TIME The description of Counter/Timer 2 in the following paragraphs is intended to be a general overview. Details on architecture, address locations, interrupt structure, and timer operation are given in the 83C552 Users Manual. This users manual may be useful to complement the material presented in this application note. eferences to registers, bits, I/O ports, and on-chip hardware will relate directly to 83C552 Users Manual nomenclature. This application note will focus on the use of Counter/Timer 2 as a powerful input capture and high-speed output facilitator through some specific examples and not on the detailed coding. The counter/timer consists of a 16-bit counter which is readable by software through special function registers TM2L and TM2H. The timer itself has two overflow flags, one after the entire 16-bit counter and one attached to the eighth stage. This latter flag reflects an overflow from the first byte of the counter. These two flags are present in register TM2I and are labeled T2BO for the overflow from the first byte and T2OV for the overflow from the entire 16 bits. These flags may be used to generate an interrupt. The counter timer is controlled directly through the special function register TM2CON, the timer 2 control register. This register also contains certain status flags. The prescaler divides the input clock by a programmable ratio. The prescaler divide value is programmable to divide by 1, 2, 4, or 8 as controlled by T2PO and T2P1 in TM2CON. The input clock to the prescaler is either fosc/12 or the external input, T2. The clock input to the prescaler may also be shut off. This clock input selection is controlled by bits T2M0 and T2M1 in TM2CON. If T2 is used as the input clock to the timer 2 subsystem, the hardware logic samples this input and looks for a low-to-high transition. If the logic detects a logic 0 at the T2 input in state 2P1 of the microcontroller and a logic 1 in state 5P1, then this is recognized as a low-to-high transition, and the prescaler is incremented. The prescaler is incremented in the second cycle after the cycle in which the transition was detected. If the transition is detected before 2P1 is finished, the prescaler is incremented in the next cycle. This timing is shown in Figure 2. Note that this sampling rate is twice that of the normal 80C51 timers, T0 and T1; therefore T2 has twice the maximum external counting rate as compared to the standard timers. Any programming of the clock source or the prescaler divide ratio results in a reset of the prescaler. This allows the state of the timer subsystem to be in a known state upon programming. The main 16-bit timer cannot be reset by software but it is reset by activating the reset pin or using the external reset, T2. The external reset, T2, can be enabled or disabled by bit T2E in TM2CON. These resets reset the prescaler as well as the 16-bit counter. Only one interrupt is available from the 16-bit counter timer. Two bits in TM2CON control whether TM2L, TM2H, or both flags will be used to generate the interrupt. A selection for no interrupt is also possible. Capture ystem The capture system is a powerful tool to measure the width of pulses or repetition rates. There are four independent inputs for the signals to be analyzed, CTI0 through CTI3. These inputs are alternate functions to port 1. Each input is connected to a dedicated capture register. A transition at any of these inputs will cause the content of the 16-bit counter/timer to be loaded into the respective capture register. The capture can occur upon various conditions of the input signal as specified by certain bits in the capture control register, CTCON. Each input can be set to cause a capture on a low-to-high transition, a high-to-low transition, or on both transitions. Upon a capture taking place, each input causes an interrupt flag to be set in the Timer 2 errupt Flag egister, TM2I. If enabled, an interrupt will be generated. One of the capture inputs is shown in more detail in Figure 3. All of the other capture inputs are similar to this one. The capture input is gated with the capture enable bits CTN0 and CTP0, which are located in CTCON. According to the status of these bits, the desired edges are selected to generate the capture enable pulse. The input pulse transient detection is at the input of the enable pulse generator. The input signal is sampled at 1P1 of the machine cycle. If a logic 1 is detected when a logic 0 was detected at the same time in the previous cycle, then the event is taken as a transition. An enable pulse is sent to the capture register, and the contents of timer 2 is copied into the capture register at the end of this machine cycle. The interrupt flag CTI0 is also set. January 1992 1

CT0I CT1I CT2I CT3I CTI0 CTI1 CTI2 CTI3 CT0 CT1 CT2 CT3 off f OC T2 1/12 Prescaler T2 Counter 8-Bit Overflow errupt 16-Bit Overflow errupt T2 T2E External eset Enable P4.0 P4.1 COMP COMP COMP P4.2 P4.3 I/O Port 4 P4.4 CM0 () CM1 () CM2 (T) P4.5 TG T P4.6 TG T P4.7 TE TE = set = reset T = toggle TG = toggle status T2 F address: TML2 = lower 8 bits TMH2 = higher 8 bits Figure 1. 83C552 Counter/Timer 2 Block Diagram U00352 January 1992 2

1 Machine Cycle 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 P 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 f OC The Basic Microcontroller Instruction Cycle Timing ample Pulse T2 Input 1 2 Counter Incremented By transition 1 By transition 2 U00353 Figure 2. The ampling of the External Clock ignal TM2 CT0 TM2H CTH0 TM2L CTL0 8 ernal Bus 1 TM2I 0 CT01 Enable Pulse t M CTI0 CTCON CTN0 CTP0 Enables capture on falling edge Enables capture on raising edge 1P1 t M U00354 Figure 3. Capture ubsystem for CTO1 January 1992 3

Compare ystem The compare system of Timer 2 can be used to generate a set of outputs whose transitions are controlled directly by the time defined by the 16-bit counter/timer. There are eight of these high-speed outputs which are directly controlled from Counter/Timer 2. These outputs are alternate functions to port 4. ix of these outputs are set-reset controlled (CM0 through CM5), and two are toggle controlled (CMT0 and CMT1). To clarify the operation, these two types will be discussed separately. In the following discussions, refer to Figure 4, which shows the compare system for P4.5 (a set-reset high-speed output) and P4.6 (a toggle high-speed output). There are two compare registers associated with the set-reset outputs. These registers are CM0 and CM1. In addition, there are two enable registers: one to enable setting of an output and the other to enable resetting of an output. These registers are TE and TE, respectively. The contents of CM0 and CM1 are continuously compared to the contents of the 16-bit counter. Whenever there is a match between the 16-bit counter and the contents of CM0, a ET pulse is generated. imilarly, whenever there is a match between the timer and the contents of CM1, a EET pulse is generated. The set pulse is applied to the set-reset outputs, CM0 through CM5, through gates controlled by bits in TE. Bits 0 through 5 in TE control the application of the ET pulse to one of the high-speed outputs. For example, TE.0 controls the gating of the ET pulse to CM0, TE.1 controls the gating of the ET pulse to CM1, and so forth. Thus, if the corresponding ET enable bit in TE is a 1 and a compare occurs with CM0, then that high-speed output will become set. imilarly, the reset pulse from CM1 is applied to the high-speed outputs CM0 through CM5 through gates controlled by bits in TE. As with TE, bits 0 through 5 in TE control the application of the reset pulse to one of the high-speed outputs. If a compare occurs between the timer and CM1, a high-speed output will be reset if its corresponding enable bit in TE is a 1. Compares with CM0 and CM1 set interrupt flags which, if enabled, can be used to generate an interrupt. The two toggle-controlled outputs are CMT0 and CMT1, and these are associated with compare register CM2. These outputs are also alternate functions on port 4. Upon a compare between the counter and the contents of CM2, CM2 generates a toggle pulse which is applied to the high-speed outputs CMT0 and CMT1 through a set of gates. The gates control the application of the toggle pulse to the toggle outputs as specified by the high-order bits of register TE. ET.6 controls CMT0, and ET.7 controls CMT1. hould the corresponding bit of TE be set, then the toggle pulse is enabled to the associated high-speed output and that output will toggle upon generation of the toggle pulse from CM2. The structure of these toggled outputs is different from the other high-speed outputs in that the toggling is actually accomplished in a separate toggled flip-flop and not directly in the port latch. This toggle flip-flop cannot be controlled directly by software and powers up in an indeterminate state. The state of the toggle flip-flops is readable in TE bits 6 and 7. CM0() CM1() CM2(T) TM2 Comparator0 Comparator1 Comparator2 Q =Match Q =Match Q =Match TM2I CMI2 CMI1 To interrupt system CMI0 TE.5 & Q Port P4 TE.5 & Q TE.6 P4.5 & Q P4.6 & Q P4.7 oftware Control Toggle FF TE TG46 TG47 TE.6 TE.7 U00355 Figure 4. Compare ystem for P4.5 and P4.6 January 1992 4

APPLICATION EXAMPLE TIMED FUEL INJECTION In modern automobiles, optimal combustion is necessary to meet emission standards and improve fuel consumption. Optimal combustion depends on several factors and is enhanced by proper fuel injection based upon these factors which vary according to engine speed and other factors. Thus the task is to control the opening and closing of the engine fuel injectors of each cylinder relative to the crankshaft reference point. For the application example here, we will not consider the factors which determine the timing relationships. These are assumed to be given quantities. The example here will focus upon the implementation of the injector timing control signals and how they are generated using the Counter/Timer 2 system. The illustration considers a four cylinder engine. While this is an automotive application which serves to clearly illustrate Counter/Timer 2 ubsystem operation, it is clear that many systems share similar timing requirements, and the techniques employed here are applicable to a wide class of timing tasks. The 83C552 will also support six cylinder engine control. Figure 5 shows the injection timing required for two consecutive revolutions of the engine crankshaft.. tart and stop of the injection are given relative to a reference point on the crankshaft. The cylinders are numbered in the order of the injection sequence (not with reference to their physical location). tart of the injection is usually given in angular measure with respect to top dead center, and the injection duration is assumed to be a time value calculated from engine environmental factors and operating parameters. The angle for the start of the injection must be converted into time with respect to the reference point. The injector drivers are assumed to be connected to the port 4 high-speed outputs CM0 through CM3. To obtain the top dead center reference point, the signal from the appropriate sensor is connected to the capture input CTOI. The interrupt for this capture input is enabled so that software can synchronize its operation to this time reference and make use of the top dead center time in the injector timing calculations. The software synchronization takes two forms. First, the captured time is an absolute reference for all real-time output operations. This time is available in capture register CT0. Note that at 12 MHz operation, Timer 2 can have a resolution as fine as 1 microsecond with a total time before overflow of over 65 milliseconds, and these times are adjustable by increasing the prescaler divide ratio. A proper selection can make the timing calculations relatively simple. econd, at the time the input is captured, flags which keep track of the phases of the crankshaft cycle are reset when cylinder 1 is at top dead center. These flags are used in the interrupt service routines to tell which action is required for that phase of the crankshaft. Consider now the sequence of events in one rotation of the engine crankshaft and refer to Figure 5 during the discussion. Assume that the engine is running, that all relevant parameters are available, and that it has been determined that the processor is responding to the interrupt associated with the top dead center capture, CTOI. errupts for CTOI, CM0 (compare register 0), and CM1 (compare register 1) are enabled. Upon entering the interrupt service routine for CTOI, the previous value of the captured top dead center time is subtracted from the present value, and the crankshaft rotation time is determined. This is used to compute the time to open the first injector from the required angle at which the injector is to open. This time is made available for the interrupt service routine which responds to a compare from CM0. The interrupt service routine is exited. The next interrupt to occur per the figure for this example is a result of a compare with CM1 which will be a result of the injector stop time for cylinder 4 having been reached. The flags in an internal status register are employed to keep track of the cylinder number that is presently active for both injection stop and injection start times. After identifying this interrupt from the flags, the processor uses the injector start time for cylinder 1 (previously loaded into CM0) and the predetermined duration to calculate the injector stop time for cylinder 1. This value is loaded into compare register CM1 and the reset enable bit for high-speed output CM0 is programmed to a 1. This is bit TE.0 The reset enable bit for the cylinder 4 injector is set to 0 (bit ET.3). The interrupt routine is now exited. eference T-stop Cyl 1 T-start Injection Cyl 2 Cyl 3 Cyl 4 Indicates injectors are on. Figure 5. Four Cylinder Injection Timing U00356 January 1992 5

The next interrupt to occur will be for the start time for the injector for cylinder 2. This and all subsequent cases follow the same sequence of events as for the cylinder 1 CM0 interrupt described above. In this case, calculations are made for cylinder 2 and loaded into CM0,TE.1 is programmed to a 1, and TE.0 is programmed to a 0. imilarly, the next interrupt for CM1 is treated in the same way, and the sequence of events rotates around through all cylinders in turn. The flag bits associated with this operation keep track of the injector sequencing. While this example shows the injection stop time of one cylinder overlapping into the injector on time of the subsequent cylinder, close examination of the operations described above reveal that the start and stop events are independent and can overlap or not as required. In this way all injectors may be driven independently and have overlapping on times. Given that this is an example applicable to general usage, it is possible that interrupt service routine could be relatively long as it would be in an actual injector application. ince the service routine has other interrupts disabled, the length may cause real-time conflicts. To eliminate this potential problem, the interrupt service routines are divided into two parts. In the first part, all other interrupts are disabled, and the essential register loading is done to prepare for the next interrupt. After this is completed, all interrupts are enabled and the ancillary service routine functions are performed prior to a return to the main routine. As an example, consider the interrupt service routine for CM0. Upon entering the routine, all interrupts are disabled. Then the following actions are performed: et bit in TE to start next injector Clear bit in TE for injector just started Load CM0 with start time for next injector Clear CMIO interrupt flag in TM2I Now that the essential set-up is made for the next interrupt, all interrupts are now enabled. However, the return to the main program is not invoked until the following ancillary processing is completed: Calculate the next absolute start time for the next injector (the next load value for CM0) Increment the flag so that the next entry to this interrupt service routine will be able to identify the next injector to start. The process performing these calculations can be interrupted to service real-time functions. APPLICATION EXAMPLE TIMED IGNITION In electronic ignition systems, multiple ignition coils may be used and each coil is fired by electronic means rather than with the old style mechanical breakers. In a four cylinder engine, there may be two ignition coils, one coil providing spark for a pair of cylinders. Both plugs fire at the same time. For one cylinder, the spark occurs at the appropriate time while for the other cylinder, the spark occurs at the end of the exhaust stroke and has no effect. With timing references to crankshaft top dead center provided by an external sensor, the ignition timing for the engine may be generated in the 83C552 and applied to the electronic drivers for the ignition coils. To illustrate the toggle high-speed outputs of the 83C552 Counter/Timer 2 subsystem, the following example will discuss the ignition timing in a four cylinder engine employing the two coil approach with one coil for a pair of cylinders. The coil timing is illustrated in Figure 6. A reference time is used which is a given interval prior to top dead center so that the times used in the illustration can be always after the reference. There are two times of interest for each coil: the load time and the ignition point. Ignition advance is usually given in degrees crankshaft angle prior to top dead center. As with injection, this angle is assumed to be derived from other calculations and is a given value for this illustration. This angle must be converted in to a time with respect to the reference point. The load time (the time at which the coil has to be switched on to reach the current that will give sufficient energy for an adequate spark) must be subtracted from the desired ignition point. At the ignition time, the coil will be switched off and the spark will be generated. The coil driver electronics are connected to port bits P4.6 and P4.7. Ignition coil 1 is connected to P4.6, and ignition coil 2 is connected to P4.7. These outputs are the toggle high-speed outputs controlled by the 16-bit compare register, CM2. The program simply needs to set up the compare and control registers to turn the coils on and off at the appropriate times. It is assumed in this example that the ignition and load times are given quantities and have been determined previously. eference TDC T ign Ignition Advance Load Time Coil 1 Ignition Coil 2 U00357 Figure 6. Four Cylinder, Two Coil Ignition Timing January 1992 6

Consider now the sequence of events in two rotations of the engine crankshaft and refer to Figure 6. Assume that the engine is running, that all relevant parameters are available, and that it has been determined that the processor is responding to the interrupt associated with a compare to CM2. The top dead center time and crankshaft rotation speed have been already determined through the top dead center capture, CTOI. This is the same as in the injector example. The interrupt for CTOI is enabled. From the top dead center time, the times to turn on and turn off the coil drivers are computed and made available in data storage locations in the microcontroller. It is also convenient to have flags to identify the step in the complete ignition cycle. The flags are cleared in the interrupt service routine for top dead center of cylinder 1. Upon entering the interrupt service routine, other interrupts are disabled. Examination of the flags reveals that the state of the ignition sequence is that coil 1 has been turned on to begin the current build up (load time). The next event will therefore be turning off coil 2 to cause ignition. The interrupt service routine then performs the following actions: The time to turn off coil 2 is moved into compare register 2, CM2. Bit 6 of TE is cleared; this disconnects the output of CM2 from the toggle flip-flop of P4.6 (coil 1). Bit 7 of TE is set; this connects the output of CM2 to the toggle flip-flop of P4.7 (coil 2). The flags are incremented to indicate that the next interrupt will be a result of coil 2 turning off and causing ignition. The other interrupts can be enabled and a return to the main program can be executed. After the other interrupts are enabled and before a return is made to the main program, it may be convenient to do any necessary calculations to determine the time value to be loaded into CM2 in the next CM2 interrupt. ince the flip-flops are toggled, it is likely that upon power up of the microcontroller, the toggle flip-flops will not be in the desired state. To get the toggle flip-flops in the correct state in the ignition cycle, the flip-flops must be toggled if they are in the wrong state. To determine if this is necessary, the state of the toggle flip-flops can be read from the TE register. The state of the P4.6 flip-flop is present in TE bit 6 and the state of the P4.7 flip-flop is present in TE bit 7. Comparing the actual state to the required state determines which if any or both of the flip-flops must be toggled. If a toggle is necessary to put one or both of the flip-flops in the correct state, the corresponding bits in TE would be set for those flip-flops requiring the toggle, and CM2 would be loaded with a value that is slightly larger than the present contents of timer 2. If desired for reliability purposes, the state of the flip-flops could be checked periodically against the ignition cycle flags to determine if a correction is necessary. CONCLUION This application note has examined one aspect of the 83C552 CMO 80C51 derivative microcontroller. The Counter/Timer 2 ubsystem has been applied to a complex timing task of gasoline engine injector valve and ignition coil timing control. While this is a specific application to the automotive interests, the results are applicable to a wide variety of time measurement and control applications. The 83C552 would be ideal for many electromechanical systems such as copy machines, fax machines, industrial process control equipment, automatic transmission control, and anti-skid and anti-lock braking control. These application areas are those which can successfully employ the 83C552 Counter/Timer 2; however, the other features should not be overlooked. When combined with the 10-bit A to D Converter, the Pulse Width Modulator, the I 2 C serial bus, and peripheral device family, the 83C552 provides minimum component count solutions for cellular radio systems, professional audio systems, and medical instrumentation products such as bedside patient monitors and analyzers for home care and sports use. January 1992 7