code 101
rr
RRauscher at nni.com
Fri Jun 11 02:41:51 GMT 1999
Hoping to compliment what Steve and others have
been doing, I'll describe some actual code.
What follows is a code fragment from the beginning
of the spark advance calculation. I'll explain what
the code is doing as I go along.
Enjoy,
BobR.
--starts here--
In general terms, this code does a look-up into the
main SA table, based on current engine MAP (load) and
RPM. It then does a Slope calculation for any
additional SA, based on RPM.
For the following:
rpm = 4000
map = 40Kpa
We are just cruising down the highway, when the
ecm needs to do it's Spark Advance calculation...
*=============================================
* MAIN SA TABLE CALCULATION, (14x15)
*
* ECM 1227747 SA table ASDZ
*
* reg X is 16 bit (2 bytes)
* reg A is 8 bits (1 byte)
* reg B is 8 bits (1 byte)
*
* RAM and eprom locations are 8 bits each.
*
*=============================================
Code Branch Instruction: Comments:
Adr: label:
E759: LDX #$D032 ; Loads the X reg with the location
; of the MAIN SA TABLE. The '#$D032'
; is an immediate value, known as a
; hardcoded value. The SA table resides
; in the eprom.
;
; The '#' designates an immediate value
; The '$' means that it's in hex
;
E75C: LDAB L0026 ; Loads the B reg from RAM location L0026,
; with the current MAP value.
;
; So: B = 64 = MAP/0.625 => (40/0.625 = 64)
;
E75E: LDAA L001B ; Loads the A reg from RAM location L001B,
; with the current RPM value.
;
; So: A = 160 = RPM/25 => (4000/25 = 160)
;
E760: JSR LFB67 ; Jump to SubRoutine for a 3d Look-Up. The
; subroutine is located at address 0xFB67.
; This gets the SA value from the proper
; table location. We then return to
; execute the next instruction.
;
; The 'looked-up' value will be 'returned'
; in the A reg. (A = 102 => 35.8 deg), and
; stored in RAM location L0051 by the Look
; Up routine.
;
; Since the table ends at 3600 rpm, and
; the current rpm is 4000 rpm, the last
; row in the table will be used (3600 rpm).
;
E763: LDAB L001C ; Loads the B reg from RAM location L001C,
; with the current RPM value.
;
; So: B = 160 = RPM/25
;
E765: CMPB #144 ; Compare reg B value with the value 144.
; So: B - 144 => (160 - 144 = 16), The '16'
; (the result), doesn't get used. But
; condition code flags have been set
; according to the result of the compare.
;
; 144 * 25 = 3600 RPM, the end of the
; main spark table. This is where any
; added SA slope begins.
;
E767: BLS LE77E ; Branch Less Than: Branch if RPM less-than
; 3600 RPM. Branch to LE77E, a short distance
; down the code, and skip whats between here
; at the 'branch-to' location.
;
; This branch is based on the previous
; Compare instruction using the condition
; code flags.
;
; Our RPM is @ 4000, so we don't branch
; and continue on.
;
E769: CMPB LD00C ; Compare the reg B value against an eprom
; table value of 168 (4200 RPM).
;
; So: B - LD00C => (160 - 168 = -8)
;
; This is the MAIN SPK HIGH EXTEND located
; at 0xD00C (LD00C)
;
E76C: BLS LE771 ; Branch Less Than: We take the branch, as
; the above compare gave us a result less
; than zero. We continue after the next
; instruction, as we 'jumped' past it.
;
; The branch to address is 0xE771.
;
E76E: LDAB LD00C ; Load reg B from LD00C, MAX Slope RPM. The
; code would execute this if our RPM was
; above 4200. This clips the RPM value to
; this maximum possible value for the calc.
;
; So: B = 168 => (168 * 25 = 4200rpm)
;
E771: LE771 SUBB #144 ; Subtract from reg B the immediate value
; of 144 (3600 RPM). Reg B still has our
; current RPM, (or the max slope rpm if
; the current rpm was greater than 4200 rpm).
;
; So: B - 144 => (160 - 144 = 16), B = 16
;
E773: ASLB ; Arithmetic Shift Left B, shifts all the
; bits in reg B once to the left. This has
; the effect of multiplying the value in
; reg B by 2 (double it).
;
; So: B << 1 => (16 * 2 = 32), B = 32
;
E774: LDAA LD00D ; Load reg A from eprom location LD00D, with
; the SA per 1k RPM value. This value is 46
; for ~5.1 degrees every 1000 rpm.
;
; So: A = 46
;
E777: MUL ; Multiply reg A times reg B, and put
; the result in reg's A & B.
;
; So: A * B => (46 * 32 = 1472), the
; value 1472 is stored in reg's A & B.
; Reg A has the high order 8 bits, reg B
; has the low order 8 bits of the result.
;
E778: ADDA L0051 ; Add to reg A the value found in RAM
; at location L0051, this is from the
; previous look-up of the main SA value.
;
; NOte some strangeness here, the calc'd
; slope value is in reg's A & B, but the
; code is dropping the reg B part. This
; in effect is causing the value in A&B
; to be divided by 256. (subtle, eh?)
;
; So: 1472 / 256 = 5, the value held by
; reg A.
;
; So: A + L0051 => (5 + 102 = 107), reg A
; now contains the value 107, or in degrees
; of SA: 107 * .351 = 37.5 deg. (The .351
; is the conversion factor for SA values).
;
; The slope calc added 1.7 deg of SA.
;
E77A: BCC LE77E ; Branch if Carry Clear to location LE77E;
; We will take the branch, carry is clear.
;
; 'Carry' is a condition code flag that
; is set according to the previous
; ADDA instruction. Carry would be set if
; the result of adding reg A to the value
; in location L0051 was greater than 255.
;
; In that case, the value left in reg A
; would not be represenative of the 'real'
; result.
;
E77C: LDAA #255 ; Load reg A with 255, force a max limit.
; we would need to do this if the carry flag
; was set, as what is in reg A is bogus,
; and smaller then the real value.
;
; (So: A = 255, if executed)
;
E77E: LE77E TAB ; Transfer reg A value to reg B. Both
; reg A and reg B will have the value 107
; in them.
;
; So: B = A = 107
;
E77F: CLRA ; Clear reg A, set reg A = 0.
;
E780: STD L0057 ; Store Double into RAM at location L0057.
;
; A Double is reg A & B together.
;
; So: L0057 & L0058 hold the double value
; of regs A&B => 107.
;
; Since 107 fits in 8 bits, L0057 will
; contain zero, and L0058 will contain 107.
;
The value 107 will be further modified by additional code, PE, Knock,
coolant comp, to name a few. It will then be converted into a value
the ecm hardware can use to control when the distributor fires.
; eof ;
--
More information about the Diy_efi
mailing list