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
[?] Combine two Words
-
- Posts: 43
- Joined: Sat Mar 27, 2010 8:14 am
Re: [?] Combine two Words
It's wrongI 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
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:
SCL: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)
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)));
-
- Posts: 186
- Joined: Sun Feb 12, 2006 5:47 pm
- Location: Europe
Re: [?] Combine two Words
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
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
-
- Posts: 186
- Joined: Sun Feb 12, 2006 5:47 pm
- Location: Europe
Re: [?] Combine two Words
Hi,
One correction
Instead of SLD 4 You should put SLD 8 because You need to insert one byte.
regards
One correction
Instead of SLD 4 You should put SLD 8 because You need to insert one byte.
regards
-
- Posts: 43
- Joined: Sat Mar 27, 2010 8:14 am
Re: [?] Combine two Words
For dsekulic:
From http://goo.gl/4Qno9N:
From http://goo.gl/4Qno9N:
where you found the use of bytes rather than words?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.
-
- Posts: 186
- Joined: Sun Feb 12, 2006 5:47 pm
- Location: Europe
Re: [?] Combine two Words
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
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