Math Blocks
Math blocks are the most powerful Arbitrary Math and Logic Block available. The math block runs a language processor that can evaluate many C language operators and functions. The expression has a 40 character limit.
Math AND Logic expressions may be combined.
Many special functions are available. See the Math Block Expression Syntax guide below.
Math Block Configuration
Expression | A Math Block Expression Syntax. The value of parameters below may be referenced via the variables a, b, c and d |
Status | Indicates the result of the Expression. For math expressions, the Status is a number. For logical expressions, the Status is reduced to the values 0, or 1. |
Error | When the Error is not 0, the Expression has resulted in an error or cannot be computed. This happens most often when the expression is invalid. |
Parameter A | the selected parameter value is stored in variable a |
Parameter B | the selected parameter value is stored in variable b |
Parameter C | the selected parameter value is stored in variable c |
Parameter D | the selected parameter value is stored in variable d |
Math Expression Viewer
Math and Logic Expressions can be viewed in a graphic form by clicking to the left of the expression input.
Each block represents a component of the expression and allows a visual overview of any expression
Math Block Expression Syntax
All Math and Logic blocks support the following functions set.
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.
Logic Operators
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. |
^ (xor) | param1^param2 | 5^9 = 0 5^0 = 1 0^1 = 1 0^0 = 0 | a^b results in 1 if one of a or b is non zero, otherwise 0 if a and b are both 0 or both non zero. |
= (equal) == (equal) | param1=param2 or param1==param2 |
| a=b results in 1 if a and b are equal a==b is equivalent to a=b |
!= (not equal) | param1!=param2 |
| a!=b results in 1 if a and b are NOT equal |
> (greater than) | param1>param2 | 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. |
>= (greater than or equal) | param1>=param1 | 5>=5 = 1 5>=0 = 1 5>=6 = 0 | a>=b results in 1 if a is greater than or equal b, otherwise 0.
|
<= (less than or equal) | param1<=param2 | 5<=5 = 1 5<=0 = 0 5<=6 = 1 | a<=b results in 1 if a is less than or equal to b, otherwise 0. |
Math Operators
Function | Syntax | Example | Description |
| 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.
if parameter a is counting up continuously, 0,1,2,3,4,5,6,7,8,9 ... then a%4 results in 0,1,2,3,0,1,2,3,0,1,2,3 ... the example (int(t)%4)+1 results in 1,2,3,4,1,2,3,4,1,2,3,4... on a count of 1 per second
|
+ (add) | param1+param2 | 5+9 = 14 | a+b results in the addition of parameters a and b. |
| 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
Function | Syntax | Example | Description |
if | if(param, then, else) | if(a>4, b, b*5) = b if a>4 =b*5 otherwise | returns the "then" value if the "param" value is true, otherwise results in the "else" value. Any number of if() statements can be added to an expression. |
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 the timeout is 0, the peak is held indefinitely.
|
delta | dt(param, time) | dt(a, 1.0) | Holds the delta value of parameter a, taken over the time specified (in seconds).
|
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).
|
time | t |
| Holds the value of time in seconds since PDM startup. |
Counter | cnt(param) | cnt(a) | Tree running time counter. Starts counting up, once per 10 milliseconds, as long as parameter a is not 0. When parameter a is 0, the counter is reset to 0.
|
edge | ed(param1, param2) | ed(a, b) | Edge counter. Counts rising edges on parameter a, as it passes from less than 1 to greater than or equal to 1. When parameter b is 0, the counter is reset to 0.
|
Numeric Functions
Function | Syntax | Example | Description |
integer | int(param) | int(1.1) = 1 int(t) = time in seconds (without decimal) | removes the decimal places from parameter, resulting in an integer. |
bool | bool(param) | bool(2.5) = 1 bool(0) = 0 | Forces any number or result value that is not 0, to 1. otherwise returns 0. |
min | min(param1, param2) | min(a, b) | results in the value of a or b, whichever is smallest. |
max | max(param1, param2) | max(a, b) | results in the value of a or b, whichever is largest. |
compare | cmp(param1, param2) | cmp(a, b) | results in: -1 if a < b, 1 if a > b, 0 if a = b |
round | round(param, decimals) | round(1.01258, 2) = 1.01 | results in the value of the parameter, rounded to the number of decimals specified. |
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. |
power | pow(a, b) | pow(a, 2) | pow(a, 2) results in the value of parameter a being raised to the power of 2. If a=4, the result would be 16. |
constant, e | e | e = 2.71828 | Euler's number, a special constant |
constant, pi | pi | pi = 3.14159 | Pi, a special constant. |