matthewsrea
Hey, I'm no expert - but I think I've unearthed something a bit odd. Have done a few tests to validate my thinking... and have concluded it is worth reporting. I'm seeing a problem with how LREAL data is transferred to Modbus holding registers - put simply it seems like the "least 2 significant words" (of the 4 word data) is being written to Modbus address ahead/in-front of the correct offset address . I attach my testing and observations
Reply 0 0
matthewsrea
Or is this just me getting confused about Big/Little-endian issues and I've got my %ML1 offset wrong?
Reply 0 0
thiagoralves
Some embedded platforms do not support FP64 (64-bit floats), and scale down any FP64 to regular 32-bit floats. This is a hardware limitation and has nothing to do with OpenPLC. It is possible to do FP64 in software, but given the limited CPU in these systems, it is not advisable to do so unless extremely necessary, as any computation with FP64 will be orders of magnitude slower than 32-bit floats. So, in summary, even though you’ve declared your variable as LREAL (and OpenPLC does declare that as 64-bit float as well), the hardware is treating that as a 32-bit float.
Reply 0 0
matthewsrea
Really appreciate your prompt and detailed response. Very helpful guidance on the speed advantages of REAL vs LREAL computations - after all we're all trying to make this stuff run as efficiently as possible and with least overhead. The only reason I had gone down the LREAL route was because I'm using an Adafruit library to read from an HDC302x (temp/humidity) and the library declares both parameters as "double". I spent yesterday afternoon recoding my sketch to have all variables as REAL except for two locals that are LREAL passed to the Adafruit library. After the library call I'm now simply casting the resultant locals into a couple of REAL externs that can then been used by my ladder logic and read via Modbus. It all works (he says... I do have another question but it belongs in another thread - so will post it there). So again thanks for such a prompt response. I think the only issue that you answer didn't really 100% clarify for me was why, when I was using a LREALs,, were the values being saved to the the wrong holding register offsets (where I could see the least two significant words being posted seemingly two whole offsets out). Moving from LREALs to REALs is a great solution... but that observed behaviour in my first post is still bugging me... I get that the FP64 capability can't be relied on, but would this entirely explain what I was seeing. Thanks
Reply 1 0
thiagoralves
I’m checking your point about the ML registers. There could be a bug on the offsets there
Reply 0 0
Write a reply...
Reply