Possible bug ?

pjrebordao

Senior Member
Inside PE6, I simulated running the following piece of code for a 20X2.
While performing the IF, both the first and last sections of code were executed... It should have been only the first one.


"
Code:
"
symbol IX_BIN_SIZE = 15 				' size of each vector
symbol IX_MAP_X = 12
symbol IX_TOP = 121           		   ' last address in EEPROM
' vars for holding values read from sensors
symbol RAW_MAP = w3

' vars for holding sensor values after map_int
symbol MAP_MAP = b39

symbol I = b22    					' generic byte counter for loops, etc
symbol Z = w5
symbol X1 = w6
symbol X2 = w7
symbol Y1 = w8
symbol Y2 = w9

'macro map_interpolate(index, in_var, out_var)  			' defined as a macro to avoid gosub time overhead
' map_interpolate (map_int)
' linear interpolation according to Y = Y1 + (Y2-Y1)*((X-X1)/(X2-X1))
' problemas com tamanho (byte / word ?)
'
' search for the right bin
' on exit, ptr will contain the upper limit of the bin found
	


data (0,0,0,0,0,0,0,0,0,0,0,0)
' MAP raw data (x-bins)
data (10,12,14,16,20,24,28,32,34,36,38,38,40,40,40)
' MAP time data (y)
data (15,15,17,13,11,11,9,9,7,7,5,5,8,8,8)
' TPS raw data (x-bins)
data (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
' TPS time data (y)
data (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
' TMP raw data (x-bins)
data (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
' TMP time data (y)
data (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
' IDLE PWM data (y)- uses the TMP x-bins
data (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
' several configuration variables (5)
data (0,0,0,0,0)

main:

let ptr = 0
for I = 0 to IX_TOP
	read I, @ptrinc
next I
	
let RAW_MAP = 42

	let I = 0
	let ptr = IX_MAP_X
	do while RAW_MAP > @ptr and I < IX_BIN_SIZE
		inc I
		inc ptr
	loop
' detect if lower or upper bound / bin
' *** simplificar
' e se RAW_MAP = @ptr and I > 0 ?
'
	if I = IX_BIN_SIZE then    
		let ptr = ptr + IX_BIN_SIZE - 1  
		let MAP_MAP = @ptr
	elseif I = 0 or RAW_MAP = @ptr then
		let ptr = ptr + IX_BIN_SIZE
		let MAP_MAP = @ptr
	else
		let X2 = @ptr
		dec ptr
		let X1 = @ptr
		let MAP_MAP = RAW_MAP - X1
		let Z = X2 - X1
		let MAP_MAP = MAP_MAP * 100 / Z
		let ptr = ptr + IX_BIN_SIZE
		let Y1 = @ptr
		inc ptr
		let Y2 = @ptr
		if Y2 > Y1 then
			let MAP_MAP = Y2 - Y1 * MAP_MAP / 100 + Y1 
		else
			let MAP_MAP = Y1 - Y2 * MAP_MAP / 100 + Y2
		endif
	endif

end
"
"
 
Last edited:

techElder

Well-known member
Pjr, its common practice to surround your code section in this forum with "[code]" and "[/code]". That will highlight your code and provide scroll bars.

Perhaps by adding the "code" format we would see some indenting in your code? Indenting those IF / ELSE statements would make it a lot more clear.
 

hippy

Technical Support
Staff member
It seemed to work okay for me. Perhaps make sure you have the latest PE6.
 
Top