ZHCUD83 August 2025
可通过许多方式配置 ADC。示例如下:
ftdiObject.spiWrite(PAGE_ADDRESS, PAGE_ADC_CONFIG) #Set the page to ADC CONFIG, page 1
#Set the False Alarm threshold, ADC Auto/Direct mode, and Shunt range.
#This will set the False Alarm thresholds to 4 samples, the ADC to Automode, and the Shunt range to 163.84mV
ftdiObject.spiWrite(ADC_GEN_CFG_ADDRESS, ADC_GEN_CFG_FALR_SENSE_4 + ADC_GEN_CFG_FALR_ADC_4 + ADC_GEN_CFG_FALR_TMP_4 + ADC_GEN_CFG_AUTOMODE_Automode + ADC_GEN_CFG_SHUNT_RANGE_163p84mVrange)
#Set the conversion rate. This will set all channels to 152us.
ftdiObject.spiWrite(ADC_CONV_CFG_0_ADDRESS, ADC_CONV_CFG_0_CONV_RATE_ADC_152us + ADC_CONV_CFG_0_CONV_RATE_SENSE_152us + ADC_CONV_CFG_0_CONV_RATE_TMP_152us)
#Set the sampling rate. This will set all channels to 1 sample.
ftdiObject.spiWrite(ADC_CONV_CFG_1_ADDRESS, ADC_CONV_CFG_1_AVG_ADC_1sample + ADC_CONV_CFG_1_AVG_SENSE_1sample + ADC_CONV_CFG_1_AVG_TMP_1sample)
#Set the ADC Hysteresis. This sets to default.
ftdiObject.spiWrite(ADC_HYST_0_ADDRESS, ADC_HYST_0_DEFAULT)
ftdiObject.spiWrite(ADC_HYST_1_ADDRESS, ADC_HYST_1_DEFAULT)
#Set the ADC channel thresholds for the Alarm configurations. These set to default.
ftdiObject.spiWrite(ADC0_LO_THRESH_ADDRESS, ADC0_LO_THRESH_DEFAULT)
ftdiObject.spiWrite(ADC1_LO_THRESH_ADDRESS, ADC1_LO_THRESH_DEFAULT)
ftdiObject.spiWrite(ADC0_UP_THRESH_ADDRESS, ADC0_UP_THRESH_DEFAULT)
ftdiObject.spiWrite(ADC1_UP_THRESH_ADDRESS, ADC1_UP_THRESH_DEFAULT)
ftdiObject.spiWrite(SENSE0_LO_THRESH_ADDRESS, SENSE0_LO_THRESH_DEFAULT)
ftdiObject.spiWrite(SENSE0_UP_THRESH_ADDRESS, SENSE0_UP_THRESH_DEFAULT)
ftdiObject.spiWrite(SENSE1_LO_THRESH_ADDRESS, SENSE1_LO_THRESH_DEFAULT)
ftdiObject.spiWrite(SENSE1_UP_THRESH_ADDRESS, SENSE1_UP_THRESH_DEFAULT)
ftdiObject.spiWrite(TMP_UP_THRESH_ADDRESS, TMP_UP_THRESH_DEFAULT)
#Start ADC. TRIGGER then read the ADC outputs.
ftdiObject.spiWrite(TRIGGER_ADDRESS, TRIGGER_ADC_TRIG_EnableADC)
print("SENSE0: " + ftdiObject.spiRead(0x18)) # ADC_SENSE0 channel readback
print("SENSE1: " + ftdiObject.spiRead(0x19)) # ADC_SENSE1 channel readback
print("ADC0: " + ftdiObject.spiRead(0x1A)) # ADC_ADC0 channel readback
print("ADC1: " + ftdiObject.spiRead(0x1B)) # ADC_ADC1 channel readback
print("TEMP: " + ftdiObject.spiRead(0x1C)) # ADC_TEMP channel readback