Math

Thanks for your help. It appears subbd works. I can't imagine why a subtract would not simply just subtract the given value from any format number. What gets me though is that it worked for a few hours Until something told it it wasn't supposed to work. Talk about intelligence, or is it job security.

To boil it down to a few sentences; it's because of binary math and data typing. Each data type, BCD, Binary (or decimal or Hex depending on the method it is viewed), or Real (floating point) is stored as a different binary representation in the PLC memory.

If the PLC is not strongly data typed (the DirectLogic series of PLC's is not strongly typed., Productivity 3000, Click, Allen Bradley, Siemens, are strongly typed) then YOU the programmer HAVE to keep track of the data typing in order to tell the processor what math instructions to use for the data type of a memory location. BCD needs one style of math instruction. Decimal/Binary/Hex uses another. Floating point uses still another type of math instruction. All because each data type is stored in a different binary format inside the PLC memory.

Strongly typed PLC's do not have to do this since the PLC processor "knows" what the data type for each memory location is so the processor "knows" what math instruction to use and can pick the proper one by itself.
 
I mentioned in my first post that this subject confused me when I started using the DL line way back when. Internet forums of this type weren't really available then. But the great phone support at Automation Direct (then still PLC Direct) came through and helped me clear things up. A great group.
 

Similar Topics

I have an expression in a structured text routine of a Logix controller that looks more or less like the following: ResultInteger := Integer1 *...
Replies
13
Views
390
This application has a motor with encoder feedback that drives a linear actuator that moves in/out, and is at roughly 45 degs from horiz. As the...
Replies
19
Views
1,369
Hi all. First time programming a machine of this type. A center driven unwind feeding to a center driven rewind. No dancers or load cells, just...
Replies
37
Views
4,902
Hello, Been a while since I posted , Still sucking air been a interesting 3.5 years the dreaded health with old age scenario. Back at it and had a...
Replies
11
Views
2,059
Hello: Some time ago I wrote some basic code for a GuardLogix, in which I needed to add and subtract tags of LINT data type. When tried to use the...
Replies
13
Views
3,757
Back
Top Bottom