Torque

Forums

Forums

Guest  

Show or hide header
Welcome Guest, posting in this forum require registration.




Torque » Torque OBD ECU Scanner » Torque Discussion / Ideas » Automated Math Equation Generator

Pages: [1]
Author Topic: Automated Math Equation Generator
nkemp
Member
Posts: 33
Post Automated Math Equation Generator
on: March 27, 2017 (GMT)

After reading Aberk’s: https://torque-bhp.com/forums/?wpforumaction=viewtopic&t=352.0 istructions on creating equations I thought I could create an Excel tool to do it automatically. It all went relatively easy … except the results raised some questions.

UPDATE: In post 10 below, I list the Excel code that works for me. The questions below were resolved.

Can Any MATH equation experts can help?

Aberk’s process converts the last 4 MTH digits (FE70) to 400 (Using the calculator or doing so in Excel). And since the first character is “F” then it is subtracted. Hold that thought.

In some cases, the equation is needed to convert degrees C to Degrees F. The normal equation is C*9/5 +32. Hold that thought.

When you process MTH: 00090005FFD8 009 = 9, 0005 = 5, FFD8 converts to 40 and since the first character is “F” then it is subtracted. This yields a conversion factor of 9/5-40 when 9/5+32 is expected.

So two problems:
– Why the – instead of the +
– Why the 40 instead of the 32?

In the sample he uses, the result is: ((((A*256)+F)*(7/100)-400)/10)
Using the same process, for the above MTH the result is A*9/5-40

Does that explain the problem?

Capp777
Member
Posts: 2993
Post Re: Automated Math Equation Generator
on: March 27, 2017 (GMT)

°F=°C*(9/5)+32

So if A-40 = °C then…

°F= (A-40)*(9/5)+32
°F= (A*(9/5))-(40*(9/5))+32
°F= (A*(9/5))-(360/5)+32
°F= (A*(9/5))-(72)+32
°F= A*(9/5)-40

Hopes this helps your understanding
of the -40 vs +32.

nkemp
Member
Posts: 33
Post Re: Automated Math Equation Generator
on: March 28, 2017 (GMT)

But that deviates from Aberk’s process.

Plus I’m under the assumption that the equation is derived solely from the MTH values and does not require additional info. In the above one assumes the equation is a C->F conversion. That info is not embedded in the MTH data.

Or am I wrong in that the math equation is fully contained in the MTH data?

Capp777
Member
Posts: 2993
Post Re: Automated Math Equation Generator
on: March 28, 2017 (GMT)

Byte A sent from your vehicle is either
°C or °F. If an equation is converting it
to °F then I would have to conclude byte
A is in °C otherwise the results would be
incorrect.

nkemp
Member
Posts: 33
Post Re: Automated Math Equation Generator
on: March 28, 2017 (GMT)

My understanding (which is subject to being wrong without notice :) is that the MTH data contains equation info to understand the data returned. In this case the data is temperature data and it is rumored that the temperature is sent in degrees C. As such it could be displayed without modification (A) … (see next post from me).

The generic equation presented via MTH is x/y + (or -) z.
– If y is “1” then the equation is x +(or “-“) z
– If Z is “0” then the equation is x/y

The values of x, y & z are derived from mth. x is the 1st four hex coded characters, y is the 2nd four hex coded characters and z is the last four two’s compliment hex coded characters.

EXAMPLE(using the above referenced method): MTH: 00090005FFD8 0009 = 9, 0005 = 5, FFD8 converts to 40 and since the first character is “F” then it is subtracted. This yields a conversion factor of 9/5-40 ( a 32 degree F spread)

Obviously this is the wrong C->F conversion formula. If one would assume it includes a correction factor the problem with that thinking is that it only corrects the “F” display and not the “C” version.

It could be that the raw data is not actually degrees C (see next post from me).

As such … I’m trying to verify the understanding of decoding the MTH.
– Is the referenced method correct.
– Is the rumor that the data is degrees C correct?

BTW … here is the ScanGauge text for MTH
The Add/Subtract (z in the generic equation above)adds the 2 byte value to the results from the multiply (x) and divide(y). This is a signed value.
– If the upper bit is set, the value is the two’s compliment negative value.
– If the result has the highest bit set, the response will assume it is a two’s compliment negative value and will show it as a negative value
.

The two bullets are confusing because to me, they read the same. Aren’t the “upper bit” and the “highest bit” the same? Then both bullets says it is two’s compliment negative value. The second bullet seems to be only redundant information.

nkemp
Member
Posts: 33
Post Re: Automated Math Equation Generator
on: March 28, 2017 (GMT)

So I created a PID to test for Hybrid Battery Inlet Temperature.

First I used the equation A*9/5-40 and hit the TEST button. Results:
Results for equation: 60.8
Command: 224107
7E7F04624100738 The first test showed this, subsequent tests did not display this data
Subsequent tests displayed 62410738
A=56
Hex=38
Binary = 00111000

Then I ran the test with the equation set to “A”. This should be the degrees C reading if the data is actually degrees C

Results for equation: 56.0
Command: 224107
response 62410738 (and alternates with “?”
A=56
Hex=38
Binary = 00111000

Note that the outside ambient is about 57F and the vehicle had been driven about 5-6 hours earlier. The hybrid batteries are located inside the vehicle. I can’t get to the batteries but inside the vehicle it is 55F to 61F.

So what does this tell me? … I’m not sure
– The raw “A” data likely is not degrees C
– The temperature with and without the equation is close and close to ambient in this case (I should have done this when it was -20F and it had time to soak.)
– the 9/5-40 equation may only be coincidentally close to the C->F conversion formula

So this is not really helping confirm or deny the equation generation process accuracy.

Capp777
Member
Posts: 2993
Post Re: Automated Math Equation Generator
on: March 28, 2017 (GMT)

Quote from nkemp on March 28, 2017
So I created a PID to test for Hybrid Battery Inlet Temperature.

First I used the equation A*9/5-40 and hit the TEST button. Results:
Results for equation: 60.8
Command: 224107
7E7F04624100738 F conversion formula

So this is not really helping confirm or deny the equation generation process accuracy.

End Quote.

Byte A=38 hex=56 decimal

so…

56-40=16 °C which converts to
56*(9/5)-40=°F
100.8-40=°F
60.8=°F

16*(9/5)+32=°F
28.8+32=°F
60.8=°F

nkemp
Member
Posts: 33
Post Re: Automated Math Equation Generator
on: March 28, 2017 (GMT)

Capp777 … I had to edit my last post since it got mangled when I hit submit. It truncated the message for whatever reason. FYI

Your insite confirms that the data is not presented as degrees C. It also seems to confirm that the process originally referenced works.

nkemp
Member
Posts: 33
Post Re: Automated Math Equation Generator
on: March 28, 2017 (GMT)

Is there a way to post the excel spreadsheet for others to use? BTW … it does not use macros.

nkemp
Member
Posts: 33
Post Re: Automated Math Equation Generator
on: March 29, 2017 (GMT)

In the absence of a method of posting an Excel spreadsheet, here is a list of the code used. This may or may not work as shown using Google Sheets (or any other spreadsheet). If not, the spreadsheet likely has a function similar but with slightly different implementation.

I had a bunch of PIDS and MTH’s to create formula from. This really simplified the process. Plus it eliminated “I did it wrong errors”.

Implement the equations in Excel as shown and it should work as mine does. There may be better, easier or more efficient ways to perform the task of parsing the MTH data for the equations …. but this works. For that matter, it could be built into the Torque application so that you’d enter the MTH data and Torque parsed it for you…Ian?

Inputs:
D7 = RXF value (example: 032180000000 )
D8 = RXD value (example: 2810 )
D9 = MTH Value (example: 00070064FE70 )

Create the following cells:
CELL FORMULA
F7 =MID(E7,5,1)
F8 =MID(E8,1,2)
G8 =MID(E8,3,2)
F9 =MID(E9,1,4)
G9 =MID(E9,5,4)
F10 =HEX2DEC(F9)
G10 =HEX2DEC(G9)
J6 “EQUATION—>”
K6 =CONCATENATE(“((“,K8,”*”,K10,”/”,K7,”)”)
K7 =IF(F7=”4″,100,IF(F7=”8″,10,1))
K8 =IF(G8=”10″,”((A*256)+B)”,”A”)
I9 =MID(H9,1,1)
J10 =IF(OR(I9=”F”, I9=”E”, I9=”D”, I9=”C”, I9=”B”,I9= “A”, I9=”9″, I9= “8”),”-“,””)
K10 =CONCATENATE(“(“,F10,”/”,G10, “)”,H11,”)”)
H9 =MID(E9,9,4)
H10 =MOD(HEX2DEC(H9)+2^15,2^16)-2^15
H11 =TEXT(H10,”+#,###;-#,###;+0″)

The final equation is located in Cell K6

Note:
Let’s say your equation looks like this: (A*(100/255)+0)/1)
Looking at the part that looks like: +0)/1)

In math equation terms:
+0 adds nothing to the value and
/1 does nothing to the value
As such, both can be eliminated (or left in … your option) from the equation so that it looks like this:
(A*(100/255))

They are there because I did not complicate the tool to automatically eliminate them.

Note also that extra parenthesis pairs can also be eliminated (optional). If the parenthesis don’t balance, balance as needed

———————–
If you are copying text from elsewhere and it looks like this:

TXD: 07E021D9 
RXF: 032180000000 
RXD: 2810
MTH: 00070064FE70
NAM: TFT

Paste into C23, C24, C25, C26, C27 respectively.

The following formulas will parse out the data from the text automatically from C23, C24, C25, C26, C27. Then you can COPY and PASTE SPECIAL – PASTE_VALUES into the above cells D7, D8, D9. Or set D7:=E23, D8: =E24, D9: =E25 to get the data automatically from E23,E24, E25)

Note: The ID and Value need not be typed into cells and are shown for reference only. When I created this post, some of the formatting was lost and makes the following a bit harder to read. The first line shows the ID, the 2nd line shows the value and they alternate from there. Dashes were added to trick the forum tool to help with spacing.

Address____Formula _______________________ID_______Value
D23 =MID(C23,1,FIND(“:”,C23,1)) _________ TXD:
E23 =TRIM(MID(C23,1+FIND(“:”,C23,1),30)) _____________ 07E021D9 
D24 =MID(C24,1,FIND(“:”,C24,1)) _________ RXF:
E24 =TRIM(MID(C24,1+FIND(“:”,C24,1),30)) _____________ 032180000000 
D25 =MID(C25,1,FIND(“:”,C25,1)) _________ RXD:
E25 =TRIM(MID(C25,1+FIND(“:”,C25,1),30)) _____________ 2810
D26 =MID(C26,1,FIND(“:”,C26,1)) _________ MTH:
E26 =TRIM(MID(C26,1+FIND(“:”,C26,1),30)) _____________ 00070064FE70
D27 =MID(C27,1,FIND(“:”,C27,1)) _________ NAM:
E27 =TRIM(MID(C27,1+FIND(“:”,C27,1),30)) _____________ TFT

SJ74
Member
Posts: 5
Post Re: Automated Math Equation Generator
on: August 9, 2017 (GMT)

Do you have an example excel sheet?

diesl
Member
Posts: 26
Post Re: Automated Math Equation Generator
on: August 13, 2017 (GMT)

I know it’s an old thread, but since there seems to be some confusion: (some) temperatures are reported as C+40 (to avoid negative numbers). That info seems to be missing in the OPs posts.

2012 VW JSW TDI w/ DSG

Pages: [1]
WP-Forum by: Fredrik Fahlstad, Version: 2.4
Page loaded in: 0.042 seconds.

  Follow me on twitter