EdgePi-Cloud / edgepi-python-sdk

Python SDK to control EdgePi, an industrial PC/PLC/IoT device powered by Raspberry Pi CM4
MIT License
6 stars 3 forks source link

ADC GND Issue #338

Open sjpark608 opened 1 year ago

sjpark608 commented 1 year ago

Analog ground has a potential failure when the user connects the grounds together through the sensors they are attaching. If the analog and digital sensors share the same power place, it can short the 12V Analog reference to the digital reference.

To avoid this issue, 12V analog reference will be disabled.

Things to be tested

sjpark608 commented 1 year ago

Test Setup

A/DOUT4 -> A/DIN1 GND1 -> GND A/DIN5 -> Black Function Generator A/DIN6 -> Red Function Generator

ADC_AC_DIFF_TEST1 ADC_AC_DIFF_TEST2

sjpark608 commented 1 year ago

Test script using revised ADC

New_ADC_config_calib.xlsx sample.csv

import logging
import time
_logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

from edgepi.adc.edgepi_adc import EdgePiADC
from edgepi.adc.adc_constants import AnalogIn, ConvMode, ADC1DataRate, ADCNum, DiffMode
from edgepi.calibration.eeprom_constants import MessageFieldNumber
from edgepi.calibration.edgepi_eeprom import EdgePiEEPROM
from edgepi.dac.dac_constants import DACChannel as Ch
from edgepi.dac.edgepi_dac import EdgePiDAC

# edge_eeprom = EdgePiEEPROM()
# edge_data = edge_eeprom.get_edgepi_reserved_data()
time.sleep(1)
# edge_data.adc_calib_params[0].gain = 1.000176493
# edge_data.adc_calib_params[0].offset = -0.000869539
# edge_data.dac_calib_params[3].gain = 1.026760142
# edge_data.dac_calib_params[3].offset = -0.019556622

time.sleep(1)

# edge_eeprom.set_edgepi_reserved_data(edge_data, MessageFieldNumber.ALL)

# initialize DAC
edgepi_dac = EdgePiDAC()
# initialize ADC
edgepi_adc = EdgePiADC()
# setting DAC range 0-5V
edgepi_dac.set_dac_gain(False)
# configure ADC to sample A-IN 1 (Refer to the EdgePi label for details)
edgepi_adc.set_config(adc_1_analog_in=AnalogIn.AIN1, conversion_mode=ConvMode.CONTINUOUS, adc_1_data_rate=ADC1DataRate.SPS_20)
edgepi_adc.select_differential(ADCNum.ADC_1,DiffMode.DIFF_1)
# send command to start automatic conversions
edgepi_adc.start_conversions(ADCNum.ADC_1)

time.sleep(1)

# volts = [i for i in range(11)]
volts = [0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0]
adc_reads = []
dac_codes = []
measured = []

edgepi_dac.write_voltage(Ch.AOUT4, 1.254)
for i in range (10):
  adc_read= edgepi_adc.read_voltage(ADCNum.ADC_1)
  print(adc_read)

# for volt in volts:
#   adc_read_sum = 0
#   # write voltage value of 3.3 V to analog out pin number 1
#   edgepi_dac.write_voltage(Ch.AOUT4, volt)
#   measure = float(input("Input Measure: ").strip())
#   measured.append(measure)
#   # read state of DAC output 1
#   code, voltage, gain = edgepi_dac.get_state(Ch.AOUT4, True, True, True)
#   dac_codes.append(code)
#   for i in range(1000):
#     adc_read_sum += edgepi_adc.read_voltage(ADCNum.ADC_1)
#   adc_reads.append(adc_read_sum/1000)

# # stop automatic conversions
# edgepi_adc.stop_conversions(ADCNum.ADC_1)

# with open("samples.csv", "a") as fd:
#   for i in range(len(dac_codes)):
#     fd.write(f"{dac_codes[i]}, ")
#   fd.write(f"\n")
#   for i in range(len(adc_reads)):
#     fd.write(f"{adc_reads[i]}, ")
#   fd.write(f"\n")
#   for i in range(len(measured)):
#     fd.write(f"{measured[i]}, ")
sjpark608 commented 1 year ago

Revised configuration is tested in single-ended, differential, DC, and AC configuration