allocation of variables for different modules

bmattlet
2011-08-23
2011-09-03
  • bmattlet - 2011-08-23

    Hi,

    I have programmed a up/down counter (UDC) module on CoDeSys.

    My problem is : I would like to use the same function_block for all my UDC modules but the addresses of the variables (such as "AT %QX0.0") change from one module to another. All the modules are UDC-type but %QX0.0 become %QX2.0 for module 2 and so on...

    Is it possible to automatically allocate the addresse of the variables so I can use the same function_block for the different modules ?

    Thank you for any response.

     
  • Rolf-Geisler - 2011-08-23

    Hi,
    just do not use absolute addresses inside the UDC function block

    FUNCTION_BLOCK UDC
    VAR_OUTPUT
    Β  qxSomeOutput : BOOL;Β  (* that's all you need *)
    END_VAR
    

    To get the outputs of a module instance, use the instance identifier :

    VAR
    Β  AnUDCInstance : UDC;
    Β  AnUDCOutputΒ  Β : BOOL;
    END_VAR
    (* --- *)
    AnUDCOutput := AnUDCInstance.qxSomeOutput;
    

    With CoDeSys, you need absolute addresses fΓΌr physical inputs / outputs only. All other data the compiler is able to allocate dynamically.

    Have success
    Rolf

     
  • bmattlet - 2011-08-24

    .

     
  • bmattlet - 2011-08-24

    Ok thank you but how do I link "AnUDCInstance.qxSomeOutput" to a physical address after that ?

    I mean I know that I could write "%QX1.0:=AnUDCInstance.qxSomeOutput" so the physical Ouput take the value of my variable but how can I do this automatically or with some kind of function ?

    Because to every I/O of the function block it exists the I/O of the Wago module but with a different address for every module...
    Hope I'm clear enough...

    Benoit.

     
  • Rolf-Geisler - 2011-08-24

    Hi,

    VAR
    Β  AnUDCInstance : UDC;
    Β  AnUDCOutput AT %QX0.0 : BOOL;Β  (* This assigns a physical address *)
    END_VAR
    (* --- *)
    AnUDCOutput := AnUDCInstance.qxSomeOutput;Β  (* This brings the UDC output to the absolutely addressed target *)
    

    Rolf

     
  • bmattlet - 2011-08-24

    ok, nice!

    May I write directly :

    AnUDCInstance.qxSomeOutput AT QX0.0
    

    Or do I have to assign a physical address to a variable and then put the data of my function block in the variable like the way you did ?

    Thankt you!

     
  • Rolf-Geisler - 2011-09-03

    Hello Benoit,
    sorry for the late reply. Had been off for a few days.
    ```

    AnUDCInstance.qxSomeOutput AT QX0.0

    ``` probably willl not work. I can't imagine, how the compiler could assign an absolute address to just a little part of a function block.
    The safe way is to have just variables with certain addresses, to which you assign the output var of the FB instance, as I suggested it in one of my posts.
    Rolf

     

Log in to post a comment.