Configuration = 'Dual Table v.2.00' Requires = 1.03 RAM = { #PUBLIC #ORG ram_start ; Defined in Gp32.equ ;============================================================================ ;== == ;== MegaSquirt Hardware Wiring == ;== == ;============================================================================ ; ; Inputs ; Port MCU Xn DB Use ; ---------- --- -- ------ --------------------------------------------- ; IRQ 14 - - Ignition/RPM interrupt ; PTA6 39 X1 H3:6 Switch 2 ; PTA7 40 X0 H3:7 Switch 1 ; PTB0/AD0 23 - - MAP sensor ; PTB1/AD1 24 - - MAT sensor ; PTB2/AD2 25 - - CLT sensor ; PTB3/AD3 26 - - TPS ; PTB4/AD4 27 - - battery voltage ; PTB5/AD5 28 - - EGO sensor ; PTB6/AD6 29 X7 H3:4 Unused thermistor circuit ; PTB7/AD7 30 X6 H3:5 Unused thermistor circuit ; ; Outputs ; Port MCU Xn DB Use B&G (efahl) ; ---------- --- -- ------ --------------------------------------------- ; PTA0 33 - - Fuel pump relay ; PTA1 34 - - Fast idle solenoid (nitrous relay) ; PTA2 35 X5 H4:2-3 None (IAC solenoid) ; PTA3 36 X4 H4:6-7 None (Boost control) ; PTC0 7 - - Squirt LED ; PTC1 8 - - Acceleration enrichment LED ; PTC2 9 - - Warmup LED ; PTD4/T1CH0 21 - - Injector bank 1 ; PTD5/T1CH1 22 - - Injector bank 2 ; ;---------------------------------------------------------------------------- pta port($00) = { fuelp (0) n2oP (1) iasc (2) ; Iasc should really be 1 to work with stim. boostP (3) } ptc port($02) = { sled (0) aled (1) wled (2) } ptd port($03) = { inject1(4) inject2(5) } ;-------------------------------------------------------------------------- ;Timer Equates for real-time clock function timerStop const = %00110010 ; TSC timerGo const = %01010010 ; TSC T2SC0_No_PWM const = %00010000 ; TSC0 ;-------------------------------------------------------------------------- ; These control Injector PWM mode for T1SC0 and T1SC1 Timergo_NO_INT const = %00000010 ; TSC without interrupts ;T1SCX_PWM const = %00011010 ; Unbuffered PWM enabled T1SCX_PWM const = %00011110 ; Unbuffered PWM enabled - set high on compare, toggle on overflow T1SCX_NO_PWM const = %00010000 ; No PWM ;******************************************************************************* ;* MegaSquirt RAM Variables ;******************************************************************************* ; ; RAM Variables - Ordered List for RS232 realtime download - ; delivered in one packet. ; ;=============================================================================== ; First 19 must have their order maintained for compatibility with ; original Configurator. secl byte ; low seconds - from 0 to 255, then rollover ;-------------------------------------------------------------------------- ; Squirt Event Scheduling Variables ; - bit fields for "squirt" variable above squirt bits = { ; Event variable bit field for Injector Firing inj1 (0) ; 0 = no squirt 1 = squirt inj2 (1) ; 0 = no squirt 1 = squirt sched1 (2) ; 0 = nothing scheduled 1 = scheduled to squirt firing1 (3) ; 0 = not squirting 1 = squirting sched2 (4) firing2 (5) } ;-------------------------------------------------------------------------- ; Bit fields for "engine" status variable. engine bits = { ; Variable bit-field to hold engine current status running (0) ; 0 = engine not running 1 = running crank (1) ; 0 = engine not cranking 1 = engine cranking startw (2) ; 0 = not in startup warmup 1 = in warmup enrichment warmup (3) ; 0 = not in warmup 1 = in warmup TPSaen (4) ; 0 = not in TPS acceleration mode 1 = TPS acceleration mode TPSden (5) ; 0 = not in deacceleration mode 1 = in deacceleration mode ; Note, mapaen is not yet implemented. mapaen (6) ; 0 = not in MAP acceleration mode 1 = MAP deaceeleration mode ; Note, idleOn only valid when c13_fi is turned on in config13 idleOn (7) ; 0 = not in idle adjust mode 1 = idle mode } barometer byte = 101T ; Raw Barometer ADC Reading ;------------------------------------------------------------------------------- ; Raw ADC Counts ; This block must remain in exactly this order as it is dictated by the ; hardware configuration. See DoADC and schematic. mapADC byte ; Manifold Absolute Pressure matADC byte ; Manifold Air Temperature cltADC byte ; Coolant Temperature tpsADC byte ; Throttle Position Sensor batADC byte ; Battery Voltage egoADC byte ; Exhaust Gas Oxygen ;------------------------------------------------------------------------------- EGOcorr byte ; Oxygen Sensor Correction percent AirCorr byte ; Air Density Correction lookup percent warmcor byte ; Total Warmup Correction percent rpm byte ; Computed engine RPM rpm/100 pw1 byte ; injector #1 squirt time mms TPSaccel byte ; Acceleration enrichment percent barocor byte ; Barometric Correction percent GammaE byte ; Total Gamma Enrichments percent vecurr byte ; Current VE value from lookup table percent pw2 byte ; Table 2 pulse width mms vecurr2 byte ; Table 2 VE percent idleDC byte ; Idle controller duty cycle percent #PRIVATE ;------------------------------------------------------------------------------- ; Pulse width stuff. pwcalc1 byte ; Computed injector 1 pulse width - move into variable PW1 at pulse time pwcalc2 byte ; Computed injector 2 pulse width pwrun1 byte ; Pulsewidth timing variable - from 0 to 25.4ms pwrun2 byte ;------------------------------------------------------------------------------- ; Engine RPM -> RPM = 12000/(ncyl * (rpmph - rpmpl)) rpmph byte ; High part of RPM Period rpmpl byte ; Low part of RPM Period rpmch byte ; Counter for high part of RPM rpmcl byte ; Counter for low part of RPM idleph byte ; Target RPM period for idle control (MSB) idlepl byte ; Target RPM period for idle control (LSB) ;---------------------------------------------------------------------------- ; Previous raw ADC values for computing derivatives. Must correspond ; exactly to the block above starting with "mapADC". lmap byte ; Manifold Absolute Pressure ADC last Reading lmat byte ; Manifold Air Temp ADC last Reading lclt byte ; Coolant Temperature ADC last Reading lTPS byte ; Throttle Position Sensor ADC last Reading lbatt byte ; Battery Voltage ADC last Reading lEGO byte ; Last EGO ADC reading ;---------------------------------------------------------------------------- ; Global Time Clock and various timer variables mms byte ; 0.0001 second update variable ms byte ; 0.001 second increment hs byte ; 0.01 second increment ts byte ; 0.1 second increment sech byte ; high seconds - rollover at 65536 secs = 1110.933 min = 18.51 hours mmsDiv byte TPSaclk byte ; TPS enrichment timer clock in 0.1 second resolution TPSaclkcmp byte ; Comparison value for TPS acceleration time - from lookup table EGOcount byte ; Counter value for EGO step - incremented every ignition pulse ASEcount byte ; Counter value for after-start enrichment counter - every ignition pulse IGNcount1 byte ; Bank 1 ignition pulse counter IGNcount2 byte ; Bank 2 pulse counter idleCtlClock byte ; Idle controller clock - incremented every ignition pulse. idleActClock byte ; Idle actuator clock bcActClock byte ; Boost control actuator clock. bcCtlClock byte ; Boost controller algorithm clock - incremented every ms. pageNo byte ; used for offsetting the VE and enrichments for table 2 TPSfuelCorr byte = 100T; TPS Fuel Correction (percent) ;---------------------------------------------------------------------------- ; SCI parameters/variables txcnt byte ; SCI transmitter count (incremented) txgoal byte ; SCI number of bytes to transmit txmode byte ; Transmit mode flag rxoffset byte ; offset placeholder when receiving VE/constants vis. SCI ;---------------------------------------------------------------------------- ; Routines for integer math - storage variables INTACC1 dword INTACC2 dword ;---------------------------------------------------------------------------- ; Variables for Flash burner ;---------------------------------------------------------------------------- burnSrc word ; 2-byte address of RAM source data. burnDst word ; 2-byte address of FLASH destination. burnCount byte ; 1-byte count of bytes to store. ;burnBlk word ; 2-byte offset of block being erased or written. ;burnLast word ; 2-byte end of block address ;ms_temp_sp word ; 2-byte to store return address ;---------------------------------------------------------------------------- ; Extra "registers", make sure this stuff is direct page. tmp1 byte tmp2 byte tmp3 byte tmp4 byte tmp5 byte tmp6 byte tmp7 byte tmp8 byte tmp9 byte tmp10 byte tmp11 byte tmp12 byte tmp13 byte tmp14 byte tmp15 byte tmp16 byte tmp17 byte tmp18 byte tmp19 byte tmp20 byte tmp21 byte ; used in burner routine } RAM_FLASH = { #ORG $E000 ;------------------------------------------------------------------------------- ; Flash Configuration Variables here - variables can be downloaded by pcc or clc. ;------------------------------------------------------------------------------- ; VETABLE and Constants ; VE byte(64) = { ; 64 bytes for VE Table 18T, 18T, 18T, 18T, 18T, 18T, 18T, 18T, ; VE (0,n) 22T, 25T, 30T, 32T, 35T, 35T, 35T, 35T, ; VE (1,n) 35T, 35T, 35T, 35T, 35T, 35T, 35T, 35T, ; VE (2,n) 50T, 50T, 50T, 50T, 50T, 50T, 50T, 50T, ; VE (3,n) 50T, 50T, 50T, 50T, 50T, 50T, 50T, 50T, ; VE (4,n) 50T, 50T, 50T, 50T, 50T, 50T, 50T, 50T, ; VE (5,n) 65T, 65T, 65T, 65T, 65T, 65T, 65T, 65T, ; VE (6,n) 80T, 80T, 80T, 80T, 80T, 80T, 80T, 90T ; VE (7,n) } ;============================================================================== ; 64 byte boundary ;============================================================================== CWU byte = 100T ; Crank Enrichment at -40 F CWH byte = 025T ; Crank Enrichment at 170 F AWEV byte = 020T ; After-start Warmup Percent enrichment add-on value AWC byte = 250T ; After-start number of cycles WWU byte(10) = { ; Warmup bins(fn temp) 120T, ; -40 F 120T, ; -20 F 115T, ; 0 F 115T, ; 20 F 115T, ; 40 F 110T, ; 60 F 105T, ; 80 F 100T, ; 100 F 100T, ; 130 F 100T ; 160 F } TPSAQ byte(4) = { ; TPS acceleration amount (fn TPSDOT) in 0.1 ms units 13T, ; TPSdot = 0.1 v/ms 30T, ; TPSdot = 0.4 40T, ; TPSdot = 0.8 40T ; TPSdot = 1.5 } TPSacold byte = 2T ; Cold acceleration amount (at -40 degrees) in 0.1 ms units TPSthresh byte = 6T ; Accel TPS DOT threshold TPSASYNC byte = 10T ; ***** TPS Acceleration clock value TPSDQ byte = 20T ; Deacceleration fuel cut EGOtemp byte = 200T ; Coolant Temperature where EGO is active EGOcountcmp byte = 32T ; Counter value where EGO step is to occur EGOdelta byte = 1T ; EGO Percent step size for rich/lean EGOlimit byte = 10T ; Upper/Lower EGO rail limit (egocorr is inside 100 +/- Limit) REQ_FUEL byte = 70T ; Fuel constant Divider1 byte = 5T ; IRQ divide factor for pulse ;------------------------------------------------------------------------------- ; tblCnf ; ; If tblCnf = 0 then, as default, both injectors are driven off table ; 1 in simultaneous fire mode. ; ; Each injector can be ; not driven ; from table 1 ; from table 2 ; from both tables ; ; tblCnf ; bit 0 ; controlled by MS or MT for simul/alternate mode ; 0 = both Inj's controlled by 'standard' table the rest of the byte is ignored ; 1 = additional modes activated ; ; bits 1&2 ; 00 = injector 1 not driven ; 01 = driven from table 1 ; 10 = driven from table 2 ; 11 = driven from both tables ; ; bits 3&4 ; 00 = injector 2 not driven ; 01 = driven from table 1 ; 10 = driven from table 2 ; 11 = driven from both tables ; ; bit 5 ; 0 = GammaE not applied to Inj 1 ; 1 = GammaE applied to Inj 1 ; ; bit 6 ; 0 = GammaE not applied to Inj 2 ; 1 = GammaE applied to Inj 2 ; ; bit 7 - not used ;-------------------------------------------------------------------------- ; Bit fields for tblCnf byte when in dual table mode. tblCnf bits = { ; used to offset the VE calcs both (0) = 1 b1tbl1 (1) b1tbl2 (2) b2tbl1 (3) b2tbl2 (4) b1gammaE (5) b2gammaE (6) } InjOpen byte = 10T ; Injector Open Time InjOCFuel byte = 0T ; PW-correlated amount of fuel injected during injector open INJPWM1 byte = 30T ; Bank 1 - Injector PWM duty cycle at current limit INJPWMT1 byte = 255T ; Bank 1 - Injector PWM mmillisec time at which to activate. BATTFAC byte = 12T ; Battery Gamma Factor ;------------------------------------------------------------------------------- ; Constant for RPM = 12,000/ncyl - downloaded constant rpmk word = $05DC ; 1200 ; VE table RPM Bins for 2-D interpolation RPMRANGEVE byte(8) = { 5T, 10T, 15T, 20T, 28T, 36T, 44T, 52T } ; VE Table MAP Pressure Bins for 2_D interp. KPARANGEVE byte(8) = { 20T, 30T, 40T, 50T, 60T, 75T, 90T, 100T } ;------------------------------------------------------------------------------- ; CONFIG11: ; Bit 0-1 = MAP Type ; 00 = MPX4115AP ; 01 = MPX4250AP ; 10 = User-defined ; 11 = User-Defined ; Bit 2 = Engine Stroke ; 0 = Four Stroke ; 1 = Two Stroke ; Bit 3 = Injection Type ; 0 = Port Injection ; 1 = Throttle Body ; Bit 4-7 = Number of Cylinders ; 0000 = 1 cylinder ; 0001 = 2 cylinders ; ... 0 -> 15 maps to 1 -> 16 cylinders. config11 bits = { mapType (0:1) = 0 twoStroke ( 2) = 0 throttleBody ( 3) = 0 nCylinders (4:7) = 4 } ;------------------------------------------------------------------------------- ; CONFIG12: ; Bit 0-1 = Coolant Sensor Type ; 00 = GM ; 01 = User-defined ; 10 = User-defined ; 11 = User-Defined ; Bit 2-3 = MAT Sensor Type ; 00 = GM ; 01 = Undefined ; 10 = Undefined ; 11 = Undefined ; Bit 4-7 = Number of Injectors ; 0000 = 1 Injector ; 0001 = 2 Injectors ; ... 0 -> 15 maps to 1 -> 16 injectors, just like nCyls, above. config12 bits = { coolantSensor (0:1) = 0 matSensor (2:3) = 0 nInjectors (4:7) = 4 } ;-------------------------------------------------------------------------- ; Config13 bits ; Bit 0 = Odd-fire averaging ; 0 = Normal ; 1 = Odd-Fire ; Bit 1 = O2 Sensor Type ; 0 = Narrow-band (single wire 14.7 stoch) ; 1 = DIY-WB (Stoch = 2.5V, reverse slope) ; Bit 2 = Control Stategy ; 0 = Speed-Density ; 1 = Alpha-N ; Bit 3 = Baro correction ; 0 = Disable ; 1 = Enable ; Bit 4 = Fast idle policy ; 0 = B&G on-off algorithm ; 1 = Brian Fielding pwm control ; Bit 5 = Unused ; Bit 6 = Unused ; Bit 7 = Unused config13 bits = { oddFire (0) = 0 wideBand (1) = 0 alphaN (2) = 0 baroCorrection (3) = 0 pwmIdle (4) = 1 } ;------------------------------------------------------------------------------- primeP byte = 20T ; Priming pulse in 1/10ths ms EGOrpm byte = 12T ; EGO disabled below this rpm (* 100rpm) fastIdleTemp byte = 125T ; Fast Idle Temperature O2targetV byte = 26T ; target voltage (in adc counts) for lamda sensor ACMULT byte = 100T ; Acceleration cold multiplication factor (percent/100) ;------------------------------------------------------------------------------- ; User parameters for Brian Fielding's idle controller. ; fastIdleTemp remains in its B&G position above, for compatibility. slowIdleTemp byte = 185T ; Slow Idle Temperature, dF fastIdle byte = 110T ; Fast Idle Speed, RPM/10 slowIdle byte = 65T ; Slow Idle Speed, RPM/10 idleThresh byte = 30T ; TPS A/D count threshold below which idle is on. ;============================================================================== ; 128 byte boundary ;============================================================================== ; VETABLE 2 and Constants ; VE_2 byte(64) = { ; 64 bytes for VE Table 2 18T, 18T, 18T, 18T, 18T, 18T, 18T, 18T, ; VE (0,n) 22T, 25T, 30T, 32T, 35T, 35T, 35T, 35T, ; VE (1,n) 35T, 35T, 35T, 35T, 35T, 35T, 35T, 35T, ; VE (2,n) 50T, 50T, 50T, 50T, 50T, 50T, 50T, 50T, ; VE (3,n) 50T, 50T, 50T, 50T, 50T, 50T, 50T, 50T, ; VE (4,n) 50T, 50T, 50T, 50T, 50T, 50T, 50T, 50T, ; VE (5,n) 65T, 65T, 65T, 65T, 65T, 65T, 65T, 65T, ; VE (6,n) 80T, 80T, 80T, 80T, 80T, 80T, 80T, 90T ; VE (7,n) } ;============================================================================== ; 64 byte boundary - Start of table 2, lots of unused data. ;============================================================================== CWU_2 byte = 100T ; UNUSED Crank Enrichment at -40 F CWH_2 byte = 025T ; UNUSED Crank Enrichment at 170 F AWEV_2 byte = 020T ; UNUSED After-start Warmup Percent enrichment add-on value AWC_2 byte = 250T ; UNUSED After-start number of cycles WWU_2 byte(10) = { ; UNUSED Warmup bins(fn temp) 120T, ; -40 F 120T, ; -20 F 115T, ; 0 F 115T, ; 20 F 115T, ; 40 F 110T, ; 60 F 105T, ; 80 F 100T, ; 100 F 100T, ; 130 F 100T ; 160 F } TPSAQ_2 byte(4) = { ; TPS acceleration amount (fn TPSDOT) in 0.1 ms units 13T, ; TPSdot = 0.1 v/ms 30T, ; TPSdot = 0.4 40T, ; TPSdot = 0.8 40T ; TPSdot = 1.5 } TPSacold_2 byte = 2T ; Cold acceleration amount (at -40 degrees) in 0.1 ms units TPSthresh_2 byte = 6T ; Accel TPS DOT threshold TPSASYNC_2 byte = 10T ; ***** TPS Acceleration clock value TPSDQ_2 byte = 20T ; Deacceleration fuel cut EGOtemp_2 byte = 200T ; UNUSED Coolant Temperature where EGO is active EGOcountcmp_2 byte = 32T ; UNUSED Counter value where EGO step is to occur EGOdelta_2 byte = 1T ; UNUSED EGO Percent step size for rich/lean EGOlimit_2 byte = 10T ; UNUSED Upper/Lower EGO rail limit (egocorr is inside 100 +/- Limit) REQ_FUEL_2 byte = 155T ; Fuel constant Divider2 byte = 1T ; IRQ divide factor for pulse Alternate_2 byte = 1T ; Not used InjOpen_2 byte = 10T ; Injector Open Time InjOCFuel_2 byte = 0T ; PW-correlated amount of fuel injected during injector open INJPWM2 byte = 30T ; Bank 2 - Injector PWM duty cycle at current limit INJPWMT2 byte = 255T ; Bank 2 - Injector PWM mmillisec time at which to activate. BATTFAC_2 byte = 12T ; Battery Gamma Factor ;------------------------------------------------------------------------------- ; Constant for RPM = 12,000/ncyl - downloaded constant rpmk_2 word = $05DC ; ; VE table RPM Bins for 2-D interpolation RPMRANGEVE_2 byte(8) = { 5T, 10T, 15T, 20T, 28T, 36T, 44T, 52T } ; VE Table MAP Pressure Bins for 2_D interp. KPARANGEVE_2 byte(8) = { 20T, 30T, 40T, 50T, 60T, 75T, 90T, 100T } ;------------------------------------------------------------------------------- config21 bits ; UNUSED config22 bits ; UNUSED ;------------------------------------------------------------------------------- ; ; CONFIG23 Bit Definitions ; CONFIG23: ; Bit 0 = Unused ; Bit 1 = Unused ; Bit 2 = Control Strategy for INJ 2 ; 0 = Speed-Density ; 1 = Alpha-N ; Bit 3 = Unused ; Bit 4 = Unused ; Bit 5 = Unused ; Bit 6 = Unused ; Bit 7 = Unused ;---------------------------------------------------------------------------- config23 bits ;-- Boost Controller Settings ---------------------------------------------- bcFreqDiv byte = 2 ; PWM frequency = 10000/(freqDiv*256) ; 1=39.1 Hz, 2=19.5, 3=13.0 bcUpdate byte = 50T ; Clock ticks between updates in ms bcPgain byte = 100T ; Proportional gain bcDgain byte = 100T ; Derivative gain ;-- Rev limiter parameters ------------------------------------------------- revLimit byte = 67T ; Rev limit ;-- Spares ----------------------------------------------------------------- b2_1 byte = $AA b2_2 byte = $AA b2_3 byte = $AA ;-- Cranking RPM, last byte of 256. ---------------------------------------- crankRPM byte = 003T ; RPM below which the engine is cranking. ;============================================================================== ; 128 byte - Flash Page boundary ;============================================================================== } HIGH_RAM = { pageOffset byte = 99 ; Used by SCI routines for paging. ADCselector byte ; ADC Selector Variable ;------------------------------------------------------------------------------- ; Actual engine parameters in engineering units. Pambient byte ; Barometer in kPa kpa byte ; MAP value in kPa coolant byte ; Coolant temperature in deg F plus 40 throttle byte ; Throttle position in percent. GET RID OF THIS, use tuning sw. load byte ; kpa or throttle, depending on SD vs A-N mode. ;------------------------------------------------------------------------------- ; Idle controller variables idleLastDC byte = 100T ; Last Active Idle Duty Cycle idleTarget byte ; Target idle speed. ;------------------------------------------------------------------------------- ; Boost controller data bcDC byte ; Current pwm "duty cycle" (255=100%) ;------------------------------------------------------------------------------- ; Various useful quantities. KPAdot byte ; KPA first derivative, dt=0.1 s KPAlast byte = $FF ; MAP reading updated at 0.01 seconds TPSlast byte = $FF ; TPS reading updated every 0.1 seconds fill byte(100) ; fill with zeros so we can see how low the stack goes... } FLASH = { ; This is used to set the bin coolant range for WWU. WWUrange byte(10) = { 0T, 20T, 40T, 60T, 80T, 100T, 120T, 140T, 170T, 200T } TPSdotrate byte(4) = { 5T, ; 0.1 volts delta 20T, ; 0.4 volt 40T, ; 0.8 volt 77T ; 1.5 volt } ;=========================================================================== ; Nitrous switch parameters. minN2Otemp byte = 160T ; Coolant temperature below which N2O is disabled. lowN2ORPM byte = 035T ; RPM below which N2O is disabled. highN2ORPM byte = 066T ; RPM above which N2O is disabled. ;=========================================================================== ; PD boost controller data. bcTableSize const = 4 bcCTL byte(bcTableSize) = { ; Control variable bins for boost controller set point. ; Use TPS or RPM or whatever you want to control setpoint, I use TPS. ; Barring tuner support, suck these out of your throttlefactor.inc ; Percentages are just my outta the hat values. 25T, ; ADC at 0% throttle 98T, ; 35 127T, ; 50 225T ; 100 } bcSPV byte(bcTableSize) = { ; Set Point Values corresponding to each ctl var bin. 90T, ; kPa at 0% throttle 100T, ; 35 167T, ; 50 167T ; 100 } ;=========================================================================== REVNUM byte = 02T ; revision number, Bruce uses 1x & 2x, we'll use 0.1 }