16 bit addition in 95U CPU

V

Thread Starter

Vagelis

Hello everybody!!

I am looking for an integrated function block in STL which achieves a 16bit addition. The result may be 32 bit number! I am 95U cpu user.

Any help will be appreciated!!!!

Best regards,
Vagelis Katsos
 
M

Michael Griffin

The S5-95U does not have an integrated block for this. There are integrated blocks for BCD conversion (FB240, FB241), multiplication and division (FB242, FB243), and analogue I/O and scaling (FB250, FB251). Siemens does (or did) sell a math library which had various function blocks. This may possibly have included 32 bit addition.

However, whether this would be useful depends upon what you wanted to do with this 32 bit number once you created it. The built in instructions only recognise 16 bit signed numbers. This means that exceeding 32767 results in a negative number when examined using 16 bit instructions. You may also therefore need various additional function blocks to evaluate the resulting 32 bit number.

If you can tell us what you are trying to accomplish, perhaps we can suggest a solution that avoids the need for 32 bit math. For example, if all you are trying to do is count up a large number, then sometimes cascading counters may be the better solution.

--

************************
Michael Griffin
London, Ont. Canada
************************
 
Thank you a lot for your interest!

I would like to achieve a Low pass filter for a temperature sensor, which based on "rolling average". So, I want to add some samples (1000 for example) in memory (DW, FW, etc.) and after to devide this summary by 1000 again. The analog scaling for the sensor is 2000-10000 (the limits in the FB250) that corresponds to a signal 4-20mA from sensor (0-200C) and with a resistor 500Ohm the cpu reads a voltage 2-10V.

As you Know the final result of addition will be a 32bit number. Of course, I know the technical specifications of the cpu 95U.

Any sugestion welcome!!!

Thanks a lot again. Best best regards!

Vagelis Katsos
 
M

Michael Griffin

You will have more difficulty with the division than the addition. FB243 (the division FB) only works on 16 bit numbers.

I believe you have stated that the values 2000-10000 correspond to 0-200C? I am not sure why your scaling has been done like this. If you convert to engineering units (which is the purpose of FB250), then the values would be
in the range of 0-200 (one degree resolution), or perhaps 0-2000 (one tenth degree resolution). This would give you smaller numbers to work with. I don't see any point in collecting very precise numbers if you are going to average them.

Secondly, if you are simply trying to reduce random jitter to achieve a more stable temperature value, then averaging 1000 readings would not normally give you significantly better results than averaging 10 or 20 readings. A smaller number of smaller values would mean you will stay within the range of a 16 bit number, thereby avoiding your range problem.

If you still need 32 math, I would suggest you contact Siemens to see if their S5 math library (this was a separately purchased item) supports both 32 bit addition, and 32 bit division (this latter one is the more difficult part).

Finally, I would suggest that you have another look at the signal conditioning you are using on the temperature sensor. These often have selectable filters. A slower filter may be able to achieve what you desire without doing any math at all.

--

************************
Michael Griffin
London, Ont. Canada
************************
 
Top