MamoJaLatam

Accessing specific bits in a word.

6 posts in this topic

Hello,

I'm new to PLCs, now I learned about the "." operator, but it seems limited to specified registers only. So, for example, this works:

D100.1 := 1;

Question 1 - Is it possible to somehow access a specific bit of a label?  Something like:

myLabel.1 := 1;

Question 2 - Same, but this time with Z registers:

Z1 := 1;
myLabel.Z1 := 1;

Both examples throw a parser error. For now I'm sticking to assigning label value to a register, THEN changing the bit, THEN assigning the changed register back to my label, but it just looks ugly. Is there a better way to solve this? I'm using FX3G series.

Share this post


Link to post
Share on other sites

No.
If you want to check a specified bit of the word, you should move the word to the bit memory.
 

LD TRUE
MOV D200 K4M200
LD M204
OUT Y0

The index registers can not be used for this purpose too. It can be done by a complex way:
 

LD TRUE
MOV D200 K4M200
MOV K1M200Z K1M200
LD  M200
OUT Y0

Read the programming manual carefully. There is written all.

Share this post


Link to post
Share on other sites

If you have access to predefined Mitsubishi Functions- you can also use the conversion to Bit Array- this is what I normally use, then specify your Tag[x] where x is the position of the bit you wish to analyse. 

Here is an example for a 16-Bit Integer

 

 

 

BitArray.bmp

Share this post


Link to post
Share on other sites

collinsd70, 

INT_TO_BITARR 16 = MOV Dxxxx K4Myyyyy. It's just an IEC interpretation of MELSEC command instruction.

Share this post


Link to post
Share on other sites

You are correct that "." are limited to specific addressing only. The way "around" it is to define variables in global lists and then use the variable name (you can assign a labelname the address D100.1 for example).

Share this post


Link to post
Share on other sites

I think you want to use an Array.

Like than you can acces is like the following.

Arrayname[Z0] But you do  not have to use a direct indes register you can alos define a word Arrayname[index]

 

 

Share this post


Link to post
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