1

I am trying to read the values from an energy meter, and convert them to REAL (32bit float). In this case I am reading phase 1 voltage. Each value is read across two registers. So I have received to WORDS of values 17268 (MSW) and 2456 (LSW) converted them into a DWORD, and then to a REAL value after multiplying by 0.1, but I am not getting the answer I'm expecting. I should be getting 245.0375 volts. However I am getting 1.13E+08 Please see snip of structured text with live values. snip

James
  • 13
  • 2

1 Answers1

0

The problem is that DWORD_TO_REAL is trying to do a type conversion; that is, make the value of a DWORD match the format of a REAL. In your case, the contents of MSW and LSW are simply a IEEE754 value split in half and just need to be forced into the corresponding bits of a REAL variable. With TwinCAT (Beckhoff) I would do a direct memory copy:

MEMCPY(ADR(realValue)+2, ADR(MSW), 2);
MEMCPY(ADR(realValue), ADR(LSW), 2);

I would assume Schneider has a similar command.

kolyur
  • 457
  • 2
  • 13
  • For the moment, I have assigned these two words to adjacent memory locations (%MW0, %MW1) and then defined a REAL variable at %MD0. I will try the above, as in some cases I want to keep to 'symbolic' addressing, rather than 'immediate' addressing. – James Aug 25 '21 at 21:24