BPC_Eng
Hi, not sure if this is normal behavior when reading Analog input values.  I have set up a small test as I am wanting to set up some assessments where student programs read the analog inputs on Arduino's running OpenPLC.

I have an RPI running the runtime and have set up an Arduino Uno with Modbus RTU enabled.  Program below,

Obviously, I am expecting the ADC being 10bit to give results of between 0 and 1023.  However, it produces output in increments of 64.   I just wonder if this is normal behavior when using Modbus.

I can of course work around this as shown in my program to correct this with a couple of type conversions and a DIV Function Block now I understand what the likely output is going to be.

If this is normal then at least I now know what to expect!


Clipboard01.jpgClipboard02.jpg
Reply 0 0
thiagoralves
OpenPLC analog inputs and outputs are 16-bits. Since the runtime is compatible with several different platforms with several different specifications, the runtime automatically scales the readings to a 16-bit variable so that the same program would run the same way on different hardware.

Tip: If you really need to have all values in 10-bits it is way faster to use the shift right block to make the conversion instead of pulling out an arithmetic div operation. The result is the same, of course. This is just a nice optimization to have.
Reply 0 0
BPC_Eng
Thank you for the clarification.   I see why you have done this now.  It was just unexpected.

The bit shift right is much more concise.

Clipboard03.jpg

 
Reply 0 0
Reply