Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Capacitor Discharge Ignition Using The Angular Timer

Download as pdf or txt
Download as pdf or txt
You are on page 1of 34

AN1980

Capacitor Discharge Ignition Using the Angular Timer

Authors: Ashutosh Tiwari The merits of using these peripherals, by demonstrat-


ing how the challenges of the conventional design are
Shailendra Vengurlekar
overcome, are also explained. Furthermore, this appli-
Namrata Dalvi cation note provides information on the improvements
Microchip Technology Inc. realized using CIPs in terms of performance of the CDI
system and reduced usage of the CPU.
INTRODUCTION Lastly, this document offers information on multiple PIP
systems, mathematical formats and certain useful tips
The Capacitor Discharge Ignition (CDI) system is an and tricks for improving mathematical computations.
electronic ignition system used in internal combustion
engines. An ignition system provides a high-voltage
spark in the engine’s cylinders to ignite the air-fuel mix- INTERNAL COMBUSTION ENGINE
ture. The CDI system uses high-voltage capacitor dis- The internal combustion engine is a basic building
charge current output to fire the spark plug. block of an automobile, which converts the chemical
This application note briefly explains the implementa- and heat energy into mechanical energy. The air and
tion of CDI for single Profile Ignition Pickup (PIP) sys- fuel chemical mixture is burnt and extreme heat is gen-
tems using standard peripherals on an 8-bit PIC® erated expanding the exhaust gases which force the
microcontroller and the challenges associated with cylinder piston to move, causing the camshaft to rotate
such designs. It also covers the implementation of the and create a kinetic energy. This kinetic energy is cou-
CDI system using the following advanced Core Inde- pled to the vehicle’s wheels by gear trains in order to
pendent Peripherals (CIP) of PIC microcontrollers: convert the angular motion into linear motion.
• Angular Timer (AT) A four-stroke cycle engine that utilizes four distinct pis-
• Signal Measurement Timer (SMT) ton strokes, intake, compression, power and exhaust to
complete one operating cycle is shown in Figure 1.
• Math Accelerator
• Configurable Logic Cell (CLC).

FIGURE 1: FOUR-STROKE ENGINE WITH ENGINE PARTS


Exhaust
Air-fuel gases
mixture pushed out
drawn in
Valves closed Valves closed
Intake
valve
open Air-fuel Exhaust
Spark valve
mixture
Plug open
Combustion compressed
firing
Chamber

Piston

Intake Compression Power ExŚaust

 2015 Microchip Technology Inc. DS00001980A-page 1


AN1980
To burn the air and fuel mixture in the cylinder, a THE CAPACITOR DISCHARGE
high-voltage spark is generated by passing electrical
IGNITION (CDI) SYSTEM
current through a spark plug during the power phase.
This ignites the air-fuel mixture, producing a pressure The CDI system uses the current produced by a capac-
wave which forces the piston down. The momentum of itor discharge to fire the spark plugs. Figure 2 shows a
the crank shaft caused by the power stroke of the pis- basic CDI system.
tons continually moves the engine through the four
The parts that make up a CDI system are listed below.
strokes.
• High-Voltage Supply
Top dead center (TDC) is the highest position of the
piston near the spark plug and bottom dead center • Capacitor
(BDC) is the lowest position near the camshaft. After • Ignition Coil
the spark plug fires into the power stroke, the air-fuel • High-Power Switch
mixture needs some time to completely burn; this burn- • Pulser Coil
ing process is progressive in nature (i.e., the mixture at • Signal Conditioning
the top burns first and quickly moves towards the bot-
• Microcontroller
tom). Therefore, to completely burn the air-fuel mixture
and produce the maximum pressure wave, the spark
plug should be precisely fired moments before the pis-
ton reaches TDC and at the proper angle, which is
determined by the engine piston speed. There are
other factors, such as temperature and throttle position
(i.e. amount of air-fuel mixture) which also determine
the spark firing angle. To fire the spark correctly and
accurately, a separate module known as the ignition
control mechanism, is used. There are two types of
ignition systems:
• Inductive Discharge Ignition (IDI) or Transistor
Controlled Ignition (TCI)
• Capacitor Discharge Ignition (CDI)
This application note will focus on the CDI system.

FIGURE 2: BASIC CAPACITOR DISCHARGE IGNITION (CDI) SYSTEM

HV Supply
Magneto
(AC CDI)

Spark
HV Supply 300-400V Capacitor Plug
DC-DC (DC CDI) HV Supply
12V Battery Converter SCR

Pulser Coil Ignition


Coil
PWM

SCR Gate
+ Control
Pick-up signal Signal
from ƉƵůƐĞƌcoil Conditioning -

Thermistor
Throttle MCU

DS00001980A-page 2  2015 Microchip Technology Inc.


AN1980
High-Voltage Supply OFF when the input is less than the lower operating
threshold.
There are two types of CDI systems:
The Insulated-Gate Bipolar Transistor (IGBT) and the
• Alternating Current Capacitor Discharge Ignition Metal-Oxide Semiconductor Field Effect Transistor
(AC-CDI) (MOSFET) are used in modern CDI designs due to
• Direct Current Capacitor Discharge Ignition their ability to switch ON and OFF, as well as better
(DC-CDI) frequency response at higher operating ranges.
In an AC-CDI system, an alternator or stator (magneto)
generates enough power for all electronic systems Pulser Coil
including the CDI. The capacitor is charged through
rectified output of magneto AC supply, which is 200V The pulser coil or pick-up/timing coil is responsible for
DC to 400V DC. When the engine is cold (not running), providing the timing signal to the ignition control sys-
a kick-start is required to rotate both the engine and the tem. A magnet is mounted on a flywheel. The flywheel
magneto. This does not generate sufficient power from is mounted on the magneto shaft. When the flywheel
the magneto to completely charge the capacitor for a rotates, the magnet passes near the pulse coil produc-
high-voltage spark. For very low RPM, the firing angle ing a timing pulse. There is one pulse per pole. Hence,
is always constant. Hence, analog firing is used to fire for each magnet there are two outputs, one positive
at negative PIP output from the magneto-flywheel pulse followed by a negative pulse, generating one
pulser coil without calculating the RPM. alternating pulse pair. For a single PIP system, there is
only one pair. For multi-pulse systems there are multi-
In a DC-CDI system, a constant 12V DC power is ple pulse pairs, based on the number of magnets on the
always available from the battery. It requires an addi- flywheel. The alternating pulses are at a fixed angle
tional DC/DC converter circuit to raise the 12V DC to with respect to the TDC piston position in the engine for
200-400V DC. This additional circuitry makes the CDI each rotation. The period of the pulses triggers the
module slightly larger than an AC-CDI system. When rotation of the engine.
the engine is not running, it can be started easily at a
precisely calculated firing angle, as the input DC supply Based on the number of alternating pulses from the
is always available. pick-up, per engine rotation, the pulser coil system can
be divided into the following types:
Capacitor • Single PIP System
• Multiple PIP System
To create the high-voltage spark in the spark plug, a
high-voltage capacitor with a high-charge capacity is
charged using either the output of the DC/DC converter FIGURE 3: PICK-UP SIGNAL IN THE
(DC-CDI) or using the output of the magneto, an AC SINGLE PIP SYSTEM
alternator (AC-CDI). The capacitor is charged to a
high-voltage supply, usually 200V to 400V.

Ignition Coil
The capacitor is connected to an ignition coil or step-up
pulse transformer which produces a very high voltage,
in the range of 40 kV or more.

High-Power Switch
The switch is used to connect the capacitor to the pri-
mary of the ignition coil. The switch is fired when the
microcontroller gives a pulse at the gate of the switch. SINGLE PIP SYSTEM
The sudden rush of current in the primary of the coil In a single PIP system, the pulser coil provides one
produces a very high voltage in the secondary, which positive pulse followed by a negative reference pulse,
generates the spark to ignite the air-fuel mixture. Thus, as shown in Figure 3. The angle between the pulses
the microcontroller controls the firing angle of the and the angle between the negative pulse and the TDC
switch for generating the spark. are fixed. The firing of the spark should be done at a
A Silicon-Controlled Rectifier (SCR) is most commonly specific angle based on the engine operating tempera-
used as a high-power switch in CDI. It is highly durable ture, the throttle position and the RPM. This angle is
due to the higher operating voltages and current usually between the positive and the negative pulses.
ranges with moderate frequency response. The disad- The negative pulse is a reference point for firing the
vantage of the SCR is that it is a one-sided switch (i.e. spark at very low RPM. The firing angle changes to an
the switch can only be ON). It will automatically go to angle between the pulses for higher RPM.

 2015 Microchip Technology Inc. DS00001980A-page 3


AN1980
FIGURE 4: PICK-UP SIGNAL IN THE DUAL PIP SYSTEM

MULTIPLE PIP SYSTEM Microcontroller


In a multiple PIP system the pulser coil provides more In a digital CDI system the microcontroller has two
than one alternating pulse. The pick-up signal for the major functions:
dual PIP system is shown in Figure 4, along with the
TDC and the firing range. The second negative pulse is • Deciding the advance firing angle by reading input
the reference point before TDC. This is the minimum from the sensors, such as the pulser coil,
firing angle at which the spark should be generated for thermistor, and throttle position, then producing
engine speeds below a lower speed threshold. the firing pulse.
• Setting the duty cycle of pulse-width modulation
The first positive and negative pulses can be used for (PWM) for the DC to DC converter.
calculating the RPM of the engine. The second positive
pulse can be used as a reference point for deciding the The advance angle required for getting optimum perfor-
firing angle for higher speeds. mance from the engine is mainly dependent on the
RPM. Hence, the system must be aware of the current
RPM, temperature, and throttle position. Look-up
Signal Conditioning tables called MAPs are stored in the program memory
The pulser coil generates the timing signals that con- of the microcontroller, which give the appropriate
tain both positive and negative pulses. These pulses advance angles with respect to the RPM. Multiple
are in the range of ±3V to ±90V, depending on the mag- MAPs are stored based on different throttle positions
netic field strength of the magnet mounted on the fly- and for different temperature ranges. Once the control-
wheel. A signal conditioning circuit is used to invert the ler calculates the RPM, it can then look up the appro-
negative pulse and limit the pulses to a range of 0V to priate advance angle from the MAP. For details about
5V. It is also used to filter any spurious noise. The sig- the firing angle selection and an example firing MAP,
nal conditioning circuit will provide two positive outputs, refer to CDI Implementation Using AT, and Figure 12.
one corresponding to positive pulses and another for
negative pulses. Output of the signal conditioning
circuit is connected to the microcontroller.

DS00001980A-page 4  2015 Microchip Technology Inc.


AN1980
CDI IMPLEMENTATION USING TIMER, Analog-to-Digital Converter (ADC)
CAPTURE AND COMPARE MODULES An ADC is used to determine the engine temperature
(CONVENTIONAL METHOD) and the throttle position (if it is analog). Throttle position
input can be either analog or digital. In the case of a
Peripherals on PIC MCUs, such as Capture Compare digital throttle, the position for the wide open throttle
or PWM (CCP) and ADC, together with the interrupt pin (WOT) is one state and the partially open throttle (POT)
INT are used to determine the firing angle control in is another. There are distinct firing MAPs for different
CDI, as explained in the following section. throttle positions and different temperature ranges.
Figure 5 shows the conventional method for the CDI
Capture/Compare/PWM (CCP) Capture
implementation.
Mode
Output for the positive PIP signal of the signal condi-
tioning circuit is given to the capture module. The cap-
ture module measures the time between two positive
pulses (the period of the pulser coil output). The period
of the pulses gives the RPM of the engine.

FIGURE 5: CDI IMPLEMENTATION (CONVENTIONAL METHOD)

Spark
300-400V Capacitor Plug
DC-DC HV Supply
12V Battery Converter SCR

Ignition
Coil
PWM

PWM

+ CCP CCPRx
Pick-up signal Signal (Capture)
from pulsĞr coil Conditioning -
INT

SCR Gate
CDI LOGIC
Thermistor Control
ADC Map
Throttle RPM Calculation
Selection
RPM

Firing Angle to
Firing Angle
Timer Counts
Calculation
Conversion

CCP
I/O
(Compare)
PICΠ MCU

 2015 Microchip Technology Inc. DS00001980A-page 5


AN1980
CDI Logic
RPM CALCULATION
The RPM of the engine can be calculated from the external signal frequency fsignal as shown in Equation 1:

EQUATION 1: RPM CALCULATION USING TIMER1

Timer1 CLK
f = -----------------------------------------------------------------------
signal Timer1 Prescaler  CCPRx

Timer1 CLK
RPMEngine = -----------------------------------------------------------------------  60
Timer1 Prescaler  CCPRx

Where: Timer1 CLK = Clock input for Timer1 using T1CON register = Fosc/4 = 32/4 = 8 MHz
Timer 1Prescalar = Timer1 clock prescaler selected in T1CON register = 1:8 = 8
CCPRx is the captured value of Timer1 at falling edge of fsignal
fsignal is input signal frequency of the pick-up signal
60 scalar value is multiplied to convert Hz to RPM, RPMEngine = fsignal * 60

FIRING MAP SELECTION Challenges in the Conventional CDI


Every engine is associated with a firing MAP which Approach
shows the relationship between input engine speeds in
RPM and the firing angle of spark in degrees. These FIRING ANGLE TO TIMER COUNTS
MAPs vary depending on the throttle position and the CONVERSION
engine temperature. The current engine temperature After selecting the firing angle from the MAP and the
and throttle position is measured through sensors and interpolation, the firing angle has to be converted to
the firing MAP is selected by using these values. corresponding timer counts. Even if the firing angle
value is the same for the range of RPM, the corre-
FIRING ANGLE CALCULATION sponding timer counts will be different. Thus, the calcu-
If the current RPM is in between the values stored in lation of the firing angle to timer count is necessary for
the look-up table, then the firing angle for that RPM can every RPM change. If computations are not complete
be calculated using linear interpolation. before the expected firing event, a previous value of the
firing angle is used.
FIRING ANGLE TO TIMER COUNTS
CONVERSION RPM CALCULATION
The firing angle is converted to corresponding timer Conventional method of RPM calculation uses a 16-bit
counts. Timer1 along with capture peripheral. In case of lower
RPM values, less than 60 (corresponding to 1 Hz fre-
Capture/Compare/PWM (CCP) Compare quency), the 16-bit Timer1 will overflow if the timer
clock frequency is 1 MHz. The timer overflow bit should
Mode
be taken into account for RPM calculations.
The timer count corresponding to the firing angle is
stored in the CCP compare register. When the timer RESOLUTION
count and compare register values match, an interrupt The firing angle resolution is RPM dependent.
is generated. In the Interrupt Service Routine, a pulse
For example, for a Timer1 clock of 1 MHz and RPM of
is given on the digital output connected to the SCR gate
250 the angular resolution is AR = 360/Timer1 counts
to fire the SCR, and generate the spark.
for 250 RPM = 360/4000 = 0.09˚ and for 10.000 RPM
the angular resolution is AR = 360/Timer1 counts for
10.000 RPM = 360/100 = 3.6˚.

DS00001980A-page 6  2015 Microchip Technology Inc.


AN1980
CDI IMPLEMENTATION USING AT The period counter uses (ATxCLK/(ATxRES+1)) as a
clock for counting. The phase counter divides the input
The PIC16F161X family of 8-bit PIC microcontrollers periodic pulse or one cyclic rotation to equidistant
has a CIP called the Angular Timer (AT), which can be angles. The phase counter uses (ATxCLK/(ATx-
used in internal combustion engines’ to fire the spark at PER+1)) as a clock for counting. The ATxRES register
the exact firing angle with very little CPU intervention. defines the number of angular divisions per cycle. This
value is determined by the user. If the external pulse
AT frequency is reduced, the period counter value crosses
the ATxPER register that was stored during the previ-
The AT divides the incoming periodic signal (one single ous period. When the period counter value is 1.5 times
cycle) into smaller equidistant angles. This allows the of ATxPER, a missing pulse trigger is given by the AT
division of signals based on a phase angle, instead of to indicate sudden decrease in external frequency. This
time. Irrespective of the frequency of an input signal, is called missing pulse trigger in the Adaptive mode.
the division is always constant and configurable. The ATxMISS register is configured by the user to give
As shown in Figure 6, the periodic pulse input to the AT a missing pulse output at a fixed value which can be
can be selected either from the internal core indepen- used to detect errors in line frequency detection to con-
dent peripherals or from the external pin. The AT has trol generator engine speed. This is called a Fixed
two counters: the period counter and the phase Missing Pulse mode.
counter. The period counter counts the length of the The AT has no output, but it generates an interrupt at
external periodic pulse which is stored in the ATxPER every period pulse, phase pulse, and missing pulse.
register after every external pulse.
The AT can be configured for either Single or
Multi-Pulse mode.

FIGURE 6: AT BLOCK DIAGRAM IN SINGLE-PULSE MODE

Rev. 10-000245A
ATxRES 1/21/2015

15
Set PERIF
SSEL Divide by Period
ATxRES+1 Counter
R R
ATx_perclk
PRP
LC4_out 111
PREC 15
LC3_out 110 ATxMISS
LC2_out 101
+ Divide by 2
LC1_out 100 Sync ATxsig LD ATxPER Difference
ZCD1_out 011 (2 Clocks)
-
15
C2OUT_sync 010 1 0 APMOD
C1OUT_sync 001
PPS 000 MPP ATx_missedpulse
Comparator
ATxINPPS
PHP
PS 1 Clock
CS Delay
ATx_phsclk
HFINTOSC (16 MHz) 1 Divide by Phase
Prescaler ATxclk
FOSC 0 ATxPER+1 Counter
R R Set PHSIF
ATxclkcc

10

To Capture/
Compare
Instruction
LD ATxPHS
Clock

 2015 Microchip Technology Inc. DS00001980A-page 7


AN1980
FIGURE 7: SINGLE-PULSE MODE TIMING DIAGRAM

Period
fsignal

AT Phase Pulse

ATxPER

AT Period Pulse

360°

ATxPHS

SINGLE-PULSE MODE
In Single-Pulse mode, every external pulse is a period pulse which determines one complete cycle or rotation of 0 to 2π
(360), as shown in Figure 7. The phase pulse output depends on the previous period value, since the period register
(ATxPER) only updates once every period.
The AT uses the clocks in Equation 2 for the period and phase counter.
EQUATION 2: AT CLOCKS
AT clock
AT = -------------------------------
periodClock ATxRES + 1

AT clock
AT = -------------------------------
phaseClock ATxPER + 1

Where ATclock is AT input clock given by


ATxCLK
AT clock = ----------------------------------
AT Prescalar

Where: ATxCLK is the clock selection using the ATxCLK register.


ATPrescalar is the AT clock prescaler value.
ATxRES is the AT resolution register set by the user, determines the number of angular divisions per
cycle.
ATxPER is the period counter value for one complete period cycle of the external signal fsignal (input
periodic pulse signal).

The instantaneous values of ATxPER and ATxPHS in Single-Pulse mode can be calculated as shown in Equation 3.
EQUATION 3: ATxPER AND ATxPHS IN SINGLE-PULSE MODE
AT periodClock ATxCLK
ATxPER = ---------------------------------------- = -----------------------------------------------------------------------------------------------------
f AT   ATxRES + 1   f
signal Prescalar signal
ATphaseClock ATxCLK
ATxPHS = -------------------------------------- = -----------------------------------------------------------------------------------------------------
f AT   ATxPER + 1   f
signal Prescalar signal

DS00001980A-page 8  2015 Microchip Technology Inc.


AN1980
Maximum phase value in the ATxPHS counter in the case of Single-Pulse mode will be equal to ATxRES (angular
resolution), as indicated in Equation 4.

EQUATION 4: ATxPHS MAXIMUM PHASE VALUE

ATxPHS = ATxRES = AR – 1
max
Where: ATxPHSmax is maximum value of the AT phase register.
ATxRES is value configured in the AT angle resolution register.
AR is the desired angular resolution.

EXAMPLE 1: AT REGISTER VALUES IN SINGLE-PULSE MODE

Suppose, ATxCLK = 32 MHz, ATPrescalar = 1:1 = 1, AR = 360˚, fsignal = 250 Hz.


Hence, ATxRES = AR-1= 359, as shown below:

32000000
ATxPER = ----------------------------------------------- = 355.55555555556  355 and
1   359 + 1   250
32000000
ATxPHS = ----------------------------------------------- = 359.55  360
1   355 + 1   250

MULTI-PULSE MODE
In AT Multi-Pulse mode, the input signal contains more than one pulse per cycle, as shown in Figure 9 as fsignal.

FIGURE 8: AT BLOCK DIAGRAM IN MULTI-PULSE MODE

Rev. 10-000246A
ATxRES 1/21/2015

15

SSEL Divide by Period Set PERIF


ATxRES+1 Counter
R R

PREC ATx_perclk
LC4_out 111 PRP
15
LC3_out 110 ATx_missedpulse ATxMISS
ATxperiod
LC2_out 101
+ Divide by 2
LC1_out 100 Missing ATxsig
ATx_in
Pulse Period LD ATxPER Difference
ZCD1_out 011 Trigger -
15
C2OUT_sync 010 1 0 APMOD
C1OUT_sync 001
PPS 000 MPP ATx_missedpulse
Comparator
ATxINPPS
PHP
PS 1 Clock
CS Delay
ATx_phsclk
HFINTOSC (16 MHz) 1 ATxclk Divide by Phase
Prescaler
FOSC 0 ATxPER+1 Counter
R R Set PHSIF
ATxclkcc

10

To Capture/
Compare
Instruction
LD ATxPHS
Clock

 2015 Microchip Technology Inc. DS00001980A-page 9


AN1980
FIGURE 9: MULTI-PULSE MODE TIMING DIAGRAM

Period

fsignal

AT Phase Pulse

AT Missing Pulse

AT Period Pulse

ATxPER

360°

ATxPHS

To determine the period of input signal, the signal must Since the ATxPER value resets every external pulse
have at least one missing pulse. As indicated in except for the pulse after the missing pulse, the ATx-
Figure 9, there are five signal pulses with one missing RES should be chosen so that ATxPHS should not
pulse which makes it six pulses per period. A missing cross the maximum count of 1024 (10-bit register which
pulse is generated by the AT when no pulse is detected is 210).
after the fifth one. After the missing pulse, the first rising A Multi-Pulse mode example, Example 2, shows
edge on fsignal gives the AT period pulse output. Hence, choosing the resolution register (ATxRES) value for the
the missing pulse and the period pulse have exactly the required angular resolution (AR).
same length. The ATxPER register updates on every
rising edge of the external pulse, except for the pulse The instantaneous values of period and phase regis-
immediately following the missing pulse. This helps ters in Multi-Pulse mode can be given as shown in
ATxPHS to correct itself according to ATxPER after Equation 5.
every rising edge in order to output phase pulses
correctly within the same period.

EQUATION 5: ATxPER AND ATxPHS IN MULTI-PULSE MODE

ATxCLK
ATxPER = --------------------------------------------------------------------------------------------------
AT f   ATxRES + 1 
Prescalar pulse

ATxCLK
ATxPHS = -------------------------------------------------------------------------------------------------------------------------
AT f   ATxPER + 1 
Prescalar Mis sin gPulse

Where: fpulse is the pulse frequency in a period signal.


fmissingPulse is the missing pulse frequency of AT, which is same as fsignal.

DS00001980A-page 10  2015 Microchip Technology Inc.


AN1980
So, the relationship between maximum counts of ATxPHS with respect to ATxRES can be determined, as demonstrated
in Equation 6.

EQUATION 6: MAX ATxPHS VALUE FOR MULTI-PULSE MODE

 fpulse 
ATxPHS = ATxRES   -------------------------------------
max  f mis sin gPulse

As a result, the value of ATxRES will be different for the same angular division or angular resolution (AR) in the Multi-
Pulse mode compared to the Single-Pulse mode. See Equation 7.

EQUATION 7: ATxRES CALCULATION FOR MULTI-PULSE MODE

 f mis sin gPulse  T pulse 


ATxRES = AR   ------------------------------------- – 1 = AR   --------------------------------------- – 1
 f pulse  T
 mis sin gPulse

Where: Tpulse = 1/fpulse and TmissingPulse = 1/fmissingPulse.

Using the above value of ATxRES and Equation 5, the values of ATxPER and ATxPHS can be calculated as indicated
in Example 2.

EXAMPLE 2: AT REGISTER VALUES IN MULTI-PULSE MODE

Suppose, ATxCLK = 32 MHz, ATPrescalar = 1:1 = 1, AR = 360˚.


fsignal = fmissingPulse = 250 Hz and fpulse = 2500 Hz;
Hence, using Equation 7 the below results will be obtained:

250 360
ATxRES = 360  ------------ – 1 = --------- – 1 = 36 – 1 = 35
2500 10
32000000
ATxPER = ----------------------------------------------- = 355.55555555556  355
1  2500   35 + 1 

32000000
ATxPHS = ----------------------------------------------- = 35.955  35
1  250   355 + 1 

CAPTURE AND COMPARE FUNCTIONS Compare Mode


The AT has three capture/compare modules along with In the Compare mode, the AT module compares the
it. current phase counter value (ATxPHS) to the value in
the compare register (ATxCCy). The compare register
Capture Mode (ATxCCy) can be loaded with an angle value which is
In Capture mode, on the rising or on the falling edge of less than or equal to the angular resolution AR (ATx-
the capture input signal, the value of the phase counter RES) in the Single-Pulse mode. When the two values
(ATxPHS) is captured into the capture register match, a compare event is generated. This can be
(ATxCCy). used to trigger other peripherals such as an ADC or a
CLC input, or to generate an interrupt.
The capture event also generates a pulse that can be
used to trigger other peripherals such as an ADC or a
CLC input, or to generate an interrupt.

 2015 Microchip Technology Inc. DS00001980A-page 11


AN1980
CDI Implementation with AT SIGNAL MEASUREMENT TIMER (SMT)
Figure shows the AT with Core Independent Peripher- For the RPM calculation, a 24-bit SMT is used. SMT is
als (CIPs) in PIC16F1619/5 for the implementation of configured in Windowed Measurement mode with the
the CDI system. window input set to AT period pulse. Whenever AT
gives period pulse, the SMT captures the timer value
CIPs of PIC microcontrollers, such as CLC, AT, SMT, into SMTxCPR register, resets its timer count, and
and Math Accelerator are used for the firing angle restarts counting. The timer capture into the SMTxCPR
control in CDI. register generates a captured period interrupt.
CONFIGURABLE LOGIC CELL (CLC) ADC
The outputs of the signal conditioning circuit are con- An ADC is used to find the engine temperature and the
nected to the CLC. The outputs of the signal condition- throttle position (if it is analog). Throttle position input
ing circuit will be in logic 1 state except for the positive can be either analog or digital. In the case of a digital
and negative pulses from the pick-up coil. The CLC is throttle position, the wide open throttle (WOT) is one
configured as an XOR gate, so that the CLC output will state and the partially open throttle (POT) is another.
give positive pulses for both inputs, as shown in There are different firing MAPs for different throttle
Figure 11. The CLC output is connected to the AT input positions and different temperature ranges.
internally. The AT will provide a period pulse to SMT.

FIGURE 10: CDI IMPLEMENTATION WITH PIC16F161X

Spark
200-400V Capacitor Plug
DC-DC HV Supply
12V Battery Converter SCR
Ignition
Coil
PWM
SCR Gate
Control
CWG I/O

Angular Timer

Capture
+
Phase
Pick-up signal Signal Compare
from pulser coil Conditioning - CLC AT
Input ATxCCy

AT Period Pulse
Firing Angle
SMT SMTxCPR

CDI LOGIC
Thermistor
ADC Map RPM
Throttle Selection Calculation
RPM
Firing Angle
Calculation

Math Accelerator
PIC16F161x MCU

DS00001980A-page 12  2015 Microchip Technology Inc.


AN1980
CDI LOGIC

RPM Calculation
The RPM of the engine can be calculated from the
external signal frequency fsignal as shown in
Equation 8.

FIGURE 11: SIGNAL CONDITIONING OUTPUT

TDC
+5to15V +ve
Period
Advance
pulse
Pick-up Signal
Pulser output -ve
Reference
-5to15V pulse
Input signals +5V
to p_PIP
MCU After
signal +5V
n_PIP
conditioning

CLC (XOR) output

AT Period Pulse

EQUATION 8: RPM CALCULATION USING SMT

SMTxCLK
fsignal = ------------------------------------------------------------------------
SMT Prescalar  SMTxCPR

SMTxCLK
RPM = ------------------------------------------------------------------------  60
Engine SMT  SMTxCPR
Prescalar

Where: SMTxCLK = clock input for SMT using SMTxCLK register= Fosc = 32 MHz.
SMTPrescalar = SMT clock prescaler selected in SMTxCON0 = 1:8 = 8.
SMTxCPR is captured value of SMTxTMR at window input event.
fsignal is input signal frequency to AT and SMT.
60 scalar value is multiplied to convert Hz to RPM, RPMEngine = fsignal * 60.

 2015 Microchip Technology Inc. DS00001980A-page 13


AN1980
Firing MAP Selection
Every engine is associated with a firing MAP which
shows the relation between the input engine speeds in
RPM and the firing angle of the spark in degrees.
These MAPs vary depending on throttle position and
engine temperature. The current temperature of the
engine and the throttle position can be used to select
one of the firing MAPs.The MAP is nonlinear in nature
and nondeterministic, which can change from engine to
engine. Hence, these MAPs are divided into smaller lin-
ear MAPs (piecewise linear curves) and are expressed
in terms of a table with RPM on LHS and firing angle on
RHS.

FIGURE 12: EXAMPLE OF RPM TO


FIRING ANGLE (THETA)
MAP

Figure 12 shows an example of a firing map. This firing


MAP is a plot of a piecewise linear curve. Here, the red
curve shows the RPM to firing angle relationship for
throttle OFF and the blue curve shows RPM to firing
angle relationship for throttle ON.

Firing Angle Calculation


To find the firing angle of an engine between two points
in the MAP, linear interpolation is used as follows:

EQUATION 9: FIRING ANGLE CALCULATION USING LINEAR INTERPOLATION

y 2 – y1
y = y +  x – x   -----------------
1 1 x –x
2 1

Where: y is the instantaneous value of the firing angle to be calculated, which is in between y1 and y2.
x is the instantaneous value of engine RPM which is known and in between x1 and x2.
(x1, y1) and (x2, y2) are the successive points in the graph between which a line is drawn these are
shown as row 1 and row 2 in the firing map table, respectively.
x1 and x2 represent values of Engine RPM of two endpoints. y1 and y2 represent the values of the
firing angle of two endpoints of a straight line curve.

In Equation 9, the ratio ((y2-y1)/(x2-x1)) is always con-


stant and is called slope m of a straight line. This can
be pre-calculated for a curve to reduce the amount of
calculation.

DS00001980A-page 14  2015 Microchip Technology Inc.


AN1980
For example, Table 1 is the firing map given by the MATH ACCELERATOR
engine specifications. The values in the column “Slope”
The math accelerator peripheral, also called a PID
are calculated from the previous two column values,
module, is used to calculate the firing angle for the cur-
and are called line slopes.
rent RPM using Equation 9. Using the math accelera-
TABLE 1: Firing Map for Example Engine tor, the calculation can be done faster. It performs an
Engine Speed Firing Angle Slope addition and a multiplication as shown in Equation 10.
(RPM) (θ°) (m)
EQUATION 10: MULTIPLY/ADD OPERATION
250 10 0 IN MATH ACCELERATOR
500 10 0
R = A + B  C
1600 10 0
1800 10 0.075 Where:
2000 25 0.012 A is the first input operand for addition
(PIDxIN register).
2500 31 0
B is the second input operand for addition
4100 31 0 (PIDxSET register).
4200 31 0 C is the third input operand for multiplying
with the result of addition (PIDxK1
5100 31 0
register).
5200 31 0 R is the results of one complete add and
5900 31 0 multiply operation (PIDxOUT register).
8500 31 -0.042
9000 10 0 The math accelerator performs these operations in
16-bit integer, either in signed or unsigned format, con-
10000 10 0
figured by the user. The result of this operation is 32-bit
in size, and is stored in the PIDxOUT register. The
EXAMPLE 3: FIRING ANGLE result of this operation can be configured to be accu-
CALCULATION USING mulated or non-accumulated. For accumulation of the
INTERPOLATION result, the PIDxACC register is used to accumulate
previous results.
Suppose, RPMEngine = 1915 rpm.
AT
From Table 1, this RPM value lies between 1800
rpm (with a firing angle of 10˚) and 2000 rpm (with Depending on the angular resolution settings in the res-
a corresponding firing angle of 25˚). olution register (ATxRES) the AT will start counting. AT
will divide the input signal into equidistant angles. The
Thus, from Equation 9, the terms are as follows:
phase counter (ATxPHS) is incremented accordingly.
y1 = 10, y2 = 25, x1 = 1800, x2 = 2000, x = 1915
The result is shown below: Selecting the ATxRES Value of the AT for CDI
Implementation
25 – 10
y = 10 +  1915 – 1800   ------------------------------ = 18.625  18 The granularity of the phase counter is called angle
2000 – 1800
resolution. The value in the ATxRES register is used to
determine the angle resolution of the AT phase counter.
Thus, the firing angle for the given RPM of 1915 is 18˚.
The angle resolution can be achieved through
Equation 11 below.

EQUATION 11: ANGLE RESOLUTION


360 
Angle Resolution = -------------------------------
ATxRES + 1

In the AT, the period is measured in increments of ATx-


RES. For smaller ATxRES values, the ATxPER values
will be high. AT truncates the actual period value in
order to load the value in the period register (ATxPER).
For a smaller percentage of error, the higher ATxPER
value is required.

 2015 Microchip Technology Inc. DS00001980A-page 15


AN1980
The figure of merit (FOM) for the system is defined as
the minimum expected ATxPER value. For error to be
less than 0.2%, FOM should be as per Equation 12.

EQUATION 12: FIGURE OF MERIT

1 1
FOM = 100  --------------- = 100  ------- = 500
Error 0.2

Therefore, it is recommended that the AT clock and res-


olution (ATxRES) be chosen so that the minimum
expected ATxPER value (FOM) corresponding to the
highest RPM will be greater than 500.

EXAMPLE 4: ATxRES CALCULATIONS

Consider the following values:


Maximum engine RPM = 10000
fsignal = RPM/60= 10000/60 = 166.66 Hz
ATxCLK = 32 MHz
ATPrescalar = 1:1
ATxPER is given by
ATxCLK
ATxPER = ------------------------------------------------------------------------------------------------------------------------------
min AT
Prescalar
  ATxRES
max
+ 1  f
signal_max

So, for a FOM of 500 (ATxPERmin), ATxRESmax will be as shown below:

ATxCLK 32000000
 ---------------------------------------- 
ATxRES = -------------------------------------------------------------------------------------------------------------- – 1 =  1  500  166.66- – 1 = 383
max AT
Prescalar
 ATxPER f
min signal_max

It is preferable to select the value of ATxRES smaller than ATxRESmax.


If ATxRES is chosen as 359°, to get an angle resolution of 1° the minimum ATxPER value (FOM), corresponding
to the highest RPM will be as shown below:

ATxCLK 32000000
ATxPER = ------------------------------------------------------------------------------------------------------------------ = ----------------------------------------- = 533.33
AT Prescalar   ATxRES + 1   fsignal_max 1  360  166.66

LOW RPM CORRECTION


From zero RPM to very low RPM, the AT period counter
can overflow due to the limited size of the AT period
counter, which is 15 bits in length. The value in this AT
period counter will be high for lower RPM counts.
Therefore, a sufficiently low clock needs to be chosen
for the AT input, so that lower RPM can also be taken
into consideration. As a result, the minimum value of
RPM is 60, as calculated in Example 5. Decreasing the
AT input clock frequency and increasing the AT clock
prescalar would result in less accuracy of angular divi-
sions, but this design trade-off is necessary here to
take lower RPM into account.

DS00001980A-page 16  2015 Microchip Technology Inc.


AN1980
EXAMPLE 5: LOW RPM CORRECTION

Suppose ATxCLK = 32 MHz, ATxRES = 60, ATxPER max = 32767 (15-bit counter), hence fmin is calculated as
shown below:

ATxCLK
f min = -------------------------------------------------------------------------------------------------------------------
AT Prescaler   ATxRES + 1   ATxPERmax

As a result, for the case above with ATPrescalar = 1, fmin is 16.27 Hz or 976 RPM.
To include lower RPM, if ATxCLK = 16 MHz and ATPrescalar = 8 are selected, the value will be calculated as
follows:
16000000
f min = ------------------------------------ = 1.017 Hz  60 RPM
8  60  32767

SCR/IGBT FIRING
The calculated firing angle is loaded into the AT com-
pare register. When the value in the compare register
matches the AT phase counter, a compare interrupt is
generated and IGBT or SCR is fired, as shown in
Figure 13. In case of IGBT, another compare register is
used to switch off the firing.

FIGURE 13: TIMING DIAGRAM FOR SCR FIRING

TDC
+5to15V +ve
Period
Advance
pulse
Pick-up Signal
Pulser output -ve
Reference
-5to15V pulse

CLC (XOR) output

AT Period Pulse

360°
ATxPHS
Phase Counter

Advance Angle ΘA

SCR/IGBT trigger Θ=ΘA-ΘF


from MCU
Firing
Angle ΘF
TDC

 2015 Microchip Technology Inc. DS00001980A-page 17


AN1980
COMPLEMENTARY WAVEFORM
GENERATOR (CWG)
The CWG is used to generate a single or complemen-
tary sine wave modulated PWM signal for the DC to AC
inversion. This inversion is required to convert 12V DC
from battery to 220V AC RMS which is rectified again
to generate 300V DC. This 300V DC is used to charge
the CDI capacitor. A complementary PWM can be used
to make full-wave inversion while a single PWM only
makes half-wave inversion. For very small engines,
only half cycle is enough to charge the capacitor where
RPM is very low, i.e., chainsaws, lawn mowers, etc.

FIRMWARE
Firmware flowchart is shown in Figure 14.

FIGURE 14: FIRMWARE FLOWCHART

Start

Initialize

NO

SMT1 Int? & ADC Int? & AT period Int? NO AT1CC1 Int? NO AT1CC2 Int?
NO NO FAU = 1? NO
FAU = 3? FAU = 2? & FAU = 0?
NO
YES YES
Y ES YES YES YES
YES
Calculate RPM Select Firing Map Ignition coil Ignition coil
from SMT timer Mode = Mode = using Temperature Set Switch ON Switch OFF
NO
Thermister? Throttle? and Throttle AT1CC1 = On Firing Angle
AT1CC2 = Off Firing Angle
Set FAU = 2
YES YES
Get ON and OFF
Convert ADC to Convert ADC Set FAU = 3
firing angles
Temperature to Throttle
from MAP

ADC channel = ADC channel =


Throttle Temperature
Set FAU = 0
Mode = Mode =
Throttle Thermister

Set FAU = 1

Note 1: FAU is a firing angle update variable which keeps track of the firing angle calculation step number.
When it is done, update the ON and OFF firing angles.
2: The ADC will sample the engine temperature and the throttle position for each AT period pulse. These
will be taken as current parameter values, and a firing map is selected based on these values.

DS00001980A-page 18  2015 Microchip Technology Inc.


AN1980
Program Flow
The program execution is sequentially divided into a
number of steps to compute the RPM and firing angle
as explained below:
1. Initialize: The board is powered on or reset; all
the peripherals (ADC, PID, CWG, CLC1, SMT1
and AT1) are initialized.
2. Input Acquisition: The CLC1 takes two inputs
to generate one XORed output connected to AT
input. AT starts counting and gives period pulses
periodically. This AT period pulse is used by
SMT as window input in “Windowed Measure
mode”. The SMT at every AT period input
captures the value of the SMT1TMR register to
the SMT1CPR register and a corresponding
interrupt is generated. The program is notified
about a new SMT value available for calculation.
This is the acquisition step.
3. ADC: The analog output of the sensor for
engine temperature and throttle position is
digitized by an internal 10-bit ADC.
4. RPM calculation: The RPM of the engine is
calculated from the SMT1CPR register value.
5. MAP selection: Using temperature and throttle
position values, a particular MAP is selected.
From this selected MAP, the firing angle
corresponding to the present RPM is read from
the look-up table. If the current RPM is between
the values stored in the look-up table, the firing
angle for that RPM is calculated using
interpolation.
6. Firing Angle Update: The firing angle value is
stored in the AT compare register (AT1CCy).
7. AT compare interrupt: In the AT compare ISR
a pulse is given on the port pin connected to
SCR/IGBT gate to turn ON the switch for firing
the spark. If the IGBT is used, another ATxCCy
register is used to switch OFF the IGBT.
8. Steps 2 through 7 are repeated every AT period
cycle.

 2015 Microchip Technology Inc. DS00001980A-page 19


AN1980
COMPARISON BETWEEN CDI USING Overall Comparison
THE AT, AND CDI USING THE The maximum frequency of the input pick-up signal to
CONVENTIONAL APPROACH the CDI system can be 500 Hz, corresponding to
30000 RPM (500 Hz or 2 ms period). Within this period
Firing Angle to Timer Counts Conversion of 2 ms, the CDI operation must finish all of the execu-
tion and calculations. Considering PIC16F devices for
When the conventional method is used, the firing angle both the conventional method and that using the AT,
has to be converted to corresponding timer counts. which has eight MIPS of execution speed at 32 MHz,
Whereas the firing angle value obtained from the MAP the comparison table below shows the CPU usage for
can be written directly to AT compare register. When both systems.
the angle value matches, it generates an interrupt and
The MIPS can be calculated as indicated in
the SCR can be fired. There is no CPU intervention
Equation 13.
because the AT is a separate on-chip peripheral.
EQUATION 13: MIPS CALCULATION
Interpolation Calculation for Firing Angle
For the conventional method, the interpolation calcula- MIPS Total
tion of the firing angle and its conversion to timer count MIPS = -----------------------------  T
Actual T Execution
calculation take a longer time. MIN

When using the math accelerator, the firing angle inter-


polation calculation can be expedited. Where: MIPSActual is the calculated MIPS for
current program execution
RPM Calculation TMIN is the minimum input period which
is 1/fMAX i.e. inverse of minimum input
When the conventional method is applied, there is the signal frequency
possibility of a timer overflow at lower RPM. MIPSTotal is the max MIPS of the device
SMT is a 24-bit timer. If used for RPM calculations with TExecution is the actual execution time of
a clock frequency of 1 MHz, it can count until 0.125 Hz program
(7.5 RPM) without overflowing.

In the case above, the TMIN = 2 ms and MIPSTotal = 8.


Resolution
And CPU usage, based on maximum MIPS, is given as
The angular resolution varies with RPM in the case of shown in Equation 14, below.
conventional methods using the timer, capture and
compare peripherals. Whereas the desired resolution EQUATION 14: % CPU USAGE
of the firing angle can be directly loaded into the reso-
lution register (ATx RES) of the AT. For a resolution of MIPS
Actual
1°, the resolution register is loaded with a value of 359, %CPU = --------------------------------  100
USAGE MIPS
in the case of Single-Pulse mode. The angular resolu- Total
tion is independent of the RPM of the engine.

TABLE 2: TIMING COMPARISON


CDI Using the Angular Timer CDI Using the Conventional Method
Program
Operations Execution % CPU Execution Time % CPU
MIPS MIPS
Time (µs) Usage (µs) Usage
Long Division 150 0.6 7.5 200 0.8 10
(includes extra time for the T1 count over-
flow value inclusion in the calculation)
Firing Angle 150 0.6 7.5 350 1.4 15.5
Calculation (using Math
Accelerator)
T1 count to degree 0 0 0 200 0.8 10
ISR and other 50 0.2 2.5 50 0.2 2.5
program commands
Total 350 1.4 17.5 800 3.2 40

DS00001980A-page 20  2015 Microchip Technology Inc.


AN1980
Table 3 summarizes the resource comparisons of the two methods for CDI implementation.

TABLE 3: RESOURCE COMPARISON


CDI Using the CDI Using the
Parameters
AT Conventional Method
Flash Memory (Words) 1994 3347
RAM (Bytes) 65 233
Peripherals Used ADC, CLC, AT, SMT, Math Accelerator, CWG ADC, CCP, Timer 1, PWM

Table 4 summarizes the performance comparisons of the two methods for CDI implementation.

TABLE 4: PERFORMANCE COMPARISON


Parameters CDI Using AT CDI Using conventional Method
Accuracy Depends on FOM and the ATxRES Depends on engine speed (i.e., RPM and granularity of timer
value count for firing angle calculation).
Resolution Minimum 0.35˚ resolution (i.e., 10 Depends on Timer1 clock and RPM (i.e., for 1 MHz clock, 250
bit) ATxRES value RPM, the angular resolution is 0.09˚, and for 10000 RPM the
angular resolution is 3.6 ˚).

CONCLUSION
CDI systems can be implemented using PIC16F micro-
controllers either through the conventional method or
by using CIPs, such as AT, CLC, SMT, Math Accelera-
tor, and CWG. However, using the CIPs greatly
improves the overall performance and implementation
of CDI.
The AT successfully divides the input signal to angular
division without CPU intervention, which helps to boost
performance by removing the need for firing angle con-
version from degree to equivalent time. These angular
divisions are also very accurate and constant through-
out the input signal range. As shown in the comparison
tables (Table 2 through Table 4) of this document, the
performance of the CDI system can be greatly
enhanced using the AT, with significant CPU bandwidth
remaining for other calculations. In addition, with the
use of the Math Accelerator, the calculations are now
more accurate and faster. The SMT with its inherent
high-bit resolution helps in tracking low engine RPM
and taking necessary action, without the need for large
computations. Albeit being outside the scope of this
application note, a similar implementation technique
can be extended to other systems, such as inductive
discharge ignition (IDI), that use the same CIPs.

 2015 Microchip Technology Inc. DS00001980A-page 21


AN1980
APPENDIX A: CDI
IMPLEMENTATION
WITH MULTI PIP
SYSTEM
If the pick-up signal from the pulser coil consists of
more than one pulse per period, then AT Multi-Pulse
mode should be used. The example of multi-pulse
output is shown in Figure 4.
The implementation of the CDI system for both Single
and Multi-Pulse modes is the same, except for the con-
figuration of the AT mode and the ATxRES register
value, which is explained in the Multi-Pulse mode sec-
tion of CDI Implementation Using AT (Equation 7). LSb
in the AT1CON0 register should be set to 1 for the
Multi-Pulse mode.
The RPM calculation, MAP selection, and firing angle
calculations are all the same. The value to be loaded in
the ATxCCy register is also the same, and it is noted as
such in the Equation A-1 below.

EQUATION A-1: AT COMPARE MODULE


VALUE CALCULATION

ATxCCy =  – 

Where:  is the angle of positive pulse with


respect to TDC in an anticlockwise
rotation.
θ is the calculated firing angle in an
anticlockwise rotation.

In Single or Multi-Pulse mode, the φ represents the


angle where the pulser coil gives the first positive pulse
at an angle before TDC and after BDC in a
counterclockwise direction.

DS00001980A-page 22  2015 Microchip Technology Inc.


AN1980
APPENDIX B: FIRING ANGLE
CALCULATION WITH
Q15 NUMBER
FORMAT AND MATH
ACCELERATOR
Equation 9 of the firing angle calculation requires one
addition, three subtractions, one division, and one mul-
tiplication operation per external signal cycle for imple-
mentation. In 8-bit MCU, these arithmetic operations
might require quite a long time to finalize. To minimize
the number of computations, the slope value can be
pre-calculated in firing angle calculation as shown in
Table 1. Hence, Equation 9 can be represented as
shown in Equation B-1:

EQUATION B-1: LINEAR INTERPOLATION

y = y1 +  x – x 1   m

Where: m = (y2–y1)/(x2–x1).
m is the slope of straight line between
(x1, y1) and (x2, y2).

As seen from Table 1, the value of m can be smaller


than 1 which requires Equation B-1 to be calculated
using the floating point math. In 8-bit MCU, this math
can take significant amount of time. To ease this calcu-
lation, the Q15 number format is used. In Q15 format,
every number is divided with the max value of that
parameter type and then multiplied with the maximum
value of 16-bit signed integer (i.e., 32767). This brings
the number to a 16-bit numeral form. This technique is
also called normalization.
Now, the normalized Q15 number can be used in cal-
culation and integer math can easily be used. When all
calculations are finished, the result of the operation is
converted back to normal units.

EXAMPLE B-1: FIRING ANGLE CALCULATION IN Q15 FORMAT


Suppose, RPMMAX = 30660, fMAX = RPMMAX/60 = 511
θMAX = 63 (Maximum firing angle)
Applying Q15 on RPM = 10000 and FiringAngle = θ = 25, the following string of equations is obtained:

RPM 10000
f = ------------- = --------------- = 166.666667  167
60 60
f 167
f = --------------  32767 = ---------  32767 = 10687.21461  10687
Q15 f MAX 511

 25
 = ----------------  32767 = ------  32767 = 13002.77778  13002
Q15  MAX 63

Applying the above formulas, Table 1 can be written as Table B-1 below.

 2015 Microchip Technology Inc. DS00001980A-page 23


AN1980
TABLE B-1: FIRING MAP REPRESENTED IN Q15 FORMAT
fsignal Firing Angle (θ˚ to
Slope (m ˚/Hz)
(Hz to Q15) Q15)
267 5201 0
534 5201 0
1710 5201 0
1924 5201 37
2137 13003 6
2672 16123 0
4382 16123 0
4489 16123 0
5450 16123 0
5557 16123 0
6305 16123 0
9084 16123 -20
9618 5201 0
10687 5201 0
The slope value in Table B-1 is calculated from the Q15
formatted firing map values and not from the actual
RPM and firing angle values. To calculate the actual fir-
ing angle from Table B-1, Equation B-1 can be used,
with some modifications:

EQUATION B-2:

y1 + x –x  m 
Q15  Q15 1 Q15 MAX
y = -------------------------------------------------------------------------------------------------------
Q15
MAX

DS00001980A-page 24  2015 Microchip Technology Inc.


AN1980
EXAMPLE B-2: FIRING ANGLE CALCULATION IN Q15 FORMAT WITH CONVERSION FROM Q15
TO DEGREES

By using the values given in Example 3 and performing Q15 calculations, the following results are obtained.

RPM 1915
f = ------------- = ------------ = 31.91666667  32
60 60
f 32
f Q15 = --------------  32767 = ---------  32767 = 2046.6  2046
f MAX 511

 10
 Q15 = ----------------  32767 = ------  32767 = 5201.111111  5201
 MAX 63

Hence, from Table B-1 and the above calculated values, the results are shown here:
y1Q15 = 5201, xQ15 = 2046, x1Q15 = 1924, m = 37, Q15 MAX = 32767. Using Equation B-1 y can be calculated as
shown:

 5201 +  2046 – 1924   37   63


y = ---------------------------------------------------------------------------------- = 18.6787  18
32767

These results match the results in Example 3, Firing


Angle Calculation Using Interpolation.
The integer math above can easily be done with the
Math Accelerator. The result in the above example con-
tains Equation 10 operation twice. The first multiply/
add operation is [(2046-1924)x37] in numerator. The
second multiply/add operation is adding the result of
the first operation to 5201, which is multiplied by 63.
The final output of the second operation can then be
shifted logically to the right 15 times to make the
division by 32767.

 2015 Microchip Technology Inc. DS00001980A-page 25


AN1980
APPENDIX C: TIPS AND TRICKS TO TABLE C-1: EXPANSION OF TABLE 1 FOR
REMOVE EVERY 1˚ CHANGE IN FIRING
ANGLE (CONTINUED)
INTERPOLATION
CALCULATION Engine Speed Range Firing Angle
(RPM) (θ˚)
The interpolation operation in Equation B-1 takes a
8596-8619 26
long time to finalize due to the inclusion of one division
and one multiplication operation, since these opera- 8620-8642 25
tions are implemented using an emulator in an 8-bit 8643-8666 24
MCU. To increase the speed of execution of the CDI
program, the interpolation operation can be replaced 8667-8690 23
by a firing angle look-up table. For this, Table 1 can be 8691-8714 22
implemented as a look-up table for 1˚ change in firing 8715-8738 21
angle and the left hand side will contain the range of
RPM values for that firing angle. Below is Table 1 8739-8761 20
expanded as a look-up table. 8762-8785 19
8786-8809 18
TABLE C-1: EXPANSION OF TABLE 1 FOR
EVERY 1˚ CHANGE IN FIRING 8810-8833 17
ANGLE 8834-8857 16
Engine Speed Range Firing Angle 8858-8880 15
(RPM) (θ˚) 8881-8904 14
250-1813 10 8905-8928 13
1814-1826 11 8929-8952 12
1827-1839 12 8953-8976 11
1840-1853 13 8977-10000 10
1854-1866 14 This method increases the performance of the CDI pro-
1867-1879 15 gram by simply finding the firing angle against the
range of RPM at the cost of requiring more Flash mem-
1880-1893 16 ory. If enough memory is available for implementing all
1894-1906 17 the MAPs as a look-up table, and performance is of
1907-1919 18 prime importance, the above look-up table method can
be used. For example, for a RPM value of 1915, the fir-
1920-1933 19 ing angle from Table C-1 is 18˚.
1934-1946 20
1947-1959 21
1960-1973 22
1974-1986 23
1987-1999 24
2000-2083 25
2084-2166 26
2167-2249 27
2250-2333 28
2334-2416 29
2417-2499 30
2500-8500 31
8501-8523 30
8524-8547 29
8548-8571 28
8572-8595 27

DS00001980A-page 26  2015 Microchip Technology Inc.


AN1980
APPENDIX D: ENGINE AND
VEHICLE SPEED
CALCULATION
The engine speed is calculated from Equation 8 which
is in Hz or RPS (rotations per second). This value is
multiplied by 60 to convert it to engine speed (RPM).
This rotation per second or speed in Hz can also be
used to find the angular speed or velocity of the engine
given as follows:

EQUATION D-1: ENGINE ANGULAR


VELOCITY

 Engine = 2  f signal

Where: ωEngine is the angular velocity of engine


in radians/second.
fsignal is the engine speed in Hz.
2π is the length of circumference of a
circle in radian angles or one complete
rotation of circle in radian.

Equation D-1 can be used to find the linear speed of


the engine as shown below:

EQUATION D-2: ENGINE LINEAR


VELOCITY

V = r
Engine Engine
Where: VEngine is the linear velocity or speed of
the engine piston in meters/second
r is the radius which is equal to half of the
distance between the TDC and BDC
position of the piston in meters

The engine rotation is mechanically coupled to automo-


bile wheels through gear trains. The mechanical cou-
pling through gears has a ratio called gear turn ratio,
which measures how fast the wheel will rotate for one
complete rotation of the engine. The gear turn ratio
value can be used to convert the engine linear velocity
into automobile linear velocity or speed as follows:

EQUATION D-3: AUTOMOBILE LINEAR


VELOCITY

V Automobile = V Engine  G

Where: VAutomobile is the automobile linear


velocity or speed in meters/second.
G is the gears’ turn ratio of engine rotation
and the automobile wheel rotation.

 2015 Microchip Technology Inc. DS00001980A-page 27


AN1980
APPENDIX E: MPLAB® CODE select the required settings. This reduces the time to
development. The MCC also provides some built-in
CONFIGURATOR
functions for working with specific peripherals.
(MCC)
Figure E-1 shows the configuration of the PIC16F161X
The MPLAB® Code Configurator (MCC) plug-in for device in MCC for CDI implementation. Figures E-2,
MPLAB X can be used to configure the peripherals in E-3, E-4, and E-5 show the configuration of the
PIC MCU. The MCC provides graphical user interface PIC16F1619 device peripherals used in the CDI appli-
(GUI) tools to easily understand the configuration and cation for AT, CLC, Math Accelerator, and SMT1,
respectively.

FIGURE E-1: AT CONFIGURATION IN MCC FOR PIC16F1619

FIGURE E-2: CLC CONFIGURATION IN MCC FOR PIC16F1619

DS00001980A-page 28  2015 Microchip Technology Inc.


AN1980
FIGURE E-3: MATH ACCELERATOR CONFIGURATION IN MCC FOR PIC16F1619

FIGURE E-4: SMT1 CONFIGURATION IN MCC FOR PIC16F1619

To install MCC, go to Tools  Plugins Available Plugins  MPLAB X Code Configurator Install. To start and use
the MCC after installation, go to Tools Embedded MPLAB Code Configurator.

 2015 Microchip Technology Inc. DS00001980A-page 29


AN1980
FIGURE E-5: MCC GENERATED FILES AND FOLDER STRUCTURE

After all the settings are selected in MCC, click the Generate Code button to generate the peripheral code, and create
a header and a C file for every peripheral separately. Figure E-2 shows the files created and arranged under the MCC
Generated Files folder for CDI implementation using AT. The programmer should add the code wherever it is required
in these files.

DS00001980A-page 30  2015 Microchip Technology Inc.


AN1980
APPENDIX F: REFERENCES
1. TB3129 – Signal Measurement Timer on PIC®
Microcontrollers (DS90003129)
2. TB3133 – Configurable Logic Cell on PIC
Microcontrollers (DS90003133)
3. TB3134 – 16-Bit Multiplication and Addition by
using the Math Accelerator Peripheral on
PIC16(L)F161X (DS90003134)
4. TB3118 – Complementary Waveform Generator
Technical Brief (DS90003118)

 2015 Microchip Technology Inc. DS00001980A-page 31


AN1980
NOTES:

DS00001980A-page 32  2015 Microchip Technology Inc.


Note the following details of the code protection feature on Microchip devices:
• Microchip products meet the specification contained in their particular Microchip Data Sheet.

• Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.

• There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.

• Microchip is willing to work with the customer who is concerned about the integrity of their code.

• Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”

Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.

Information contained in this publication regarding device Trademarks


applications and the like is provided only for your convenience The Microchip name and logo, the Microchip logo, dsPIC,
and may be superseded by updates. It is your responsibility to
FlashFlex, flexPWR, JukeBlox, KEELOQ, KEELOQ logo, Kleer,
ensure that your application meets with your specifications.
LANCheck, MediaLB, MOST, MOST logo, MPLAB,
MICROCHIP MAKES NO REPRESENTATIONS OR
OptoLyzer, PIC, PICSTART, PIC32 logo, RightTouch, SpyNIC,
WARRANTIES OF ANY KIND WHETHER EXPRESS OR
SST, SST Logo, SuperFlash and UNI/O are registered
IMPLIED, WRITTEN OR ORAL, STATUTORY OR trademarks of Microchip Technology Incorporated in the
OTHERWISE, RELATED TO THE INFORMATION, U.S.A. and other countries.
INCLUDING BUT NOT LIMITED TO ITS CONDITION,
QUALITY, PERFORMANCE, MERCHANTABILITY OR The Embedded Control Solutions Company and mTouch are
FITNESS FOR PURPOSE. Microchip disclaims all liability registered trademarks of Microchip Technology Incorporated
arising from this information and its use. Use of Microchip in the U.S.A.
devices in life support and/or safety applications is entirely at Analog-for-the-Digital Age, BodyCom, chipKIT, chipKIT logo,
the buyer’s risk, and the buyer agrees to defend, indemnify and CodeGuard, dsPICDEM, dsPICDEM.net, ECAN, In-Circuit
hold harmless Microchip from any and all damages, claims, Serial Programming, ICSP, Inter-Chip Connectivity, KleerNet,
suits, or expenses resulting from such use. No licenses are KleerNet logo, MiWi, MPASM, MPF, MPLAB Certified logo,
conveyed, implicitly or otherwise, under any Microchip MPLIB, MPLINK, MultiTRAK, NetDetach, Omniscient Code
intellectual property rights unless otherwise stated. Generation, PICDEM, PICDEM.net, PICkit, PICtail,
RightTouch logo, REAL ICE, SQI, Serial Quad I/O, Total
Endurance, TSHARC, USBCheck, VariSense, ViewSpan,
WiperLock, Wireless DNA, and ZENA are trademarks of
Microchip Technology Incorporated in the U.S.A. and other
countries.
SQTP is a service mark of Microchip Technology Incorporated
in the U.S.A.
Silicon Storage Technology is a registered trademark of
Microchip Technology Inc. in other countries.
GestIC is a registered trademark of Microchip Technology
Germany II GmbH & Co. KG, a subsidiary of Microchip
Technology Inc., in other countries.
All other trademarks mentioned herein are property of their
respective companies.
© 2015, Microchip Technology Incorporated, Printed in the
U.S.A., All Rights Reserved.
ISBN: 978-1-63277-673-0

QUALITY MANAGEMENT SYSTEM Microchip received ISO/TS-16949:2009 certification for its worldwide
headquarters, design and wafer fabrication facilities in Chandler and
CERTIFIED BY DNV Tempe, Arizona; Gresham, Oregon and design centers in California
and India. The Company’s quality system processes and procedures
are for its PIC® MCUs and dsPIC® DSCs, KEELOQ® code hopping
== ISO/TS 16949 == devices, Serial EEPROMs, microperipherals, nonvolatile memory and
analog products. In addition, Microchip’s quality system for the design
and manufacture of development systems is ISO 9001:2000 certified.

 2015 Microchip Technology Inc. DS0001980A-page 33


Worldwide Sales and Service
AMERICAS ASIA/PACIFIC ASIA/PACIFIC EUROPE
Corporate Office Asia Pacific Office China - Xiamen Austria - Wels
2355 West Chandler Blvd. Suites 3707-14, 37th Floor Tel: 86-592-2388138 Tel: 43-7242-2244-39
Chandler, AZ 85224-6199 Tower 6, The Gateway Fax: 86-592-2388130 Fax: 43-7242-2244-393
Tel: 480-792-7200 Harbour City, Kowloon China - Zhuhai Denmark - Copenhagen
Fax: 480-792-7277 Hong Kong Tel: 86-756-3210040 Tel: 45-4450-2828
Technical Support: Tel: 852-2943-5100 Fax: 86-756-3210049 Fax: 45-4485-2829
http://www.microchip.com/ Fax: 852-2401-3431 India - Bangalore France - Paris
support
Australia - Sydney Tel: 91-80-3090-4444 Tel: 33-1-69-53-63-20
Web Address:
Tel: 61-2-9868-6733 Fax: 91-80-3090-4123 Fax: 33-1-69-30-90-79
www.microchip.com
Fax: 61-2-9868-6755 India - New Delhi Germany - Dusseldorf
Atlanta Tel: 91-11-4160-8631 Tel: 49-2129-3766400
China - Beijing
Duluth, GA
Tel: 86-10-8569-7000 Fax: 91-11-4160-8632 Germany - Karlsruhe
Tel: 678-957-9614
Fax: 86-10-8528-2104 India - Pune Tel: 49-721-625370
Fax: 678-957-1455
China - Chengdu Tel: 91-20-3019-1500 Germany - Munich
Austin, TX Tel: 86-28-8665-5511
Tel: 512-257-3370 Japan - Osaka Tel: 49-89-627-144-0
Fax: 86-28-8665-7889 Tel: 81-6-6152-7160 Fax: 49-89-627-144-44
Boston Fax: 81-6-6152-9310
China - Chongqing Italy - Milan
Westborough, MA
Tel: 86-23-8980-9588 Japan - Tokyo Tel: 39-0331-742611
Tel: 774-760-0087
Fax: 86-23-8980-9500 Tel: 81-3-6880- 3770 Fax: 39-0331-466781
Fax: 774-760-0088
China - Dongguan Fax: 81-3-6880-3771 Italy - Venice
Chicago Tel: 86-769-8702-9880 Korea - Daegu Tel: 39-049-7625286
Itasca, IL
Tel: 630-285-0071 China - Hangzhou Tel: 82-53-744-4301 Netherlands - Drunen
Fax: 630-285-0075 Tel: 86-571-8792-8115 Fax: 82-53-744-4302 Tel: 31-416-690399
Fax: 86-571-8792-8116 Korea - Seoul Fax: 31-416-690340
Cleveland
China - Hong Kong SAR Tel: 82-2-554-7200 Poland - Warsaw
Independence, OH
Tel: 216-447-0464 Tel: 852-2943-5100 Fax: 82-2-558-5932 or Tel: 48-22-3325737
Fax: 216-447-0643 Fax: 852-2401-3431 82-2-558-5934
Spain - Madrid
China - Nanjing Malaysia - Kuala Lumpur Tel: 34-91-708-08-90
Dallas
Tel: 86-25-8473-2460 Tel: 60-3-6201-9857 Fax: 34-91-708-08-91
Addison, TX
Tel: 972-818-7423 Fax: 86-25-8473-2470 Fax: 60-3-6201-9859
Sweden - Stockholm
Fax: 972-818-2924 China - Qingdao Malaysia - Penang Tel: 46-8-5090-4654
Tel: 86-532-8502-7355 Tel: 60-4-227-8870
Detroit UK - Wokingham
Fax: 86-532-8502-7205 Fax: 60-4-227-4068
Novi, MI Tel: 44-118-921-5800
Tel: 248-848-4000 China - Shanghai Philippines - Manila Fax: 44-118-921-5820
Tel: 86-21-5407-5533 Tel: 63-2-634-9065
Houston, TX
Tel: 281-894-5983 Fax: 86-21-5407-5066 Fax: 63-2-634-9069
China - Shenyang Singapore
Indianapolis
Tel: 86-24-2334-2829 Tel: 65-6334-8870
Noblesville, IN
Tel: 317-773-8323 Fax: 86-24-2334-2393 Fax: 65-6334-8850
Fax: 317-773-5453 China - Shenzhen Taiwan - Hsin Chu
Tel: 86-755-8864-2200 Tel: 886-3-5778-366
Los Angeles
Fax: 86-755-8203-1760 Fax: 886-3-5770-955
Mission Viejo, CA
Tel: 949-462-9523 China - Wuhan Taiwan - Kaohsiung
Fax: 949-462-9608 Tel: 86-27-5980-5300 Tel: 886-7-213-7828
Fax: 86-27-5980-5118 Taiwan - Taipei
New York, NY
Tel: 631-435-6000 China - Xian Tel: 886-2-2508-8600
Tel: 86-29-8833-7252 Fax: 886-2-2508-0102
San Jose, CA
Tel: 408-735-9110 Fax: 86-29-8833-7256 Thailand - Bangkok
Tel: 66-2-694-1351
Canada - Toronto
Tel: 905-673-0699 Fax: 66-2-694-1350
Fax: 905-673-6509
07/14/15

DS00001980A-page 34  2015 Microchip Technology Inc.

You might also like