formulal for 32 to 16 bit conversion

pauljess

Member
Join Date
Jul 2018
Location
Orlando
Posts
4
I am using a click plc and trying to convert a 32 bit signed integer into two 16 bit signed integer and having no luck. does anyone have a formula to use? I need the integers to be signed to send to a servo requiring -or+ for direction.
please help!
Thanks!
 
Can you give a specific example of what you're trying to do? As long the value encoded in the 32 bit signed integer can be expressed in sixteen bits, all you need to do is strip off the upper sixteen bits of the 32 bit signed integer. A sixteen bit signed integer can be in the range of -32768 to +32767.
 
I am using a 4096PPR servo 4 revolutions =.2" with overall 28"
(4096*4*5*28)-(4096*4*5*20)=655360 (20" example).
How do I change 655360 to two 16bit signed integers?
Click does not have a masked move function so is there a formula?
 
What Steve means, I think, what do you want the numbers to represent?

In your case, 655,360 would not be compatible with 16 bit logic.
So do you want the first int to contain the first 3 digits, and the second the last 3 digits or something?

Not familiar with click, but if you divide the original number by 1000, move that to first int. Then move the subliment to your second int.
 
What pauljess means is,

They have a 32 bit signed integer (0x1234ABCD) and want to extract the high byte and the low byte into two separate 16 bit signed integers (0x1234 and 0xABCD).

This would be a COP myDINT myINT[0] 2 in rslogix.

But how to do it in a click?
 
If AustralIan has got the requirement correct, look into the copy instruction. It's about your only option for moving data around, and it has a lot of different options. I'm pretty sure one of them will do what you're after. Although, you *might* have to go via hex.
 
Splitting a negative number into two parts is going to end up pretty strange unless you are going put it back together again. The most significant word should give the sign of the whole number. If its MSB is high then the whole number is negative and the lower word will need the 2's compliment reversed. That way you get a 16 bit signed number for the most significant word and an unsigned 16 bit number for lower 16.
 
I'm still not clear on what the OP is trying to do. The Click supports 32-bit signed integers. How do you need to break apart that count of 655360 to send to the servo? Number of full turns of the motor plus number of counts in the partial turn?
 
The servo that I am trying to send a message to has to have two separate 16bit integers..IE hi bits and low bits. in click there isn't anything that I could find that would separate out the bits like a masked move. is there a formula I could do in the math to create two 16 bit integers that would represent the 32bit integer? the servo uses 32 bit signed integer to move. it reads the hi bits first then adds the second sent a second later and combines the two into a single 32 bit. I am using a DMM DYN4 Series servo. Thanks in advance for any help you can provide!
 
You send all 32 bits in a single write command. According to the Modbus manual for the drive
In order to maintain data reliability, always set both high bytes and low bytes together.
The thing you will have to watch out for is to make sure the Click sends the 32 bits in the correct order. The servo will interpret the bit pattern as the first sixteen bits being the most significant (high) word and the next sixteen bits being the least significant (low) word.
 
attached is a sample of how to send a command to the servo that DMM provided. it requires using two separate commands with two separate 16bit signed integers (DS). how do I send a 32bit signed integer to this?
 
Use Modbus function code 16 (Write multiple registers) instead of code 6 (write single register).
For Master address use DDxxx instead of DSxxx. That's a 32-bit number.
For the number of master addresses, I'm not sure. A value of 1 may be enough if the function block takes into account the DDxxx address. If the number of master addresses denotes the number of 16-bit words, you'll need to enter a value of 2.
The Word swap parameter will allow you to manipulate the order of the high and low words to match how the servo will interpret the data.
 

Similar Topics

A couple days ago I accidentally toggled an alwasyoff bit. The issue is it was set up as a single OTU on a rung, nothing else, and used as XICs...
Replies
3
Views
193
Hi I have an old panel builder 32 that I’m replacing for a factory talk me hmi . In the plc for the old panel builder there is a coms bit for the...
Replies
0
Views
61
Hello, Haven't been on in a while. I need to generate a bit level pdf of the I/O for RSLogix 500. I can generate a report but it just shows the...
Replies
1
Views
110
I tried researching but I still don't quite get it. As far as I understood, it's used after a function is called in STL and then if the function...
Replies
1
Views
127
Hi. I'm struggling over some basic stuff here. 41001 I is a 16 bits integer that I'm able to read with InTouch. What I need to do is to read...
Replies
1
Views
84
Back
Top Bottom