Floating Point

Help
Claudio_72
2007-12-10
2013-03-18
  • Claudio_72
    Claudio_72
    2007-12-10

    Hi,
    I would like to add floating point support in classicladder.
    It seems that it isn't supported at the moment,is it rigth?

    Is it hard to implement?

    Could you suggest a simple way to add it?

    Thank you.

    Claudio Montemaggiore

     
    • Hello Claudio !,

      well not too much I think...

      The only part where floats could be used, is in the arithmetic evaluator... contacts and coils will always be boolean! ;-)

      -> In classicladder.h, we could could add this for the new vars:
      /* Type of vars */
      ...
      #define VAR_ARE_FLOAT 899    /* after it, all vars are floats */
      /* floats */
      #define VAR_MEM_FLOAT 900

      -> in arrays.x, a float array will have to be allocated and freed...
      (like the VarWordArray a VarFloatArray must be added)

      -> in vars.x
      *Add init of VarFloatArray in InitVars()
      *Add new functions for floats : float ReadVarFloat(int TypeVar,int Offset) & void WriteVar(int TypeVar,int NumVar,float Value)

      -> in arithm_eval.c
      Here will be the big changes to do...
      In my sense, it could be like that:
      Every functions actually returning arithmtype, should be doubled like that (example):
      arithmtype AddSub(void)
      float AddSubF(void)
      Adding a global var flag to indicate that the evaluation is done in float (=false per default)
      When parsing, if a float var is discovered, this flag is set to true, and then it is the float version of the calc functions that is used....
      I think it could work like that, and not too much difficult...

      Perhaps if float used, special init of the thread to be done (sure including RTLinux !)

      I'm interested by any patchs if you do something on it !

      Hope I have been quite clear... Ask again if not, and I will try to respond fastly than this time ! ;-)
      Bye, Bye.

      Marc.

       
    • I just see an annoying thing.... in arithm_eval they are recursive functions returning int (arithmtype)... when in Variable(void) we will find a float var, we won't be able to return its float value, in each functions returns (stack functions called)...

      Perhaps the better, could be to add an information for each expressions if it is the float evaluation expression version that must be used or not. Or else before starting evaluation, parsing it all to see if presence or not of a float variable in the expression.

      Not so simple !? ;-)

       
      • Claudio_72
        Claudio_72
        2008-04-22

        Hi Marc,

        I'm adding some changes in ladder as regard the grapich interface
        (watch window in particular).

        No yet about float implementation

        I hope to send it to you soon so you can give me  your opinion and suggestions

        I have a question for you:
        I've seen the New Timers are compliant with standard IEC 61131-3.
        How much is classicladder  compliant with this standard;
        What else need to have a fully compliance with this standard?

        Thank you

        Bye

        Claudio Montemaggiore

         
        • Hello Claudio,

          Yes if you can send the modifications it's always interesting to see what you've done, and perhaps someones could be merged to the current version.

          In the last release, you will see that I've added the possibility for indexed variables to all rung elements !

          IEC61131-3 standard is a lot of big documents to read... I've looked a little at a time, bug... arggghh not really funny!
          And I don't know what in them must really be used in all of that...
          The first thing would be to respect the syntax of the variables names/types, and many others things for sure !
          For example, in the variables %Bxxxx, B means BYTE in IEC.... should be %Mxxxx, but not sure!
          The '%' character (direct variable, not symbol one) I recently add is for IEC !

          If you find some informations on IEC, and the things that should be done, I'm interested !

          Bye, bye !