Anyone good with maths/binary/hex conversion

Xon

Xon

Associate
Joined
18 Oct 2002
Posts
1,056
Location
Malta
Hi all

I have a problem with reading some modbus value at the moment.

The value is stored on two 16 bit addresses and its giving me two values (1 per address) as unsigned integers. However, these values make no sense to me and I cannot figure out what's wrong or what the calculation is....

A little more info: the actual value is in Amps and I'm reading it from the panel. The values stored in the modbus register should be in mA. Somehow, a combination of the 1st address reading and 2nd address reading should result in this actual value but I can't figure it out.

I know this is a long shot but perhaps someone can point me in the right direction?

Basically:

Field 1 (1st reading)
1st address reading: 4
2nd address reading: 7046
What I should be getting (Actual value): 400

Field 2 (1st reading)
1st address reading: 6
2nd address reading: 37056
What I should be getting (Actual value): 364

Field 3 (1st reading)
1st address reading: 5
2nd address reading: 36442
What I should be getting (Actual value): 364

Field 4 (1st reading)
1st address reading: 5
2nd address reading: 48285
What I should be getting (Actual value): 400

==================

Field 1 (2nd reading)
1st address reading: 4
2nd address reading: 15002
What I should be getting (Actual value): 408

Field 2 (2nd reading)
1st address reading: 6
2nd address reading: 43197
What I should be getting (Actual value): 370

Field 3 (2nd reading)
1st address reading: 5
2nd address reading: 41355
What I should be getting (Actual value): 369

Field 4 (2nd reading)
1st address reading: 5
2nd address reading: 52782
What I should be getting (Actual value): 380
 
Windows calculator has easy conversion for this. Open it then go to View->Scientific
Type in your number and then hit the radio button for whichever conversion you want.
 
If it's a digital input it's unlikely to really have 32 bit resolution - it would probably help to know what the resolution is, and what the upper and lower limits are.
Could it perhaps be an IEEE floating point number represented by the 2 16 bit values? You might have to work out which way round the MSBs and LSBs are for each 16 bit values and then once you've got a float apply some scaling factor and offset to get a meaningful value in mA.
 
Think its a bit more complicated than this...

Field 2 (1st reading)
1st address reading: 6
2nd address reading: 37056
What I should be getting (Actual value): 364

Field 3 (1st reading)
1st address reading: 5
2nd address reading: 36442
What I should be getting (Actual value): 364

They both should return the same value but have different numbers - so either theres more data in there too i.e. field position in sequence or its returning garbage. Until you know that its hard to get any further.
 
Think its a bit more complicated than this...



They both should return the same value but have different numbers - so either theres more data in there too i.e. field position in sequence or its returning garbage. Until you know that its hard to get any further.

That's what got me wondering about IEEE floating point format. There are separate bits for exponent and mantissa, so there could be several sets of readings numbers that give the same measured value.
 
Are you sure these are actually the value readouts? I'm no expert in this field but from a quick google it would appear what your getting is the register addresses for the location storing the actual values?

Whatever it is pretty sure its not as simple as converting the 2 fields into the actual number.
 
Last edited:
Are you sure these are actually the value readouts? I'm no expert in this field but from a quick google it would appear what your getting is the register addresses for the location storing the actual values?

Quite possible, though it would seem a bit strange that the values for the 1st and 2nd reading were held in different locations? Probably a good time to RTFM ;)
 
Back
Top Bottom