05-03-2024 04:08 AM
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
05-03-2024 04:19 AM
I'm not sure where excactly you're struggling, but:
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.
05-03-2024 04:19 AM
O, and change your nick name!
Your email address is exposed to the internet!!
05-03-2024 04:21 AM - edited 05-03-2024 04:23 AM
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.
05-03-2024 04:32 AM