Urgent S7-300 Move digits from INT

BNA

Member
Join Date
Sep 2003
Location
Give
Posts
117
Hi

This must be simple but after several very long days programming I am out of ideas, so please HELP.

In DB1.DBW0 the value 1134 is located, I would like to move 11 to DB1.DBW2 and 34 to DB1.DBW4.

Is it possible, and if how can i do it ???

Regards Brian
 
Do you want to move int 11 and int 34? Or BCD 11 and BCD34?

If you want the BCD equivalents, then just to an INT to BCD conversion, and transfer the individual bytes to the words.

If you want use the int data type, then you would just use simple math to mask out the thousands, hundreds, ten and ones place. In your case, if you did something like 1134/100, you would have a result of 11 plus remainder 34. These values could be passed to your data words.
 
Divide it by 100, take the quotient to DBW2 and the remainder to DBW4
(after the division the remainder lives in ACCU1 HI, I think the SRD 16 will move it to ACCU2 LO for the Transfer). look in the siemens help at /I

in STL:

L db1.dbw0
L 100
/I
T db1.dbw2
SRD 16
T db1.dbw4
 
Thank you

As I though, very simple.
I did not see that one comming, thanks again.

Now just a couple of hours of work and then of to bed

Regards
Brian
 
Guys, isnt there a problem with the suggested solution ?
I mean that with "1234" it will work, but with "4567" there will be a rounding up to "46" when you divide 4567/100.

What if you first converted to BCD, then moved each byte that represents one decimal, and finally converted back to INT ?

edit:
If you have max 4 decimals, then you can use ITB to convert to 4 BCD decimals. Possibly you should test for the source being within 0-9999.
If you need more than 9999 then with DTB you can convert to 8 BCD decimals.
 
Last edited:
The following code works for positive integers in the range 0 to 32767:

Code:
	  L	 MW   998
	  L	 100
	  MOD   
	  T	 #iTensAndUnits
	  TAK   
	  L	 100
	  /I	
	  T	 #iHundredsAndThousands
 
I don't think we meant it to be a full blown solution. I just threw it out there to get him thinking. I assumed he would try all of the values, clamp a min/max, etc.

If he wanted a canned solution, I would have asked for a PO first. :)
 
S7Guy said:
I don't think we meant it to be a full blown solution. I just threw it out there to get him thinking. I assumed he would try all of the values, clamp a min/max, etc.
I understand that, but it appears that BNA went to bed with the impression that the problem was solved. And maybe we have actually given him some code with a built-in bug.

L D[AR2 said:
The following code works for positive integers in the range 0 to 32767:

Code:
	 L	 MW 998
	 L	 100
	 MOD 
	 T	 #iTensAndUnits
	 TAK 
	 L	 100
	 /I	
	 T	 #iHundredsAndThousands

MOD ? Didnt think about that one. There are many roads to Rome.
But I think it gets complicated. With the above code you have extracted the remainder part of 1234/100 (34 correct) and 4567/100 (67 correct). But the division still produces 12 (correct) and 46 (wrong).
 
Have you tried this Jesper ?

(Note just re-read Jason's post - that's the way to do it)
 
Last edited:
Ok, how about this:

L MW20 (a four digit int)
ITD
DTB
SRD 8
BTD
T DB1.DBW2

L MW20
ITD
DTB
AD DW#16#FF
BTD
T DB1.DBW4

I know it can be done in fewer steps, but I did it this way for clarity. Then again, I'm tired and just came back from a tapas bar, so maybe I got it all wrong. :)
 
L D[AR2,P#0.0].
Your post made me unsure about what I assume, so I went and tested both yours and Jasons code with PLCSIM. Jasons worked.

I stand corrected.
So now I learned something important. In S7, there is no rounding when doing integer math. I just assumed this as it is the most natural thing.
A bit shocking actually. For so long I have just taken this for granted.

edit: Interesting actually how different brands treat division of integers. I know that in AB there is rounding.

edit: S7Guy. I believe that your code works, but it is much easier with Jasons code. Sorry for having started you in that direction.

Now to nail this down for sure, I will check it on a real PLC when I get the chance.
 
Last edited:
JesperMP said:
L D[AR2,P#0.0].
Your post made me unsure about what I assume, so I went and tested both yours and Jasons code with PLCSIM. Jasons worked.

Does this mean that my code didn't work ?
 

Similar Topics

Hi all, Right now I am on Commisioning in Vietnam and I need urgent help with resetting PLC password. I have got safety PLC S7 300, CPU 315F-2...
Replies
12
Views
41,322
Good People, I am badly stuck here and seeking urgent help. I am using ET200S system having IM151-8 CPU. The programming software I've got is...
Replies
1
Views
2,357
I have modified the previous backup of PV300 & compiled & saved it. Afterwords I downloaded it into my PV300. It was showing offline. Even after...
Replies
0
Views
1,512
I am new to Panelview/Panelbuilder32. I have opened up a project in a PV300 where on different screens the function keys are tagged to bits say...
Replies
3
Views
2,631
hello all i am new to ladder programming, i am using S7 300 PLC, i am unable to figure out how to send data to the plc (control commands) through...
Replies
5
Views
17,660
Back
Top Bottom