LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

change 1 bit in a register

Hello.  Hopefully, someone can help me. I am controlling motor with the LabVIEW. To change some parameters, I need to program specific value in a specific register. In the attachment, I added the example how I do it now. If the value if not specified - its 0, otherwise I specifically set it to 1 or other parameter than can be dynamically changed during my test. For example, if the default value in the register 0x53F3 and I want to change bit 3 to 1, I also need to specify other bit that are not 0, otherwise they will be reset to 0 (according to the way I do it now). Is there a way to change only 1 bit in a register and keep the rest of the values as they were before and not specify each bit that is not 0. Thank you 

0 Kudos
Message 1 of 5
(190 Views)

I'm not sure where excactly you're struggling, but:

wiebeCARYA_0-1714727766128.png

The logical shift isn't a bad option, I'm just showing 2 alternatives:

+ Scale By Power Of 2

+ A constant set to binary

 

Note the dot on the AND, that inverts the bit pattern, so the bits that are true, becomes the only bits that are false, so they become cleared.

 

To set bit(s) and clear bit(s), you need to AND and OR.

 

To toggle bit(s) use XOR.

Message 2 of 5
(184 Views)

O, and change your nick name!

 

Your email address is exposed to the internet!!

0 Kudos
Message 3 of 5
(182 Views)

Read out the current register, Set bit 3 with OR 4 (or 1 with logical shift 2 as you do now (=4)) and turn if off with AND the inverse of 4.

Another solution, which might be easier to understand but less effective, is to convert the register to a boolean array and Replace Arrray on the bit, the convert it back.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 4 of 5
(179 Views)