Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Modbus data L M H

raman00084

Full Member level 6
Full Member level 6
Joined
Nov 29, 2010
Messages
372
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Activity points
4,062
What is L M H in the attached modbus screen short.
How to compute the value

Screenshot_20240813_223805_OneDrive.jpg
 
Byte means 8 bits?

1) Dimension 24-bit variables.
2) Start with Most Significant Byte. Left-shift 16 times. This puts zeroes in rightmost 16 columns.
3) Take middle byte. Left-shift 8 times. This puts zeroes in rightmost 8 columns.
4) No need to alter Least Significant Byte.
5) Now add all three together.
 
You can calculate using the following formula: H * 0x1000 + M * 0x100 + L
Yes, you could, but the result would be wrong.

****

I did not expect the OP (as a long term member) to ask this basic question.
It has been discussed with formulae, with mathematics, with code examples for decades and many million times. ... in basic coding documents.
Thus I´m not sure what to answer.

Code:
I mean bitwise it is:
* H-Byte: HHHHHHHH
* M-Byte: MMMMMMMM
* L-Byte: LLLLLLLL
so in total: HHHHHHHHMMMMMMMMLLLLLLLL


Klaus
 
It hasn't been mentioned which numbers are handled by the MODBUS library, I guess at least 16-Bit quantities (registers) possibly even 32-Bit (double register).

Code C - [expand]
1
encoderval = reg_read(0x4202) + (uint32)(reg_read(0x4203) & 0xff) << 16;

 
Yes, you could, but the result would be wrong.

****

I did not expect the OP (as a long term member) to ask this basic question.
It has been discussed with formulae, with mathematics, with code examples for decades and many million times. ... in basic coding documents.
Thus I´m not sure what to answer.

Code:
I mean bitwise it is:
* H-Byte: HHHHHHHH
* M-Byte: MMMMMMMM
* L-Byte: LLLLLLLL
so in total: HHHHHHHHMMMMMMMMLLLLLLLL


Klaus
The documentation states that H M L are bytes (0-255), so my formula will work without any problem with these conditions.
 
The documentation states that H M L are bytes (0-255), so my formula will work without any problem with these conditions.
I don´t think so:
Code:
LLLLLLLL          = 0000000000000000LLLLLLLL
MMMMMMMM x 0x0100 = 00000000MMMMMMMM00000000
HHHHHHHH x 0x1000 = 0000HHHHHHHH000000000000
                    ========================
Added:            = 000?????????MMMMLLLLLLLL

Klaus
 
@KlausST Yes, you are right. There is a typo in my formula. Unfortunately, I cannot edit that message. The correct formula is:
H * 0x10000 + M * 0x100 + L
 
makes more sense now.

Still unclear what the OP is after.
Code? (Which language, which IDE, wich microcontroller)
Explanation --> should already be given
Math --> given
Sth else? --> don´t know

Klaus
 

LaTeX Commands Quick-Menu:

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top