Jump to content

Converting Eint Values To Reals Using Scripted Text In A Plc


marke

Recommended Posts

EInt2Float Subroutine in Scripted Text on a Horner Series PLC.

 

 

(******************************************************************)
(* EInt2Float *)
(* Convert Emotron EInt values to standard floating point. *)
(******************************************************************)

If And_Mask(EIntIn,16#8000) = 0 then
EReal := ANY_TO_REAL(And_Mask(EIntIn,16#7FFF));
Return;
End_If;

(* Get Mantissa and convert to real *)
TempWord := And_Mask(EIntIn,16#3FF);
TempInt := ANY_TO_INT(TempWord);
If And_Mask(EintIn,16#0400) = 16#0400 then TempInt := TempInt-16#0400; End_If;
EReal1 := ANY_TO_REAL(TempInt);

(* Get Exponent and convert to real *)
TempWord := And_Mask(EIntIn,16#3800);
TempInt := (ANY_TO_INT(TempWord))/2048;
If And_Mask(EIntIn,16#4000)=16#4000 then TempInt := TempInt - 8;
End_If;
TempReal := ANY_TO_REAL(TempInt);

(* Combine Mantisa and Exponent and output. *)
EReal := EReal1 * EXPT(10, TempReal );

 

 

Typical Subroutine Call.
DispCurrent := eint2floatST(FDU2Curr);

Link to comment
Share on other sites

  • 7 years later...

Here is the Structured Text Subroutine code that can be imported to CScape Version 9.6 or later.

Right Click on Logic Modules and select Import Modules and chose eint2floadtST.XK5

image.png

eint2floatST.XK5

Link to comment
Share on other sites

If you really want to do it the hardway, you can use ladder code (ugly!!)

Right Click on Logic Modules and select Import Modules and chose eint2floadtLD.XK5

image.png

eint2floatLD.XK5

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...