MIL warning when knock occurs : patch routines for Z32 ECU

Discuss possible software enhancements/changes here.

Moderator: Matt

Post Reply
RomChip200
 

Posts: 426
Joined: Mon May 11, 2009 7:58 pm
Location: FRANCE

MIL warning when knock occurs : patch routines for Z32 ECU

Post by RomChip200 »

Here is a routine that triggers the MIL (engine check light) each time knock occurs, furtively or sustained.
This applies to 47P10 based image (but can be ported to any other Z32 ECU image) and uses the free space available in OEM image.
MIL meaning is now different depending on the car state:
1) gear engaged+throttle depressed (driving): if MIL becomes on = furtive knock
2) gear engaged+throttle released(driving): if MIL stays on = sustained knock occured
3) idle+no gear: if MIL stays on = knock map is used
4) idle+ throttle depressed: if MIL is on = the ECU threw an error code (original behaviour)
For 1) and 2), the tp, rpm, timing and temp are saved in some dedicated variables that can be checked afterwards (even if you switch off engine). Basically it stores the latest occurrences of knock.
First detection starts when you reach 3000rpm.
Max. TP (above 2000rpm) and max. temp are also stored to track engine behaviour.
On first startup, if MIL toggles, it means the routine is in place and works. On first throttle blip, it must switch off if everything is normal and you can go.

Attached file for source and patch bin file (only changed locations are different of 0xFF).

Code: Select all

flags		EQU	0x40
flags6		EQU	0x55
flags10		EQU	0x5A
flags8		EQU	0x82
flags5		EQU	0x8B
port6_copy      EQU	0xE0

knock_count     EQU	0x14BD

engine_temp	EQU	0x140C
timing		EQU	0x1443
vq		EQU	0x1453 54
rpm		EQU	0x140A 0B
maf		EQU	0x1408 09
;tp		EQU	0x1417 18
tp1		EQU	0x151F 20
timing_offset2	EQU	0x1614 15
knock_value	EQU	0x1610 11

afr_const24     EQU	0xFEE7
fb_control      EQU	0xFF91 


ram2_checksum	EQU	0x16A0
word_398	EQU	0x16DE DF
ram2_mid2       EQU	0x16A0



; ************ Variables in ram2_checksum region ***************

base		EQU	0x16E8

tp_max		EQU	0x16E8
timing_tp_max	EQU	0x16E9
rpm_tp_max	EQU	0x16EA EB 
temp_tp_max	EQU	0x16EC
temp_max	EQU	0x16ED

kd_tp		EQU	0x16F0      save in case of knock detection (highlighted by timing_offset2)
kd_kvalue	EQU	0x16F1
kd_rpm   	EQU	0x16F2 F3
kd_timing       EQU	0x16F4
kd_temp		EQU	0x16F5



kr_tp           EQU	0x16F8      save in case of knock repetitive (highlighted by knock_value)
kr_kvalue       EQU	0x16F9
kr_rpm   	EQU	0x16FA FB
kr_timing       EQU	0x16FC
kr_temp		EQU	0x16FD


version_save	EQU	0x16FF

; Variables shifted in the memory space not covered by ram2_checksum
kd_count	EQU	0x169C
kr_count	EQU	0x169D
MILstatus	EQU	0x169E
toggle_rpm	EQU	0x169F



begin_var	EQU	base
end_var		EQU	version_save

; ******************************************
		 




main_loop 	EQU	0xC3FE


	org 0x0000
	fcb 0xFF		 dummy

PATCHS

	org 0xC0B3   in reset
	jmp var_reset

	org 0xC0C0     in reset
	jmp var_reset

	org  0xC43F    in main_loop
	nop
	nop
	jsr  test


END_PATCHS

	org 0xFFFF
	fcb 0xFF	dummy, just to reach 0xFFFF size 	




; --------------------------------------------------------------------------------------------------
	org 0xE000 	   for special bin in location #7
var_reset
	sei
	clr tp_max
	clr temp_max
	clr kd_count
	clr kr_count
	cli
	nop
	clr toggle_rpm     for all bins from here
	jmp main_loop		



; --------------------------------------------------------------------------------------------------
	org 0xE200 

test
	tim %1,flags5      1 if rpm >1000rpm ; bit 1 (high octane if 0) of flags6 is dependent of this flag
	bne go_test	
check_version
	sei
	ldaa VERSION+10
	cmpa version_save
	bne reset_all
	cli
	rts
reset_all
	staa version_save
	clra
	ldx #begin_var                       
resetvar
	staa 0,x
        inx
        cpx #end_var	 keep version intact
        bne resetvar
	jmp miloff


go_test
	ldaa rpm+1
	cmpa #240	  > 3000rpm ?
	bhi rpm_toggle
	tst rpm
	beq go_on
rpm_toggle
	ldaa #1
	staa toggle_rpm
go_on
	tst toggle_rpm
	bne no_clear
	clr kd_count	clear for each startup
	clr kr_count
no_clear
	ldaa engine_temp
	cmpa temp_max
	bls go_on2
	staa temp_max
go_on2
	sei
 	ldaa rpm+1
	cmpa #160	  > 2000rpm ?
	bhi tp_test
	tst rpm
	beq go_on3
tp_test
	ldaa tp1
	cmpa tp_max
	bls go_on3
	staa tp_max
	ldd  rpm
	std  rpm_tp_max
	ldaa timing
	staa timing_tp_max
	ldaa engine_temp
	staa temp_tp_max
go_on3
	cli
	ldaa flags6       bit0= throttle (1=released) bit1= high octane (if 0) bit2= gear (1= no gear) 
	anda #%101	       
	cmpa #%000
	beq accel	       gear is engaged and throttle is depressed
	cmpa #%001
	beq gear_engaged       gear is engaged and throttle is fully released
	cmpa #%101
	beq true_idle	       no gear and throttle is fully released

	bra test_miloff       real ECU error can be checked in idle (no gear) and throttle is depressed, if still on ==> ECU error
	
;----------------------------------
true_idle
	clr kd_count   	       throttle released + full idle, we may clear the flag for next time	

	tim %100,flags10       knock map in use ?
	beq milon
	bra test_miloff	

		
;----------------------------------
gear_engaged
	ldaa knock_value       repetitive knock situation ?
	beq test_miloff
	cmpa #252	       knock_value <=252 but still above 248 (knock map threshold)
	bls knock_repetitive
	cmpa #253	       came back to normal situation i.e. >=254 ?
	bhi back_to_normal
	rts
back_to_normal
	clr kr_count
	bra test_miloff
knock_repetitive
	sei
 	tst toggle_rpm
	bne rpm_condition_ok1
	bra milon
rpm_condition_ok1
 	tst kr_count
	beq kr_save
	bra milon
kr_save
	inc kr_count	         allow to track the latest occurence of knock repetitive i.e. <=252
	ldaa tp1
	staa kr_tp
	ldaa knock_value 
	staa kr_kvalue
	ldd rpm
	std kr_rpm
	ldaa timing
	staa kr_timing
	ldaa engine_temp
	staa kr_temp
	bra milon


 ;-----------------------------------------------------------

test_miloff
	tst MILstatus
	bne miloff
	rts	

milon
	ldaa #0x88
	staa MILstatus
     	oim %01000000,port6_copy
	cli
	rts

miloff
	clr MILstatus
	aim %10111111,port6_copy
	cli
	rts

;-----------------------------------------------------------
	
	
;----------------------------------
accel
	ldaa timing_offset2       instant knock situation and then, timing pulled ?
	beq test_miloff	
	cmpa #253	          >= 3° of retard
	bls knock_detected
 	bra test_miloff	          otherwise came back to normal situation i.e. >=254 ?
knock_detected
	sei
 	tst toggle_rpm
	bne rpm_condition_ok2
	bra milon
rpm_condition_ok2
	tst kd_count
	beq kd_save
	bra milon
kd_save
	inc kd_count      allow to track the latest occurence of timing pulled i.e. <=253
	ldaa tp1
	staa kd_tp		   	
	ldaa timing_offset2
	staa kd_kvalue
	ldd rpm
	std kd_rpm
	ldaa timing
	staa kd_timing
	ldaa engine_temp
	staa kd_temp
	bra milon




	org 0xE350      to check potential overlap with the tpu_param_1 table
******************************
VERSION fcc  'KNOCK v14.0_0'
Attachments
Knock_test_v14.0.zip
(2.48 KiB) Downloaded 255 times
Post Reply