Page 1 of 1

[?] Combine two Words

Posted: Sun Apr 20, 2014 10:23 am
by sudanee
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

Re: [?] Combine two Words

Posted: Tue Apr 22, 2014 5:38 am
by kaa1979
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)));

Re: [?] Combine two Words

Posted: Wed Apr 23, 2014 9:39 pm
by dsekulic
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

Re: [?] Combine two Words

Posted: Thu Apr 24, 2014 8:45 am
by dsekulic
Hi,
One correction
Instead of SLD 4 You should put SLD 8 because You need to insert one byte.
regards

Re: [?] Combine two Words

Posted: Sat Apr 26, 2014 2:16 am
by kaa1979
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?

Re: [?] Combine two Words

Posted: Sun Apr 27, 2014 8:13 am
by dsekulic
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