[?] Combine two Words

SIMATIC S7-200/300/400, Step7, PCS7, CFC, SFC, PDM, PLCSIM,
SCL, Graph, SPS-VISU S5/S7, IBHsoftec, LOGO ...
Post Reply
sudanee
Posts: 61
Joined: Thu Mar 19, 2009 11:00 am
Location: Sudan

[?] Combine two Words

Post by sudanee » Sun Apr 20, 2014 10:23 am

Hi
I am extracting data from some Power meter
See this http://goo.gl/4Qno9N
I get the data from the tow register
1st word = 16#BD07
2nd word = 16#44
my question how to combine the tow words as described in the page above
to get 16#BD0744

I am using PCS7 7.0
Regards

kaa1979
Posts: 42
Joined: Sat Mar 27, 2010 8:14 am

Re: [?] Combine two Words

Post by kaa1979 » Tue Apr 22, 2014 5:38 am

I get the data from the tow register
1st word = 16#BD07
2nd word = 16#44
my question how to combine the tow words as described in the page above
to get 16#BD0744
It's wrong
if 1st word = 16#BD07, 2nd word = 16#44, then you should get 16#BD070044 (-1123614652 dec)
or you need to swap the words - then you should get 16#0044BD07 (4504839 dec)

create FC with:
// input variables: WORD4000: WORD; WORD4001: WORD; WORD4108: WORD;
// output variables: RESULT: REAL;
// temporary variables: tempPOWER: REAL;

STL:
L WORD4108
ITD
DTR
L 10.0
LN
*R
EXP
T tempPOWER // tempPOWER=10^(WORD4108)
L WORD4000 // if swap - change to L WORD4001
SLD 16
L WORD4001 // if swap - change to L WORD4000
OD
DTR
L tempPOWER
*R
T RESULT// RESULT=(WORD4000<<16 || WORD4001)*10^(WORD4108)
SCL:
RESULT=DWORD_TO_REAL( SHL(IN:=WORD_TO_DWORD(WORD4000),N:=16) OR WORD_TO_DWORD(WORD4001) ) * 10.0**(INT_TO_REAL(WORD_TO_INT(WORD4108)));
// if swap - RESULT=DWORD_TO_REAL( SHL(IN:=WORD_TO_DWORD(WORD4001),N:=16) OR WORD_TO_DWORD(WORD4000) ) * 10.0**(INT_TO_REAL(WORD_TO_INT(WORD4108)));

dsekulic
Posts: 186
Joined: Sun Feb 12, 2006 5:47 pm
Location: Europe

Re: [?] Combine two Words

Post by dsekulic » Wed Apr 23, 2014 9:39 pm

Hi,
You should do following

stl:

L W#16#BD07
SLD 4 // shift left double word
L B#16#44
OD // bitwise OR double word
T MD 0 // result

regards

dsekulic
Posts: 186
Joined: Sun Feb 12, 2006 5:47 pm
Location: Europe

Re: [?] Combine two Words

Post by dsekulic » Thu Apr 24, 2014 8:45 am

Hi,
One correction
Instead of SLD 4 You should put SLD 8 because You need to insert one byte.
regards

kaa1979
Posts: 42
Joined: Sat Mar 27, 2010 8:14 am

Re: [?] Combine two Words

Post by kaa1979 » Sat Apr 26, 2014 2:16 am

For dsekulic:
From http://goo.gl/4Qno9N:
Now to find out the Real Energy consumption measured value in PM210, follow the below steps :
Read the first word (4000) in hexadecimal format. Example 0000;
Read second word (4001) in hexadecimal format. Example 1ADF;
Combine the registers value as 0001ADF and convert them into decimal format. 00006879
Read the scale factor register value 4108. Example -2. This is a power of 10 and this means 0.01.
Multiply 00006870x0.01 and the result is 68.7 kWh the Real Energy Consumption.
where you found the use of bytes rather than words?

dsekulic
Posts: 186
Joined: Sun Feb 12, 2006 5:47 pm
Location: Europe

Re: [?] Combine two Words

Post by dsekulic » Sun Apr 27, 2014 8:13 am

Hi,
If You read question he need to get result 16#BD0744 not 16#BD070044. Therefore I combine second word as byte. If You put in STL

L 16#44
You will get
L B#16#44

That is just answer on question. If You wish to combine 16#BD07 and 16#0044 then You should shift left 16 bits

L W#16#BD07
SLD 16 // shift left double word
L B#16#44
OD // bitwise OR double word
T MD 0 // result

regards

Post Reply