|
Description The STEP 7 (TIA Portal) V11 program "STEP7_V11_Bit_Field_Pos" includes two functions that you can use to determine the bit position of an active bit in a marker word and monitor a 32-bit field for incoming and outgoing events.
Evaluation of the bit position of the active bit in a marker word The "Bit_Pos" function calculates the active bit in a marker word. If, for example, you program a sequence control in a marker word for a sequential process, then in this marker step word only one bit is ever active corresponding to the currently active step of the sequencer. Using the bit count you can visualize the active step as plaintext via symbol lists in a visualization system, for example. For visualization it is better to receive the bit position and thus the currently active step as an integer value.

Fig. 01
When just one bit is always set, this yields the following correlation:
2X = Y
X = lnY / ln2
Here X is the bit position and Y is the value of the marker word. For the bit position you must increment X by 1. In addition, the "Bit_Pos" function takes into account the two special cases where the value Y must not be zero or negative (sign).
Monitoring of a 32-bit field
In order to monitor a 32-bit field for incoming and outgoing events, you can use the "Monitor_Bit" function to query the bits to be monitored for positive and negative edges. However, just as in the example described above, a double-word is defined here as DINT and the set bit is calculated.
Programming in the "Monitor_Bit" function is implemented as follows:
- In order to filter out from any number of bits set the bit that has changed its status in this cycle you use an EXCLUSIVE OR DOUBLE WORD operation between the value of the last cycle and that of the current cycle. An EXCLUSIVE OR yields only that bit which occurs exclusively for one of the two values.
- Using another AND query you determine whether that bit is an incoming or outgoing signal.
- If only one bit is set for this double integer, then the definition described above applies for the DI value Y. You obtain the X value from this conversion: X = lnY / ln2 and the bit position is yielded with the increment: X + 1.
Note
You can determine the incoming and outgoing events for Bits 1 to 31 arbitrarily, which applies for the value range of 0 to +2147483647. Bit 32 is valid for the sign. If Bit 32 receives the signal status 1, the number for the set Bit 32 is output ("Bit" output) and the bit for the "Event_Come" output (for incoming event) is set. However, if you continue to use the function and want to determine more incoming and outgoing events, you must reset Bit 32 to zero beforehand.

Fig. 02
In the example in Fig. 02 the signal status at Bit 16 has changed from 0 to 1. The determined bit no. 16 is output at the "Bit" output and the "Event_Come" output receives the True signal (for an incoming event).
Copy the "STEP7_V11_Bit_Field_Pos.zip" file into a separate directory and then start the file with a double-click. The STEP 7 project is now unpacked automatically with all the associated subdirectories. You can then use STEP 7 V11 to open and process the extracted project. The two functions include German and English comments.
STEP7_V11_Bit_Field_Pos.zip ( 2492 KB )
Creation environment
The screens and download in this FAQ response were created with STEP 7 (TIA Portal) V11. The following table lists the components that have been used to create this entry and verify the functions described.
| Test environment |
Version |
| PC platform |
Intel(R) Core(TM)2 Duo CPU P8700 2.53 GHz |
| PC operating system |
MS Windows XP SP3 |
| STEP 7 (TIA Portal) |
V11 + SP2 |
| CPU 1214C (6ES7214-1AE30-0XB0) |
Firmware V2.0 |
|