GS Works2 - How to perform Indirect Addressing of "M Bits"

Yes it's simple there are two ways of doing it, mainly it will depend on whether you are using purely ladder or FBD/Ladder.
In Ladder (usually opens up the GXWorks type IDE) then any variable can be indirectly addressed for example:
Lets say you want to point at M100 then you can do one of two things.
Move 0 to Z0 (Move 0 to one of the index registers "Z" 0-7 I think) this sets the indirect pointer.
Then when using M100 you type in M100Z0 this then knows to point at an offset of zero thus M100, Alternately you could set Z0 to 100 then indirectly point to M100 by M0Z0 it's just the offset i.e. M0 plus the offset 100 in Z0 = M100.
But if you use GXW in a Structured project with FBD/LAD then you can do the same but not by Sybolic representation. for example you cannot have a tag "My_Tag" as a global label then use that indirectly like My_Tag[Z0]
What you have to do is make an array of bits for example My_Tag[array 0..100] M0 this then creates an array of 101 M bits starting at M0 to M100
Then you do the following
AND My_Tag[Z0] so it can indirectly address as it's in an array.
see attached pics. if you increment the Z register then this will obviously point to another bit so to re-cap using the index registers you can point to any bit/word etc. by using the above if you need more than one pointer (index) then just use a second index register i.e. Z1, you can also use a D type register as an index register in FBD i.e. in the global or local variables you configure a pointer like My_Pointer = Integer or if a global then perhaps My_Pointer = Integer, D0
My_Array[0..100] of integer
Then the code becomes
TRUE, MOV 100, My_Pointer
AND My_Array[My_Pointer] OUT Y0
As Mitsubishi actually uses reletive addresses when it compiles you must ensure that you do not exceed the boundaries of the memory areas, also makes sense to ensure any array you set is at least as big as the amount you tend to indirectly address for example, you create an array of words say D0 to D100 If your pointer is set to 120 then it will point to D120 or what ever actual D it is so you could overwrite other data. It is generally better to have an array slightly larger than the pointer is likely to reach.

pointer as a word.png FBD Indirect.png Indirect_Ladder.png
 
Last edited:
Thank you, you are right, i also thought it would work like "M100Z0", however GX works2 does not accept this command, i just came to know today that Bits can be addressed in sets of four like "k1M100Z0" is accepted in Gx Works, and it will address 4 bits starting from M100, similarly "K2M100Z0" will address 8 bits starting from M100.

Like (Mov K1 K1M100Z0)
 
Yes that's right, perhaps the following will explain few things. Unlike RW/AB etc. Mitsubishi to be compliant with the IEC structure designed their systems so tht there is still compatability with existing ones, hence the inclusion of either GXDeveloper session within GXWorks, the abillity to program in ladder/FBD ladder/ & ST. & of course transition.
This was done by actually compiling the ST/FBD into the naitive code of the ladder, In FDB/Ladder, you have the IEC requirement of local & global variables, although these are symbol based i.e. "My_Var" (description if you like) these can be local (I.e. Only can be relied on within the current block or considered destructive), global these do not have a physical address and global with a physical address. At compile time there is an area of reserved bits/words used by the compiler so for example "My_Tag" as a local or global is allocated a physical address in the reserved area, the global ones that you have assigned a physical address to for example M23. There is a tradeoff by their decision to make systems compatible it means in a structured FBD/Ladder program you either need to maintain your copy on disk as you cannot upload from the PLC & it be able to re-constitute it, it will come out as the old ladder but difficult to understand as there will be lots of bits/words in the reserved area & lots of jumps i.e. subroutines, you can download what they call the symbolic file this contains the information to re-build the FBD/Ladder. It is an optin when you download to the PLC, it does take time & there must be enough memory left to contain this file. Most people I know will not bother, I personaly do it on occasions & when I finish the final program just incase I get a corrupt file.
In FBD some instructions you have to use the physical address like M100Z0
rather than the Symbolic text but you can still comment it there are others like the @ symbol there is a way to find the actual physical address of a variable for example Mov @D100, D200 This gets the actual physical address i.e. 2,345,671 so instead of referencing it as D100 you can for example reference or add a number as an offset & use that, it is the same as using the Z pointers but although not used much it is probably for backward compatability. so in FBD sometimes you may need to use the real address instead of the Symbolic one.
Again if you wish to use symbolic & Indirect addressing create an array for example My_Bit_Array [0..100] of Bit = M0, this then creates an array of 100 bits from M0 to M99. you refference this like My_Bit)Array[0] for the first bit 1, for the next & so on, there is no need to use the "Z" you cn create a variable say "My_Pointer" as integer then use that within the brackets.
When it compiles it will actually move the value into the Z register & do the logic as you would in Ladder.
Hope this explains it a bit better.
 

Similar Topics

I have a FX3U clone that I am failing to get a simple Structured Text example working on and would really appreciate some help. I created a...
Replies
30
Views
982
I'm starting learning ladder programming. I bought the FX3U kit + coolmay HMI from aliexpress. I'm doing basic testing and uploading codes. I...
Replies
57
Views
3,926
Hello to all, is my first post on the forum, I searched everywhere, but I could not find an answer to this problem; I am quite experienced in...
Replies
13
Views
979
hello, I'm trying to set up communications between two Mitsubishi L series PLCs using the built in Ethernet port. All of the information I can...
Replies
6
Views
1,881
Hello all. Am new with Mitsubishi plc programming,I need two upload program from FX3S-20MT CPU,so I ask about the the cable used to interface...
Replies
8
Views
2,177
Back
Top Bottom