Hi all. I am currently working in both Arduino PLC IDE and OpenPLC and seeing some very strange results on the raw values of the analog input.
According to the following post at 10V they recorded a raw input value of 57000. This would imply reaching full scale of the UINT data type at 11.5V, still comfortably below the 24V typical digital input which is reported to have over voltage protection.
Now when running projects compiled in OpenPLC the raw input values are approximately a tenth of value of those seen from code compiled by Arduino PLC IDE. Not only that but I tested 0.0V (loop I0 to negative on Opta), and 4.7V to 15.2V in 0.1V steps. Granted I only eye balled the plot on the screen but the raw values appeared to be behaving linearly in that range and didn't appear to be close to the limits of a 14 or 16 bit data value.
So it would appear that the 0-10V input is actually much wider than that, and either there is a fault in the OpenPLC IDE, or the Arduino library does much more manipulation of the raw ADC value? If for example the 8.9kOhm impedance made a voltage divider split over a 1.2kOhm and 7.7kOhm resistors then this would give an manipulated full scale value of around 24.5V. If this really is the case then this would have an obvious effect on the resolution we can achieve on this input, unless under the hood it is really something like a 32bit ADC.
We really could do with the schematics for these inputs so we knew what we are working with. And a little understanding as to why the impedance appears so low would help. Is it simply a compromise driven by trying to do 24V digital I/O on the same contact as "0-10V" industry like input?
I'm at home at the moment so don't have access to my calibrated meter or soldering gear to setup a voltage divider but suspect the low impedance of the Opta inputs will make to difficult to test the readings using a 24V PSU and 50kOhm voltage divider.
Analog Inputs
The input voltage range for each analog input terminal is the following:
Input voltage range: 0 to +10 VDC
As the internal AREF is 3.3V this is performed by an integrated voltage divider that maps from 0...10 V to 0...3.3V.
This is taken care of in the calculations by constants
// Define constants for voltage, resolution, and divider.
const float VOLTAGE_MAX = 3.3; // Maximum voltage that can be read
const float RESOLUTION = 4095.0; // 12-bit resolution
const float DIVIDER = 0.3034; // Voltage divider
that are used to convert from analog value to voltage
// Convert the terminal value to its corresponding voltage.
float voltage = terminalValue * (VOLTAGE_MAX / RESOLUTION) / DIVIDER;
The maximum analog value should be a result for 10V.
Yes, I have one Opta that I am getting different answers on the raw pin value when programmed with the Arduino PLC IDE and OpenPLC IDE. The resolution for the opta is 2^16, and that divider implies the built in voltage divider is setup to give a full scale reading at 10.9. When was reading input values using the OpenPLC code it was not full scale at an input voltage of 15.2V.
I suspect the full scale comes in little over 24V, and the devices programmed with Arduino PLC massage the raw value into a 0-10V signal. I think this would mean the resolution quoted in the spec sheet is also not right.
I think the resolution stated in the datasheet is ok but the hardware readings are handled differently by Arduino PLC and Open PLC.
Both IDEs seem to use different cores where Arduino PLC is doing what you call "massage" while Open PLC might just take the raw input and adjust it to 16 bit.
Exact answers would require to analyse what's going on in these cores ...
We have found something which was the route cause of why the program was behaving differently to normal. Whats unanswered is what it unlocked as it seemed to change the input range from 0-10V to the full acceptable range of the input of 24V. From a design point of view this makes sense as the voltage divider is probably there all the time, so it's the 0-24V max range of the input that needs to be converted to 0-3.3V. If they set it up for 0-10V it would be complicated to protect that section of the circuit while still allowing the industrial 24V signals. All that said it makes sense to have a mode of opertion as 0-10V, but do we have access setting it to report full scale range too?
I imagine there are some automotive sensors that would be robust, cheap, available, but return 12 or 24V signals for instance.