HC11 EFI Code
peter paul fenske
pfenske at direct.ca
Thu Jul 10 20:40:18 GMT 1997
Well here is an example
10 year old engineering project..
Have fun:peter
***************************************************************** FUEL
INJECTION CODE VERSIONC
*****************************************************************
IOREGS EQU $1000
PORTA EQU $00
PORTB EQU $04
CFORC EQU $0B
TCNT EQU $0E
TIC3 EQU $14
TOC2 EQU $18
TOC3 EQU $1A
TOC4 EQU $1C
TOC5 EQU $1E
TCTL1 EQU $20
TCTL2 EQU $21
TMSK1 EQU $22
TFLG1 EQU $23
TMSK2 EQU $24
TFLG2 EQU $25
PACTL EQU $26
ADCTL EQU $30
ADR1 EQU $31
ADR2 EQU $32
ADR3 EQU $33
ADR4 EQU $34
OPTION EQU $39
JMPTOF EQU $00D0
JMPTOC2 EQU $00DC
JMPTOC5 EQU $00D3
JMPIC3 EQU $00E2
RTIVEC EQU $00EB
JMP_OP EQU $7E ;Code for jump instruction
RISEIC3 EQU %00000001
MASKIC3 EQU %00000001
CLRIC3 EQU %00000001
TOFMASK EQU %10000000
OUTRHLF EQU $FFB5 ;Ascii output routines in monitor
OUTLHLF EQU $FFB2
OUT1BYT EQU $E4D5
OUT1BSP EQU $E4E4
OUT2BSP EQU $E4E1
OUTCRLF EQU $E4ED
OUTSTRG EQU $E4FD
BUFFALO EQU $E0B2 ;Return to monitor
FUEL EQU $C600 ;Fueling table
CHOKE EQU $C700 ;Choke enrichment table
COLD EQU $C710 ;Cold run enrichment table
ORG $0000
PERIOD RMB 3
TIMER2 RMB 3
CLOCK RMB 2
CLOCKA RMB 2
SECOND RMB 1
TOC2CNT RMB 2
TOC5CNT RMB 2
COUNTER RMB 2
TOFCNT RMB 1
BANK1 RMB 1
BANK2 RMB 1
START RMB 1
RPMVAL RMB 1
RPMFRAC RMB 1
VACVAL RMB 1
VACFRAC RMB 1
AVAL RMB 1
BVAL RMB 1
CVAL RMB 1
DVAL RMB 1
X1VAL RMB 1
X2VAL RMB 1
DIFVAL RMB 1
T1 RMB 2
T2 RMB 2
CALCVAL RMB 2
MAPVAL RMB 1
FUELVAL RMB 2
MULFLAG RMB 1
QUOTE RMB 5 ;QUOTIENT BIN TO BCD ROUTINE
****************************************************************** START OF
PROGRAM *
*****************************************************************
ORG $C000
RMP SEI ;Disable interrupts
LDX #IOREGS
******************************************************************INIT TIMER
OVERFLOW ROUTINE(give periods greater than 32 mS) *
*****************************************************************
CLR TOFCNT ;set overflow counter to zero
LDAA #JMP_OP
STAA JMPTOF
LDD #TOFINT
STD {JMPTOF+1}
LDAA #TOFMASK
STAA TMSK2,X ;Enable timer overflow interrupt - TOI
STAA TFLG2,X ;Clear the timer overflow flag - TOF
******************************************************************SETUP UP
INPUT CAPTURE INTERRUPT ROUTINE(to measure RPM) *
*****************************************************************
LDAA #JMP_OP
STAA JMPIC3
LDD #IC3INT
STD {JMPIC3+1}
LDAA #RISEIC3
STAA TCTL2,X
LDAA #CLRIC3
STAA TFLG1,X ;Clear input capture flag - IC3F
LDD #0
STD PERIOD
STAA {PERIOD+2}
STD CLOCK
****************************************************************** IDLE
AIR MOTOR CONTROL SETUP *
*****************************************************************
LDAA #JMP_OP
STAA JMPTOC2
LDD #TOC2INT
STD {JMPTOC2+1}
LDAA #%01010000
STAA TCTL1,X
LDAA #$41 ;Enable OC2I and IC3I
STAA TMSK1,X
LDD #!60000 ;slowest stepper speed
STD TOC2CNT
ADDD TCNT,X ;Hold off first TOC2 interrupt
STD TOC2,X
******************************************************************
Set up and start A to D *
*****************************************************************
LDAA #%10000000 ;ADPU = 1
STAA OPTION,X
LDAA #%00110000 ;SCAN = 1, MULT = 1, CHAN 0 TO 3
STAA ADCTL,X
LDAA #4
STAA BANK1
LDAA #8
STAA BANK2
LDAA #1
STAA START
LDD #2000 ;Something to start out with
STD FUELVAL
****************************************************************** SETUP
REAL TIME INTERRUPT (Clock) *
*****************************************************************
TD LDD $0000
STD CLOCKA
LDAA $61
STAA SECOND
LDAA #JMP_OP
STAA RTIVEC
LDD #CONT
STD {RTIVEC+1}
LDAA #%00000010
STAA PACTL,X
LDAA #%11000000
STAA TMSK2,X
LDAA #%01000000
STAA TFLG2,X
******************************************************************
START OF MAIN REPITITIVE LOOP *
*****************************************************************
EDGE1 SEI ;Disable interrupts sensitive
LDAA PERIOD
STAA TIMER2
LDD {PERIOD+1} ;Get a working copy of ignition period
STD {TIMER2+1} ; in usec
CLI ;Enable interrupts
CPD #!37500 ;If RPM < 400 then START mode
BLS ON1
******************************************************************
STARTING ROUTINE *
*****************************************************************
STMODE LDAA #1
STAA START
LDAB {IOREGS+ADR3} ;GET STARTING TEMP
LSRB
LSRB
LSRB
LSRB
LDX #CHOKE
ABX
LDAA 0,X
LDAB #!200
MUL ;STARTING PULSE WIDTH
STD FUELVAL
JMP OUTIT
ON1 XGDX
TST TIMER2 ;If greater than 65535 then START mode
BNE STMODE
LDD #!2343 ;If greater than 6400 RPM then
CPD {TIMER2+1} ; set to 6400 RPM
BLO ON2
STD {TIMER2+1}
ON2 CLR START
LDX {TIMER2+1}
LDD #!37500 ;400 RPM = 37500 USEC
IDIV
DEX
XGDX
STAB RPMVAL
XGDX
LDX {TIMER2+1}
FDIV ;get fraction
XGDX
LSRA
LSRA
LSRA
LSRA
STAA RPMFRAC
LDAB {IOREGS+ADR2}
STAB VACVAL
ANDB #%00001111
STAB VACFRAC
LDAB VACVAL
ANDB #%11110000
STAB VACVAL
LDX #FUEL
ABX
LDAB RPMVAL
ABX
LDAA 0,X
STAA AVAL
CMPB #15
BEQ OK1
INX
OK1 LDAA 0,X
STAA BVAL
LDAB #16
LDAA VACVAL
CMPA #$F0
BEQ OK2
ABX
OK2 LDAA 0,X
STAA DVAL
LDAA RPMVAL
CMPA #15
BEQ OK3
DEX
OK3 LDAA 0,X
STAA CVAL
* X1 = AVAL + (BVAL - AVAL) * RPMFRAC / 16
LDX AVAL
PSHX
LDAA RPMFRAC
PSHA
JSR CALCIT
STAB X1VAL
* X2 = DVAL + (CVAL - DVAL) * RPMFRAC / 16
LDX CVAL
PSHX
LDAA RPMFRAC
PSHA
JSR CALCIT
STAB X2VAL
* MAPVAL = X1VAL + (X2VAL - X1VAL) * VACFRAC / 16
LDX X1VAL
PSHX
LDAA VACFRAC
PSHA
JSR CALCIT
STAB MAPVAL
LDAA #!156
MUL
STD FUELVAL
****************************************************************** OUTPUT
PARAMETERS TO TERMINAL *
*****************************************************************
OUTIT LDX #STARTIT
JSR OUTSTRG
LDX #START
JSR OUT1BSP
LDD {TIMER2+1}
JSR BINBCD
JSR OUTBCD
LDX #USEC ;Print "uSec"
JSR OUTSTRG
LDX #{ADR2+IOREGS}
JSR OUT1BSP
JSR OUT1BSP
JSR OUT1BSP
LDX #AVAL
JSR OUT1BSP
LDX #VACVAL
JSR OUT1BSP
LDX #RPMVAL
JSR OUT1BSP
LDX #PW
JSR OUTSTRG
LDD FUELVAL
LSRD
JSR BINBCD
JSR OUTBCD
LDX #USEC
JSR OUTSTRG
LDD CLOCKA
JSR BINBCD
JSR OUTBCD
JSR OUTCRLF ;Add a CR/LF
LDX #!500 ;Let the poor PC catch up!!!!!!!
BIGWAIT CLR COUNTER
WAIT DEC COUNTER
BNE WAIT
DEX
BNE BIGWAIT
JSR SESTEP
JMP EDGE1
****************************************************************** OUTPUT A
BCD VALUE SUBROUTINE *
*****************************************************************
OUTBCD LDAA QUOTE ;Print the period in hex
JSR OUTRHLF
LDAA {QUOTE+1}
JSR OUTRHLF
LDAA {QUOTE+2}
JSR OUTRHLF
LDAA {QUOTE+3}
JSR OUTRHLF
LDAA {QUOTE+4}
JSR OUTRHLF
RTS
****************************************************************** BINARY TO
BCD CONVERSION SUBROUTINE *
*****************************************************************
BINBCD LDX #$2710 ;LOAD DIVISOR 10,000
IDIV
XGDX
STAB QUOTE
XGDX
LDX #$3E8 ;LOAD DIVISOR 1000
IDIV
XGDX
STAB {QUOTE+1}
XGDX
LDX #$64 ;LOAD DIVISOR 100
IDIV
XGDX
STAB {QUOTE+2}
XGDX
LDX #$A ;LOAD DIVISOR 10
IDIV
XGDX
STAB {QUOTE+3}
XGDX
STAB {QUOTE+4}
RTS
*****************************************************************
* IDLE AIR MOTOR SPEED AND DIRECTION CONTROL SUBROUTINE *
*****************************************************************
SESTEP LDX #IOREGS
LDAB ADR4,X
CMPB #$C0
BHS UPP
CMPB #$40
BLO DOWNE
LDAB #$00
STAB PORTB,X
BRA MOVER
DOWNE LDAB #$10
STAB PORTB,X
JMP MOVER
UPP LDAB #$30
STAB PORTB,X
MOVER RTS
****************************************************************** TIMER
OVERFLOW INTERRUPT ROUTINE *
*****************************************************************
TOFINT INC TOFCNT
BPL TOFINT1 ;Do not let TOFCNT overflow
DEC TOFCNT
TOFINT1 LDAA #TOFMASK
STAA {IOREGS+TFLG2} ;Clear the timer overflow flag
RTI
***************************************************************** * REAL
TIME INTERRUPT ROUTINE (Clock) *
*****************************************************************CONT
LDAA SECOND
DECA
BNE CONTA
LDD CLOCKA
ADDD #$0001
STD CLOCKA
LDAA #!61
CONTA STAA SECOND
LDAA #%01000000
STAA {IOREGS+TFLG2}
RTI
****************************************************************** MAIN IGN
TIMER AND INJECTOR DRIVER INTERRUPT ROUTINE *
*****************************************************************
IC3INT LDX #IOREGS
LDD TIC3,X
BMI IC3INT1
TST TFLG2,X
BPL IC3INT1
INC TOFCNT
IC3INT1 SUBD CLOCK
STD {PERIOD+1}
BCC IC3INT2
DEC TOFCNT
IC3INT2 LDAA TOFCNT
STAA PERIOD
CLC
ROR PERIOD ;Change to usec
ROR {PERIOD+1}
ROR {PERIOD+2}
CLR TOFCNT
LDD TIC3,X
STD CLOCK
BMI IC3INT3
LDAA TFLG2,X
BPL IC3INT3
DEC TOFCNT
IC3INT3 LDAA START ;Check for START mode: 0 = RUN
BEQ IC3INT6
JSR FIREB1
DEC BANK1
BNE IC3INT4
BRA IC3INT7
IC3INT6 DEC BANK1
BNE IC3INT4
JSR FIREB1
IC3INT7 LDAA #8
STAA BANK1
IC3INT4 LDAA START ;Check for START mode: 0 = RUN
BEQ IC3INT8
JSR FIREB2
DEC BANK2
BNE IC3INT5
BRA IC3INT9
IC3INT8 DEC BANK2
BNE IC3INT5
JSR FIREB2
IC3INT9 LDAA #8
STAA BANK2
IC3INT5 LDAA #1
STAA TFLG1,X ;Clear input capture flag - IC3F
RTI
******************************************************************
Idle control motor interrupt routine *
*****************************************************************
TOC2INT LDX #IOREGS
LDD TOC2CNT
ADDD TOC2,X
STD TOC2,X
LDAA #$40
STAA TFLG1,X
RTI
*****************************************************************
* SET INJECTOR OUTPUT PULSEWIDTH INTERRUPT ROUTINE *
*****************************************************************
FIREB1 LDD FUELVAL
BEQ FIREB1E
ADDD TCNT,X
STD TOC3,X
BSET TCTL1,X,%00110000 ;Set OC3 to 1 on forced compare
LDAA #%00100000 ;Force OC3
STAA CFORC,X
BCLR TCTL1,X,%00010000 ;Set OC3 to 0 on timer compare
FIREB1E RTS
FIREB2 LDD FUELVAL
BEQ FIREB2E
ADDD TCNT,X
STD TOC4,X
BSET TCTL1,X,%00001100
LDAA #%00010000
STAA CFORC,X
BCLR TCTL1,X,%00000100
FIREB2E RTS
****************************************************************** RECOVER
PARAMETERS LOST BEFORE RTI SUBROUTINE *
*****************************************************************
CALCIT TSX
LDD 3,X ;Get back AVAL (CVAL, X1VAL) and
CBA ; BVAL (DVAL, X2VAL)
BHI CALCIT1
STAA 4,X
STAB 3,X
BRA CALCIT2
CALCIT1 LDAA #16
SUBA 2,X
STAA 2,X
CALCIT2 LDD 3,X
SBA
LDAB 2,X
MUL
STD T1
LSRD
LSRD
LSRD
LSRD
STD T2
ADDB 4,X
STD CALCVAL
PULX ;Get the RETURN address
PULA ;Clean up the STACK
PULY
PSHX ;Return RETURN address to STACK
RTS
****************************************************************** TEXT
STORAGE *
*****************************************************************USEC FCB
' uS '
FCB $04
STARTIT FCB ' Start = '
FCB $04
PW FCB ' Pulse Width = '
FCB $04
****************************************************************** FUEL
CONTROL MAP *
*****************************************************************
ORG $C600
FCB !90,!130,!145,!161,!163,!165,!167,!169
FCB !173,!171,!169,!165,!163,!161,!159,0
FCB !85,!120,!133,!157,!158,!160,!162,!163
FCB !164,!163,!161,!159,!157,!155,!154,0
FCB !80,!110,!125,!141,!142,!143,!145,!153
FCB !153,!153,!148,!146,!144,!142,!141,0
FCB !75,!105,!115,!123,!129,!131,!133,!137
FCB !143,!141,!139,!135,!131,!127,!124,0
FCB !70,!90,!105,!117,!118,!122,!125,!130
FCB !131,!131,!127,!125,!122,!119,!118,0
FCB !65,!70,!95,!110,!111,!115,!119,!125
FCB !127,!126,!123,!120,!116,!113,!112,0
FCB !60,!62,!80,!104,!105,!110,!111,!117
FCB !119,!117,!111,!108,!107,!106,!105,0
FCB !55,!56,!72,!97,!98,!99,!103,!110
FCB !113,!111,!107,!102,!101,!99,!98,0
FCB !50,!51,!68,!87,!88,!90,!96,!101
FCB !106,!103,!98,!95,!93,!91,!90,0
FCB !44,!45,!62,!75,!79,!85,!92,!98
FCB !101,!99,!93,!90,!86,!85,!84,0
FCB !42,!43,!55,!71,!76,!80,!84,!89
FCB !92,!89,!86,!83,!81,!75,!73,0
FCB !40,!41,!43,!52,!58,!63,!67,!73
FCB !71,!73,!69,!97,!65,!63,!61,0
FCB !37,!37,!37,!41,!48,!54,!58,!61
FCB !63,!61,!59,!57,!55,!54,!53,0
FCB !36,!36,!36,!38,!42,!47,!51,!54
FCB !55,!53,!51,!50,!48,!47,!46,0
FCB !34,!34,!34,!35,!38,!42,!46,!48
FCB !49,!47,!45,!44,!43,!42,!41,0
FCB !27,!27,!28,!29,!31,!33,!35,!37
FCB !38,!37,!35,!33,!31,!30,!29,0
****************************************************************** COLD
START ENRICHMENT TABLE *
*****************************************************************
ORG $C700
FCB !120,!110,!100,!90,!80,!75,!70,!65
FCB !60,!55,!50,!45,!40,!35,!30,!20
END
More information about the Diy_efi
mailing list