The Math Block feature allows a user configurable maths channel which can be used for a variety of purposes. The features has provision for up to 4 variables, supports most standard operators and supports equations up to 20 characters long. The various settings and a description of their operation are listed below.
Up to 8 Math Blocks are currently supported.
This setting allows the user to enter a label or short description which will be displayed next to the Runtime Value name of the specific Math Block being used making it easier to identify which Math Block is doing which operation.
These four settings allow the user to select which Runtime Values or Statuses will be used in the Equation as variables.
This setting allows the user to select how many decimal places they want shown on the Runtime Value of the Math Block being setup.
This text box allows the user to enter the equation they want calculated, the variables must be entered in their lower case forms (a,b,c&d).
Using a Math Block
·Parameters a, b, c and d reflect the current value of any ECU runtime value.
·The equation is calculated at a rate of 1kHz.
·The equation may contain any combination of math functions, up to 20 characters.
·Parameters are sampled at the time of calculation.
In the tables below
·param/param1/param2 may be set to any of parameters a, b, c or d.
·param/param1/param2 may be set to any number value.
Numeric functions
Math Function |
Syntax |
Example |
Description |
Absolute value |
abs(param) |
abs(-25.6) = 25.6 abs(25.6) = 25.6 |
abs(a) results in a positive number no matter if a is positive or negative. |
ceiling |
ceil(param) |
ceil(-25.6) = -25 ceil(25.6) = 26 |
ceil(a) results in the smallest integer that is greater than or equal to a (i.e : rounds up to the nearest integer). |
floor |
floor(param) |
floor(-25.6) = -26 floor(25.6) = 25 |
floor(a) results in the smallest integer that is smaller than or equal to a (i.e : rounds down to the nearest integer). |
exponential |
exp(param) |
exp(6) = 403.428 |
exp(a) results in the value of e (Euler's number), to the power of a. |
logarithm, natural |
ln(param) |
ln(2) = 0.693 |
ln(a) results in the natural log of a. |
logarithm, base 10 |
log(param) |
log(2) = 0.301 |
log(a) results in the log base 10 of a. |
power |
pow(param1, param2) |
pow(6, 2) = 36 |
pow(a, 2) results in a to the power of 2. |
square root |
sqrt(param) |
sqrt(25) = 5 |
sqrt(a) results in the square root of a. |
cosine |
cos(param) |
cos(pi) = -1 |
cos(a) results in the trigonometric cosine of a. |
sine |
sin(param) |
sin(pi) = 0 |
sin(a) results in the trigonometric sine of a. |
tangent |
tan(param) |
tan(pi) = 0 |
tan(a) results in the trigonometric tangent of a. |
constant, e |
e |
e = 2.71828 |
Euler's number, a special constant |
constant, pi |
pi |
pi = 3.14159 |
Pi, a special constant. |
Logic functions
Math Function |
Syntax |
Example |
Description |
not |
!param |
!1 = 0 !100.1 = 0 !0 = 1 |
!a results in 0 if a is not zero, and 1 if a is zero. |
and |
param1¶m2 |
5&9 = 1 5&0 = 0 |
a&b results in 0 if either a or b is zero, otherwise 1.
|
or |
param1|param2 |
5|9 = 1 5|0 = 1 |
a|b results in 1 if either a or b is 1, otherwise 0. |
graeter than |
param1>param1 |
5>9 = 0 5>0 = 1 |
a>b results in 1 if a is greater than b, otherwise 0.
|
less than |
param1<param2 |
5<9 = 1 5>0 = 0 |
a<b results in 1 if a is less than b, otherwise 0. |
Math functions
Math Function |
Syntax |
Example |
Description |
multliply |
param1*param2 |
5*9 = 45 |
a*b results in the multiplication of parameters a and b. |
divide |
param1/param2 |
5/9 = 0.556 |
a/b results in parameter a divided by parameter b.
|
modulus |
param1%param2 |
4%5 = 4 5%5 = 0 6%5 = 1 |
a%b results in the modulus of parameters a and b. modulus computes the remainder of a divided by b. |
power |
param1^param2 |
5^9 = 1953125 |
a^b results in parameter a to the power of parameter b.
|
add |
param1+param2 |
5+9 = 14 |
a+b results in the addition of parameters a and b. |
subtract |
param1-param2 |
5-9 = -4 |
a-b results in the subtraction of parameters a and b. |
braces |
param1*(param2+param3) |
10*(287+1000) = 12870 10*287+1000 = 3870 |
controls the order of precedence in calculations. |
Special functions
Math Function |
Syntax |
Example |
Description |
peak |
pk(param, timeout) |
pk(a, 1.0) |
holds the peak value of parameter a. if the value of parameter a. does not change within the timeout (in seconds) the peak is set to the current value of a. if timeout is 0, the peak is held indefinitely. Only one 'pk' function may be used per equation. |
delta |
dt(param, time) |
dt(a, 1.0) |
holds the delta value of parameter a, taken over the time specified (in seconds). Only one 'dt' function may be used per Math Channel. |
average |
av(param, time) |
av(a, 1.0) |
holds the average value of parameter a, taken for 20 evenly spaced samples over the time specified (in seconds). Only one 'av' function may be used per Math Channel. |
time |
t |
|
holds the value of time in seconds since ECU startup. |
Counter, fre running |
cnt(param) |
cnt(a) |
starts counting up, once per millisecond, as long as parameter a is not 0. when parameter a is 0, the counter is reset to 0. Only one 'cnt' function may be used per Math Channel. |
edge |
ed(param1, param2) |
ed(a, b) |
counts rising edges on parameter a, as it passes from less than 1 to greater than 1. when parameter b is 0, the counter is reset to 0. Only one 'ed' function may be used per Math Channel. |
Examples
When Units are set to degrees C but you want one digital gauge that shows ECT in Fahrenheit.
·set math block label to "ECT (Fahrenheit)"
·set math block parameter a to ECT
·set math block equation to (a*9/5)+32
When Units are set to kPa but you want one digital gauge that shows MAP in PSI.
·set math block label to "MAP (PSI)"
·set math block parameter a to MAP
·set math block equation to a/6.895