Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Addressing bit values in Plc

Addressing bit values in Plc 3 years 10 months ago #10646

  • Bruce@Spang
  • Bruce@Spang's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 41
  • Karma: 0
In Ge I can use a bit in an integer value - i.e. Iv.ActualValue##Bit[30]

I have not found a way to store a digital value in Plc using a similar addressing method?
The administrator has disabled public write access.

Addressing bit values in Plc 3 years 10 months ago #10648

  • AutoMate
  • AutoMate's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 159
  • Thank you received: 5
  • Karma: 1
Hi Bruce,

I believe you are referring to bit-packed registers, commonly used in PLCs and Modbus protocols? If so, an unsigned integer is normally used, where every bit represents a digital value. For many older PLCs, unsigned 16-bit integers are used to bit-pack digital signals. Although, the same packing technique can be used with 8-bit or 32-bit integers. Whether the integer is signed or unsigned should not matter since you are using ##Bit[xx] to extract each bit in your your graphic.

Regards,
/Ron
The administrator has disabled public write access.

Addressing bit values in Plc 3 years 10 months ago #10649

  • Bruce@Spang
  • Bruce@Spang's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 41
  • Karma: 0
Yes, that is correct. I am trying to find the syntax - or if it is more complex - method for addressing a bit in a 'bit-packed register' uint32 or uint16 etc inside the Plc programming environment fr ProwviewR
The administrator has disabled public write access.

Addressing bit values in Plc 3 years 10 months ago #10650

  • AutoMate
  • AutoMate's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 159
  • Thank you received: 5
  • Karma: 1
Hi Bruce,

Welcome to the wonderful world of bit masking. Consider investigating the following function blocks under the Integer folder:

BwAnd = Integer AND mask
BwOR = Integer OR mask
BWRotateLeft = Bit-wise rotate left
BWRotateRight = Bit-wise rotate right

The idea is to use a bit-mask to compare one or more specific bits in a integer that is bit-packed. For example, an 8-bit integer contains the following bit pattern: 01001011. A second integer is used to extract a specific bit. To test the fourth bit from the right, a mask of 00001000 is used. The result of 01001011 AND 00001000 = 00001000. Compare this value with ODD to determine if the bit is true or false. Or, you may shift the result 3 places to the right with BWRotateRight for a result of 00000001. There are many ways to achieve similar results. A quick, untested example is given below:

Bit_Mask_Extraction_Example.png


In this example, a constant input value of 1 in the RotateLeft block is rotated left by the number of positions specified by the N input to create a MASK. This MASK is BwAND'd to a bit-packed integer to extract a specific bit of interest. And Odd function provides a digital output that is either TRUE or FALSE.

There are many schemes that will work to achieve the same result. Some solutions are more clever than others. Maybe someone on the forum will suggest a more eloquent scheme? :)

Integer bits can be manipulated on a bit by bit basis in a similar manner using a MASK and BWOr function.

Regards,
/Ron
The administrator has disabled public write access.
The following user(s) said Thank You: Bruce@Spang

Addressing bit values in Plc 3 years 10 months ago #10651

  • Bruce@Spang
  • Bruce@Spang's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 41
  • Karma: 0
Thanks -

I had done basically something like that, and have PAGES and PAGES of Plc code devoted to just examining bits that I'd love to condense. Maybe the only solution is roll-my-own C code modules. But I was hoping (since Ge had covered it nicely with the ...##Bit[20] style access) that I was just missing a feature that was already there...
The administrator has disabled public write access.

Addressing bit values in Plc 3 years 10 months ago #10652

  • AutoMate
  • AutoMate's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 159
  • Thank you received: 5
  • Karma: 1
Bruce,

Other function blocks that may be helpful are found under Signals->Conversion->MaskToD and DtoMask.

/Ron
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Time to create page: 7.741 seconds