S7 STL Dword to Byte

rikcando

Member
Join Date
Apr 2012
Location
Ontario
Posts
128
I have been beating myself up for the last couple of hours trying to figure this out. It seems so simple but I really am missing something.

I have a function that I am sending a MD DWord and I need to return just am MB Byte. The value will never be more than +/-500 in the DWord. I have a return bit for negative and a return bit for overflow.

In: DWord value +/- 500
Out: Byte value 0-255, Negative bit, Overflow bit.

Attached is a picture of the latst attempt. I have tried ABS, MOD, AD, (SQR:SQRT), all with the same result.

Assuming I input -38 I would expect 38 in the byte, the negative bit on, the overflow off. I get the negative bit but the byte holds 218.

Please help me to undestand this. Thanks.

negs.jpg
 
I have it, and it was something really simple.
If it is negative just multiply by -1 before the transfer. Jump past it if not.

Code:
  L 0
  L     #XOffset
      ==I                               //check if 0, add 1
      JCN   _00X
      +     1
_00X: NOP   0
      <I    
      JC    _Xfr
      L     -1
      *I    
_Xfr: T     #bXoffset
 
At that point yes.
I cannot handle a 0 on the recieving end of the communications. A 1 is minute and will not effect results. A zero will be assumed as no communications. But nice catch.
 
For reference, here is how you can use the abs instruction (which only works on floating point numbers)

xxxx.JPG
 
Thank you.

I just took the time to look up the DTR and RND instructions in the help files. I am glad it had a description of the IEEE-FP format because I was really wondering how -100 tuns into -1027080192.

Could this be why the SQR then SQRT did not work as expected. I was not using the correct numerical format?
 

Similar Topics

i am new to simatic manager and i am trying to figure what this part do in the code : A I 5.6 = DB50.DBX 4.6...
Replies
3
Views
133
Hello everyone, can anyone help me with covert the STL code to ladder. Iam using plc s71200. A %DB1.DBX33.7 // angel of vaccum...
Replies
2
Views
208
Hello nice to meet you, im new in here, I'm currently trying to convert code written in STL for a S7-400 to SCL for an S7-1500, because when i run...
Replies
5
Views
317
First off thank you in advance. Second I am very new to STL. I am trying to build a counter that has one count up and 23 count down options. Am...
Replies
6
Views
376
Hi Siemens Experts, I am hoping someone can shed some light on my issue. I have uploaded the code from a S7-300 (317-2PN/DP) using Step 7...
Replies
9
Views
674
Back
Top Bottom