sangz07
Hi Thiago,
I am working on an Esp32 board to read the analog value on OpenPLC software,
the read analog value will be 2 ranges for the board using 5 VDC(on board ESP32) and 4 ranges for the 3.3 VDC voltage(on board ESP32-S3),
it runs from 0-65472 and then repeats from 0-65472.
For the arduino uno board the analog value read will be 0-65472, it's working ok.
All data types are UINT
Thanks.
 
Sang
Reply 0 0
thiagoralves
Perhaps the multiplying factor in the ESP32 boards is incorrect for the analog resolution of the board. If you know a little bit of C, try examining the hal files for your board at editor/arduino/src/hal
Reply 0 0
buttley
Check to make sure you have the latest version of OpenPLC. There was a pull request that I generated that just went through the in the last couple of weeks that corrected a few problems with analog I/O on the ESP32’s.
I just rechecked my ESP32C6 and it seems to be working.
I’m not sure if this applies to all ESP32’s or not. This information is from the Espressif site.
 
When VDD_A is 3.3V:
  • 0dB attenuaton (ADC_ATTEN_DB_0) gives full-scale voltage 1.1V
  • 2.5dB attenuation (ADC_ATTEN_DB_2_5) gives full-scale voltage 1.5V
  • 6dB attenuation (ADC_ATTEN_DB_6) gives full-scale voltage 2.2V
  • 11dB attenuation (ADC_ATTEN_DB_11) gives full-scale voltage 3.9V (see note below)
Note
The full-scale voltage is the voltage corresponding to a maximum reading (depending on ADC1 configured bit width, this value is: 4095 for 12-bits, 2047 for 11-bits, 1023 for 10-bits, 511 for 9 bits.)
Note
At 11dB attenuation the maximum voltage is limited by VDD_A, not the full scale voltage.
 
By default OpenPLC has the attenuation configured for 11db. Now the bottom not says not to exceed VDD or 3.3 V. Above it says 11db would be take 3.9V to give 4095 (12 bit). What that means is that at 3.3 V you get 3.3 / 3.9 X 4095 or 3465 counts. Now OpenPLC upscales   this to 16 bit by multiplying it by 16. That gives 55430 counts at 3.3V I just tested it on my ESP32C6 and that is almost exactly what I get.
 
I think when I tested my ESP32C3 it gave closer to the 65520 at 3.3 V
 
Reply 0 0
sangz07
Perhaps the multiplying factor in the ESP32 boards is incorrect for the analog resolution of the board. If you know a little bit of C, try examining the hal files for your board at editor/arduino/src/hal
I edited the file eps32.CPP according to the path you provided then I found to
"for (int i = 0; i < NUM_ANALOG_INPUT; i++)
{
if (int_input[i] != NULL)
*int_input[i] = (analogRead(pinMask_AIN[i]) * 64);"
and changed the value 64 to 1 resulting in reading the value give 4096 (12 bits).

thanks.

Sang
Reply 0 0
Reply