# Thread: MATHDR32 mathematics drive is too weak?

1. User
Join Date
23.04.2009
Posts
56

## MATHDR32 mathematics drive is too weak?

Now, I have a question about MATHDR32 driver: How can I make an integer (Int) function?

Details:

- My objective :

Now my ZenOn receives a variable X1 (between 0kW - 1000kW) which is changed every second with a decimal 0. That means, even if my power changed from 10kW to 11kW, ZenOn would create a little visual impact to the RT user. Imagine if I have hundred of variables on one screen, this impact would becomes unpleasant.

So, what I want is, 1) I want to keep the refresh time to every second, in order to be alert to the transient; 2) If the value is not changed so much (for example, 25kW a step), ZenOn shows the same value as before to reduce the visual impact.

- What I have tried:
Simply, I thought if there was a Int() function in your MATHDR32 driver, I could do the following:
X2 = Int (X1/25) * 25
So, instead of X1, I can show X2 which is totally according to what I want.

But, the problem is, I find that the MATHDR32 driver is too weak... There are only a few poor functions. It does not support Int() function ! ( even if your Report Generator supports an Int() function )

So, return to my question: How can I manage to make an integer function for a variable, or have I another way to achieve my goal?

2. ## Re: MATHDR32 mathematics drive is too weak?

I would not consider the mathematic driver as weak. It has many useful functions, like standard deviation over time, logical functions, data reduction, arithmatic functions etc. etc.

The "problem" in your case, is that the mathematic driver calculates in floating point numbers (also the division) and not in natural numbers.

I can see two fairly easy solutions for your goal to have some kind of dead-band or hysteresis for the display of your variable in the picture, and still have the original value for e.g. alarming or archiving.

One possibility is to use non linear value adjustment via VBA. You can use an allocation to assign your variable from the PLC to a dummy variable (displayed in your picture). The moment the value changes in the PLC, the dummy variable changes. At the dummy variable, a VBA macro is linked with 3 lines of code (can be one VBA macro for all variables) which performs exactly this calculation. (dummyvalue = (plcvalue / 25)*25)

Also you could use the soft-plc straton for the calculation. When you set the option "externally visible" your variable from your PLC is available immediately in straton, where you can use the value to e.g. perform a calculation, and assign it to a variable from the straton driver (displayed in your picture)

3. User
Join Date
23.04.2009
Posts
56

## Re: MATHDR32 mathematics drive is too weak?

Thank you a lot for your reply. I am trying your first solution by using a VBA Macro. But this is the first time I use VBA Macros, would you kindly reply me a basic question : How to write a VBA Macro for my case?

What I have tried:

1) My origin variable is called "BR_Somme_TotPac", which is a sum of some variables from a 61850 driver, and which I want to handle.

2) I created a new "dummy" variable, named "TestAAA" as an Internal Variables.

3) In allocation window, I created a new Allocation, named "Allocation 0". I filled [Source variable] as "BR_Somme_TotPac", and [Target variable] as "TestAAA"

4) In the [Scripting] -> [VBA Macros] -> [ModuleVariables] -> [AdjustHardwareValue], I created a new Macro, named [AdjustHardwareValue_Default], and edited it as following just for a test:

Public Function AdjustHardwareValue_Default(obVar As Variable, vValue As Variant) As Double
TestAAA = BR_Somme_TotPac * 2 + 345
End Function

5) In the properties of the "TestAAA" variable, I chose the [Value calculation] -> [Value adjustment non-linear] -> [Non linear value adjustment with macros]. Then I chose my "AdjustHardwareValue_Default" Macro as [AdjustHardwareValue].

That is all I have done. But it seemed not work. I have doubts about the little three line VBA program I wrote, but I didn't find a help document to teach me this basic usage.. So I post my question here and waiting for your help.

Originally Posted by MarkClemens
I would not consider the mathematic driver as weak. It has many useful functions, like standard deviation over time, logical functions, data reduction, arithmatic functions etc. etc.

The "problem" in your case, is that the mathematic driver calculates in floating point numbers (also the division) and not in natural numbers.

I can see two fairly easy solutions for your goal to have some kind of dead-band or hysteresis for the display of your variable in the picture, and still have the original value for e.g. alarming or archiving.

One possibility is to use non linear value adjustment via VBA. You can use an allocation to assign your variable from the PLC to a dummy variable (displayed in your picture). The moment the value changes in the PLC, the dummy variable changes. At the dummy variable, a VBA macro is linked with 3 lines of code (can be one VBA macro for all variables) which performs exactly this calculation. (dummyvalue = (plcvalue / 25)*25)

Also you could use the soft-plc straton for the calculation. When you set the option "externally visible" your variable from your PLC is available immediately in straton, where you can use the value to e.g. perform a calculation, and assign it to a variable from the straton driver (displayed in your picture)

4. ## Re: MATHDR32 mathematics drive is too weak?

non linear value adjustment does not work with the internal driver. So please create a simulator driver or use e.g. a S7TCP driver and set it to simulation static.

everything else seems fine, except for the VBA code.

```Public Function AdjustHardwareValue_Default(obVar As Variable, vValue As Variant) As Double
Dim w As Long
w = vValue
AdjustHardwareValue_Default = ((w \ 25) * 25)
End Function```
Last edited by markclemens : 27th April 2009 at 11:42 Reason: division with "\" instead of "/"

5. ## Re: MATHDR32 mathematics drive is too weak?

correction to my previous post: the non-linear value adjustment DOES work with the internal driver

Also, note the changed "\" instead of "/" for the division in VBA

6. User
Join Date
23.04.2009
Posts
56

## Re: MATHDR32 mathematics drive is too weak?

Thank you a lot, MarkClemens. I have succeeded with your instructions. I really appreciate it.

Just a thing, I have succeeded with a S7 TCP-IP driver (Simulation static). But when I try the same thing with a Driver for Simulator Variable ("Hardware" in grey), it doesn't work.

However, my problem have solved by using a S7 TCP-IP driver, that's wonderful. I thank you again!

7. User
Join Date
23.04.2009
Posts
56

## Re: MATHDR32 mathematics drive is too weak?

Yeah, really, it works also with the internal driver. That's great! thanks!
I still can not run it with simulator driver, but it doesn't matter at all.

Originally Posted by MarkClemens
correction to my previous post: the non-linear value adjustment DOES work with the internal driver

Also, note the changed "\" instead of "/" for the division in VBA

8. User
Join Date
23.04.2009
Posts
56

## Re: MATHDR32 mathematics drive is too weak?

Hi MarkClemens, sorry to annoy you again, but I have a new question.

Now I want to try a new hysteresis function with my IEC 61850 driver, just as a typical hysteresis function (reload just when the increase/decrease is bigger than 25). But after knowing the reply of your fellow, I find it a little difficult.

So, I want to ask you, can I use the same VBA Macro to realize this function? Such as something like:

Public Function AdjustHardwareValue_Default(obVar As Variable, vValue As Variant) As Double
Dim wNew As Long
Dim wOld As Long
wNew = vValue.OldValue (just want to say what I want...)
wOld = vValue.NewValue

if wNew - wOld > 25 then
else
end if

End Function

9. ## Re: MATHDR32 mathematics drive is too weak?

The iec850 driver does not support hysteresis, so this macro would be never called. You have to allocate this iec850 variable to internal one. And then you don't need non-linear adjustment in VBA, simple set values for negative and positive hysteresis properties.

#### Posting Rules

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•