Pseudocode to VB code to display max knock over the ignition map
Pseudocode to VB code to display max knock over the ignition map
I can read the knocksum, RPM and load no problem. I have myarray defined and displaying as a datagridview that displays the ignition map with its RPM and load axes.
I write what I have in pseudocode below, the stuff marked * help me rewrite to VB - are there VB functions to do this or do I loop through the array and find the nearest site?
dim RPMsites(32) as integer = "500,1000,1500,2000,2500,3000,3500, [etc]
dim loadsites(32) as integer = "0,10,20,30,40,50,60,70,80,90,100,120,140 [etc]
Read knocksum
Read RPM
Read load
RPMsite=getRPMsite(RPM) 'function to lookup what cell position for RPM
loadsite=getloadsite(load) 'function to lookup what cell position for load
if myarray(RPMsite,loadsite)=" "
myarray(RPMsite,loadsite)=knocksum 'if cell unpopulated load with present knocksum
elseif knocksum>myarray(RPMsite,loadsite)
myarray(RPMsite,loadsite)=knocksum 'if knocksum greater than old value, populate with present knocksum
endif
******************
function RPMsite(RPM)
'I need this function to return the RPMsite array position that has the value that is nearest to the RPM value
return RPMsite
'----------------------------
function loadsite(load)
'I need this function to return the loadsite array position that has the value that is nearest to the load value
return loadsite
********************
I write what I have in pseudocode below, the stuff marked * help me rewrite to VB - are there VB functions to do this or do I loop through the array and find the nearest site?
dim RPMsites(32) as integer = "500,1000,1500,2000,2500,3000,3500, [etc]
dim loadsites(32) as integer = "0,10,20,30,40,50,60,70,80,90,100,120,140 [etc]
Read knocksum
Read RPM
Read load
RPMsite=getRPMsite(RPM) 'function to lookup what cell position for RPM
loadsite=getloadsite(load) 'function to lookup what cell position for load
if myarray(RPMsite,loadsite)=" "
myarray(RPMsite,loadsite)=knocksum 'if cell unpopulated load with present knocksum
elseif knocksum>myarray(RPMsite,loadsite)
myarray(RPMsite,loadsite)=knocksum 'if knocksum greater than old value, populate with present knocksum
endif
******************
function RPMsite(RPM)
'I need this function to return the RPMsite array position that has the value that is nearest to the RPM value
return RPMsite
'----------------------------
function loadsite(load)
'I need this function to return the loadsite array position that has the value that is nearest to the load value
return loadsite
********************
... here: https://www.evolutionm.net/forums/sh...d.php?t=251750
By the way: I hate this search pause "Wait 15 seconds for next search bla bla"
By the way: I hate this search pause "Wait 15 seconds for next search bla bla"
Thanks, just had a look at the code. Your cell finder is going to put everything in the 3000-3499 RPM range into the 3000 RPM cell, and the 240-249.9 load into the 240 cell. The ECU is putting 2750-3249 into the 3000 RPM cell, and 235-244.9 into the 240 cell.
So to match the behaviour of the ECU we need to work out which is the nearest cell rather than which is the cell it rounds down to. Any ideas on the code for this? Measure the distance from the point to the two nearest cells and work out which is nearer and use that? A clumsy method would be a second lookup table which was half way between the ECU lookup tables, but I don't like that idea.
So to match the behaviour of the ECU we need to work out which is the nearest cell rather than which is the cell it rounds down to. Any ideas on the code for this? Measure the distance from the point to the two nearest cells and work out which is nearer and use that? A clumsy method would be a second lookup table which was half way between the ECU lookup tables, but I don't like that idea.
ecuEdit does the same thing. It drives me a little nuts.
This will subtract each RPM/Load scale value from the logged value, take the absolute value and record the difference. The scale value with the smallest difference wins. So 3600 would use the 3500 cell, 3800 would use the 4000 cell
Code:
RPM = Selection.Cells(z, 1)
LoadECU = Selection.Cells(z, 2)
lowestDiff = 15000
For i = 5 To 19
a = Sheets("Trace AFR").Cells(i, 2)
diff = Abs(RPM - a)
If diff <= lowestDiff Then
lowestDiff = diff
Cell = i
End If
Next i
lowestDiff = 15000
For i = 3 To 22
a = Sheets("Trace AFR").Cells(4, i)
diff = Abs(LoadECU - a)
If diff <= lowestDiff Then
lowestDiff = diff
Column = i
End If
Next i
Last edited by merkzu; May 18, 2007 at 10:43 AM.
Trending Topics
This tool seems to select multiple cells sometimes and average them, the values are way off from my logs so I don't think it's doing the same thing as the ecu. I commented out all the code that does that so it only highlights the exact cell hit. The values are a lot closer but still off, by 1-2 degrees on ignition.. has the actual formula been worked out for that?
Depends on how accurate the load is, I propose to use the real load for doing this live, rather than using estimated load and offline loading up of log files.
It will be on the same form as the live editable ignition map.
It will be on the same form as the live editable ignition map.
Thread
Thread Starter
Forum
Replies
Last Post
richardjh
09+ Ralliart Engine/Turbo/Drivetrain
156
Apr 30, 2012 05:32 AM
tephra
Evo X Engine Management / Tuning Forums
14
Aug 23, 2010 08:27 AM




