Math

Waldg

Member
Join Date
Mar 2012
Location
Nh
Posts
44
Using directsoft on a dl 06 how do I compare a bcd number with a constant in a >= contact?
Thanks
 
The constant can be on the right side but not on the left. You may have to work it out. The V register which contains your variable should be on the left and the constant will be on the right.

Example - is the contents of V2003 (which contains a BCD value) greater than or equal to a BCD value of 23?

V2003 >= K23 ---- the rest of the rung ---
 
Would k23 have to be equal or more then the decimal equivalent of v2003 to be true? Or am I missing something
Thanks
 
I had the same problem understanding the inline compares relative to BCD and binary when I first started using the DL line in the mid 90's.

As long as the two sides are both binary or both BCD the compare will be correct. You know what type you have in the 'V' register on the left hand side but how about the 'K' value?

Here's the fun part ... it can be either. Let's take 'K23'.

The bit representation of the lowest 8 bits is 0010 0011 (space added for clarity). What is that? It could be two things. If you INTERPRET it in the normal bit weighting it's 35 decimal. But if you INTERPRET it as BCD it is 23 decimal. It can be EITHER VALUE. It totally depends on the instruction you use it in. If you were to add it to another value using ADDB then the CPU would interpret it as 35 decimal. If you were to LD it then add it to another value using ADD then it is interpreted by the CPU as 23 decimal (BCD).

So the comparison that I mentioned in the previous post works because both sides are being interpreted in the same way. Even though the comparison technically is to the binary values the resultant decision works either way. It's only when you mix types (that is numbers which you are interpreting in different ways - binary/BCD) that you get in trouble.

The system does not have the type separation of a system like Allen Bradley. I discuss this on a page at my site.

Good luck. Once you see it there won't be a problem.
 
Note: some find the flexibility of memory usage of the DL line frustrating. I find it liberating. But it places the responsibility for using it properly on YOU - THE PROGRAMMER. The same may be said of the accumulator based math. For some CPUs the IBoxes add some control but at the expense of somewhat hiding the operations, much larger instructions and execution time.
 
I still have a problem with calculations. i have the following instructions
PD C5 (one Scan)
Str C5
LDD V1406
SUBD V1700
OUTD V1421
LDD V1406
OUTD V1700

If the value of V1406 is 776 when C5 comes on the result is

V1406 = 776, V1700 = 776, and V1421 = 776

When i first added the above rungs the calculation was correct, but after a few hours it does not seem to subtract V1700 from the new value in V1406

What am I doing wrong?
 
Data view is decimal dword, c5 is happening the 3 vmemory keeps increasing each time.
I am beginning to think I have a bad Plc. I have had to clear all and restart it before. I could not get the Pid to work properly until I cleared everything twice before it worked.
 
V1406 is binary I think. Each time a counter reaches a conditional value it resets the timer and increases v1406 via incb.
 
Are any of these three, V1406, V1700, V1421 used as double words anywhere else in the program. I wowuld imagine at least V1406 would be.

Are any of the second words of these (V1407, V1701, V1421) referenced anywhere?

If the value of V1406 is 776 when C5 comes on the result is

V1406 = 776, V1700 = 776, and V1421 = 776

Assuming the initial value of V1406/7 as shown and assuming 0 in V1700 before the first actuation of C5 then, after the first actuation, your results would be correct.

What gererates the PD of C5? Is it the same occurance which does an INCB of V1406? Remember that an INCB will only affect the target 'V' register as a single word. If you want to increment V1406/7 as a double word you'll have to use:

LDD V1406
ADDB K1
OUTD V1406
 
Data view is decimal dword, c5 is happening the 3 vmemory keeps increasing each time.
I am beginning to think I have a bad Plc. I have had to clear all and restart it before. I could not get the Pid to work properly until I cleared everything twice before it worked.

If you are viewing these registers as DECIMAL dword and they appear correctly (assuming they are greater than 9), then you are using the wrong math mnemonic. SUBD is for BCD math. Once it encounters a register with values that are not BCD (IE Decimal/Hex) it will give an incorrect result.

PD C5 (one Scan)
Str C5
LDD V1406
SUBD V1700
OUTD V1421
LDD V1406
OUTD V1700

What am I doing wrong?

You should be using SUBBD for the math instruction for the DECIMAL data type.
 
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.
 
With the method of storage of values in the V memory the program or CPU doesn't "know" if you intend to use the area as binary, BCD or even a real. It only works based on the instructions you pick. Use the nicknames carefully. Indicate the type in them if you can. Be sure to properly label the second word of any two word variables.
 

Similar Topics

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,296
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,716
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,031
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,668
I have a customer who has a centrifuge application. The plant engineer did all the calculations on the centrifuge to arrive at a WK^2 of 6458...
Replies
14
Views
3,505
Back
Top Bottom