CJP1967

Mapping Device Bits into a Word

17 posts in this topic

Good Morning

 

I have a small problem that I’m hoping someone can help me resolve.

 

I want to take one byte of Data from a data structure and make it into an Integer

 

The 8 bits of data are stored as a bit array. I can use BITARR_TO_INT with no issues so long as the data is stored as Bits (M coils for example)

 

My problem is that the Data is stored in a ZR register bits 0-7.

 

So basically I need to read ZR62000.0 – ZR62000.7 into an integer. Is this possible?

 

Thanks for looking.

Share this post


Link to post
Share on other sites

Hi CJP1967.

Firstly, welcome to the forum.

Of course this is possible, you have a few options here

1. Create an 8 bit array (ARRAY [0..7] of type BOOL) and map your individual bits to the array bit, then simply use the function as above with your ARRAY[0] and the lenth of 8.

2. Make your own FB with input parameter for the 8 bits- then inside add 1,2,4,8,16,32,64,128 if the bit is high). Output parameter will need to be of type INT which is the value you want to extract.

Im sure there are many other methods you can use; these are the 2 that 'spring' to mind.

Regards

Daniel.

Edited by collinsd70

Share this post


Link to post
Share on other sites

Hi CJP1967.

Had a spare 5 mins so have made the code and bench tested for you.....

2 Files attached- 1 is the FB running cyclically in a POU, the other is the source code in ASCII format (.asc). This was compiled in IEC Developer 7.04 but should convert into GXWorks2 without any issue.

Enjoy!

 

Regards

Daniel

TEST.bmp

8BIN_INT.asc

Edited by collinsd70

Share this post


Link to post
Share on other sites

Out of interest what are ZR registers?

I did find ZRRDB instruction which seems to do what you required if I have understood correctly.

 

Share this post


Link to post
Share on other sites

ZR Registers are retentive expandable memory in the Q series platform that are unallocated by default.

 

Regards

Daniel

Edited by collinsd70

Share this post


Link to post
Share on other sites
On ‎12‎/‎01‎/‎2019 at 2:41 PM, collinsd70 said:

Hi CJP1967.

Had a spare 5 mins so have made the code and bench tested for you.....

Thanks for taking the time to do that Collins.

The code works well :-)

 

Share this post


Link to post
Share on other sites
On ‎14‎/‎01‎/‎2019 at 4:46 PM, collinsd70 said:

ZR Registers are retentive expandable memory in the Q series platform that are unallocated by default.

One more question since we are talking about ZR registers. As I understand it they are the same as R registers. Is this correct?

Share this post


Link to post
Share on other sites
24 minutes ago, CJP1967 said:

Thanks for taking the time to do that Collins.

The code works well :-)

 

You are very welcome...take the time to understand how it works; for your own benefit :). The nice thing about that FB- is you can use it as many times in your program as you need.

From memory; R registers are 16-bit registers so like your standard D-Registers except they are stored in retentive memory areas. ZR registers are retentive but can be mapped as bits e.g ZR600.1 for example.

They are available as expandable memory on the Q-Series (im not 100% sure on L or iQR series).

 

Regards

Daniel.

Share this post


Link to post
Share on other sites
Just now, collinsd70 said:

You are very welcome...take the time to understand how it works; for your own benefit :). The nice thing about that FB- is you can use it as many times in your program as you need.

Yes I see exactly how it works thanks.

I'm interested to now how you exported the block as an .ASC file as well.

Share this post


Link to post
Share on other sites

You can right click anything you want....DUT, FB or POU and 'export'.

This saves as an .asc which can then be imported. I find this is the quickest method for importing new code.

Also very useful if you make single changes and want to back up the function rather than the whole program.

 

Regards

 

Daniel.

Edited by collinsd70

Share this post


Link to post
Share on other sites

Hmm That is a bit odd. I imported your FB into a new project but when I right click it I don't have the option to export it, as you can see in the screenshot. I wonder why that might be.

GXWorks.png

Share this post


Link to post
Share on other sites

No that doesn't work either.

I'd love to be able to import and export that easily.

I might start a new thread about it.

Edited by CJP1967

Share this post


Link to post
Share on other sites

This maybe one of the reasons I still use IEC Developer, for some reason they changed a lot of things in GXWorks2 including a lot of the naming conventions which I find odd (why change something if it works?). 

I will have to check this when I am back at my machine.

 

Regards

Daniel

Share this post


Link to post
Share on other sites

I skipped from GX Developer to GX works so it was a big mystery to me for a while.

If you find anything out it would be useful.

Thanks again for your help.

Share this post


Link to post
Share on other sites

Okay. Yes I made transition from GX to IEC Developer when I was a maintenance engineer and it really helped. The IEC standards meant Mitsubishi had to allow you access to program writing in the 5 main industrial languages and also encouraged structured programming with the use of Multi-instance FBs.

This type of programming will get you a long way ahead (certainly made my step in Siemens alot easier). If you can adapt your programming methods to this...it allows for easier to understand program flow.

Regards

Daniel.

 

 

Edited by collinsd70

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