Posted 21 Apr 2016 Hello! I am trying to get hold of the bits in a word, i have read that union is the way to go. My problem is that i cant figure out how union works. I have made a union between a word (16bit) and an array(0...15). The way I understood this was that the word now automaticly updates the array so that when the least significant bit in the word should update array[00] and so on. This is not happening. When I monitor the variables I can see the word change, but nothing happens with the array. Have I misunderstood the consept and what should I do to get hold of the bits? Share this post Link to post Share on other sites
Posted 21 Apr 2016 Did you do everything with respect to Unions as I suggested in this post: Here is my union definition: Here is my variable definition: Here is my simulated program (all that I did in simulation was to set on Bit00 of the array): Note that the value of UnionTesting.WordVal = 0001 Hex. As expected, the least significant bit turned on when I set bit 0 on. Share this post Link to post Share on other sites
Posted 21 Apr 2016 Thank you for your help! I had the global variables all wrong! Share this post Link to post Share on other sites
Posted 30 Sep 2020 Hi, It doesn't seem to be possible to use the Union inside a Function Block. Am I right? Share this post Link to post Share on other sites
Posted 2 Oct 2020 You can use a union as an internal variable, but not as an input or output. So, here is what you do: Let's say this is your union: You could then create an internal variable in the FB that is of the union type like this: Then you can pass a portion of the union into the FB as an input (Word Input in this case) and map it to the internal union variable, like this: Then when you use the FB in your code, you just choose the WordLevel portion of the union that you want to input into the FB, like this: Share this post Link to post Share on other sites