Silly modbus question - hi/lo register reading

I have a solar inverter that I'm successfully getting values from via ModbusMaster-particle - and so far it's working great for things like voltages, line frequency, percent load, etc - basically, anything that fits neatly into a byte value.

I went for extra credit, and am attempting to read charging watts, which has values like 6000, and that means I have to read a lo and hi register and then do the math to put the two values together. I thought I found an answer, but in using it now, the value I'm getting back is not making sense to me. So asking for help on what is probably a dumb mistake on my part...

Message spec for the device....

The register spec for the hi/lo values for AC charge current...

...and the subsection where I'm trying to do my thing... I want to get to charge AMPS but the device only tells me watts, so I divide watts by volts to get amps. Volts is reading fine.

      result = rs485.readInputRegisters(13,1);
      if (result == rs485.ku8MBSuccess) {
          STATS.ac_charge_watts_high_byte = rs485.getResponseBuffer(0);

         result = rs485.readInputRegisters(14,1);
      if (result == rs485.ku8MBSuccess) {
          STATS.ac_charge_watts_low_byte = rs485.getResponseBuffer(0);

      //compute charge amps, as long as we are all non-zero (no div0 problems)
      // credit:
      // high_byte = 0
      // low_byte = 410
      // line_volts = 246.2
      if(STATS.ac_charge_watts_high_byte >= 0 && STATS.ac_charge_watts_low_byte >= 0 && STATS.line_volts > 0) {
        STATS.charge_current = (((STATS.ac_charge_watts_high_byte << 16 | STATS.ac_charge_watts_low_byte) / 10.0) / STATS.line_volts);
      } else {
        STATS.charge_current = 0.0;

I am expecting values like 20A, but am currently getting 5.7A via this code.

Added some debug cloud functions -

register 13 = 0 (ac watt high)
register 14 = 12280 (ac watt low) units 0.1W

12280 << 16 still equals 12280
12280 | 0 still equals 12280
12280/10 = 1228 / 245.9 (volts) = 5A - so the math is functioning, but the result is not. :stuck_out_tongue:

Any fresh eyes spot a problem?
Thx for listening!

Ok - think I solved it - even tho the register is AC Charge Watts, to get to Amps instead of dividing by the ac line voltage (which you'd think makes sense) if I divide it by the current battery voltage (58.4) I get an answer more like I would expect...

register 13 (ac watt high) = 0
register 14 (ac watt low) = 9520/10 = 952watts
register 17 (batt voltage) = 5840/100 = 58.4V
952W/58.4V = 16.3A <- which is what I would expect

Follow me for more fabulous recipes. [/not]

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.