Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Var declaration AT %MW...voiding memory overlapping

hki75
2015-10-22
2023-08-17
  • hki75 - 2015-10-22

    I need to declare some variable mapped to %M address, something like:

    Timer1 AT %MW0 : TON;

    The question is: how to know the right offset for each variable to void memory overlapping?
    ex:
    Timer1 AT %MW0 : TON;
    Timer2 AT %MW ?? : TON;

     
  • Jonascox - 2015-10-27

    hki75, unlike Siemens, you don't need to offset your variables of like kind.

    Timer1 AT %MW0 : TON;
    Timer2 AT %MW1 : TON;
    Word3 AT %MW2 : word;

    However, if you use Bytes as a starting point, you can overlap memory. Like this:

    Word1 AT %MB0 : Word;
    Word2 AT %MB2 : Word;
    Word3 AT %MB3 : word; ( This variable will be overwritten by the variable starting at %MB2 )

     
  • hki75 - 2015-10-27

    Hi Jonascox,
    thanks for reply.
    I try to insert your suggestion into Codesys but it doesn't work..for the following reasons:

    TON (timer cannot to be defined AT odd address %W:
    ex:
    Timer1 AT %MW1 : TON; --> return error compiler 3729

    Defining
    Timer1 AT %MW0 : TON;
    Timer2 AT %MW2 : TON;
    --> compiler return:

    the only way I found to void memory overlapping during compiling is this:
    Timer1 AT %MD0:TON;
    Timer2 AT %MD6:TON;

    (it seems each timer needs 6 dword memory allocation)
    But my question was: how to know it in advance without try with different data type (MB or MW or MD...) and compiling every time until I get

    IMG: Bild

    IMG: Bild

     
  • Jonascox - 2015-10-27

    hki75 hat geschrieben:
    Hi Jonascox,
    thanks for reply.
    I try to insert your suggestion into Codesys but it doesn't work..for the following reasons:
    TON (timer cannot to be defined AT odd address %W:
    ex:
    Timer1 AT %MW1 : TON; --> return error compiler 3729
    Defining
    Timer1 AT %MW0 : TON;
    Timer2 AT %MW2 : TON;
    --> compiler return:
    the only way I found to void memory overlapping during compiling is this:
    Timer1 AT :TON;
    Timer2 AT :TON;
    (it seems each timer needs 6 dword memory allocation)
    But my question was: how to know it in advance without try with different data type (MB or MW or MD...) and compiling every time until I get

    Is there a reason you need the TON's defined at an absolute memory location?

    It is much simpler to define them without an absolute address.

    Example:

    Timer3:TON;

    The timer bits can be used in your code directly. They are predefined and shouldn't be added to any variable list.
    Example:

    Timer3.Q (Done Bit)
    Timer3.ET (
    Elapsed Time)
    Timer3.PT (
    Preset Time*)
    Etc.

    IMG: Bild

    IMG: Bild

     
  • hki75 - 2015-10-28

    I know it's easier to define FB without physical memory addressing, but I need it..

     
  • Jonascox - 2015-10-28

    I found that each timer uses 4 DINT's.

    So I would put the timer names in a spreadsheet and add the %md** in the column next to them. Fill out the first 2 or 3 names and addresses then drag the cells down to have the spreadsheet auto-fill the rest of the memory names. In this way you can determine where each timer memory starting point will fall.

     

Log in to post a comment.