Conversion of integer to boolean

govind2k9

Member
Join Date
Sep 2012
Location
Aberdeen
Posts
14
Hi,

I need to decode the integer value to boolean and store the each bit of 16bits in different variable of boolean type and to be used in the program. I am using siemens Step 7 5.5. Is it possible to do this?
 
If you store the integer in an word, say MW0, you can access every individual bit by using M0.0 - M1.7.

Same goes for DB (DBW0 - DBX0.0-1.7)
 
Hi all,
Thanks for reply. Now I would like to ask is there any way to do this in a multi instance FB. I receive integer variable in FB and save it in a local variable (Stat) in FB. I need to access the bits of the integer and to be used as NO or NC in the FB.
I tried this code and I am able to use individual bits of the integer but it works if there is only one FB not in multiinstance.

TAR1 #TempAR1
LAR1 P##VALVE_CONFIG_NO
L W [AR1,P#0.0]
T W [AR2,P#312.0] //Address pointer of the "Decoding_struct"
LAR1 #TempAR1

Please see attached picture to see how Decoding_struct is declared in FB.

Untitled.jpg
 
Here's an example implementation that uses a function that will move a word from a source to a destination using pointers.

To access variables indirectly in multiple instance FB's, you have to add AR2 to the pointer to the variable. The method I have shown uses the block editor to perform the addition "in the background".
 
Last edited:
Hi there,

Thank you very much for the code. It worked just fine. Sorry for being late as I was caught in offshore support and couldn't try this code in the weekend. I tried FC MoveWord in multiInstance FB and it's working with no issues.
 

Similar Topics

Hi, I need to decode to the integer value to boolean and store the each bit of 16bits in different variable of boolean type and to be used in the...
Replies
2
Views
3,458
Hi, Is there a boolean to integer conversion for the GE 90-30 PLCs? I want to determine how many fans are running, (%I1 - 20). I was going to...
Replies
2
Views
2,950
I know there's the DTOS Function, but I have a value of "35" that is really "0035", and that's how I want it converted. Looks like the function...
Replies
2
Views
1,526
I'm reading some data from a device using Modbus TCP and am having some difficulty getting the two 16 bit words converted to FP. I've done...
Replies
2
Views
1,665
Hi all, I am quite new to PLC programming, so pardon my noob-ness. First, I have counters & timers in my program that I use to calculate total...
Replies
2
Views
3,550
Back
Top Bottom