ZHCUD83 August   2025

 

  1.   1
  2.   摘要
  3.   商标
  4. 简介
  5. FT4222_Python_Controller.py
    1. 2.1 I2C 命令
    2. 2.2 SPI 命令
  6. AFE20408_Page_Global_Def.py
  7. AFE20408_Page_0_Def.py
  8. AFE20408_Page_1_Def.py
  9. AFE20408_Page_2_Def.py
  10. AFE20408_Page_3_Def.py
  11. AFE20408_Page_4_Def.py
  12. AFE20408_Page_6_Def.py
  13. 10Main.py
  14. 11通用序列
    1. 11.1 复位序列
    2. 11.2 ADC 配置
    3. 11.3 DAC 配置
  15. 12常见问题
  16. 13总结

Main.py

Main.py 是一个示例文件,展示如何初始化 FTDI 并将基本命令写入 AFE20408。为方便起见,将 Main.py 中的代码粘贴到了此处。

#Import all helper files
from FT4222_Python_Controller import *
from AFE20408_Page_0_Def import *
from AFE20408_Page_1_Def import *
from AFE20408_Page_2_Def import *
from AFE20408_Page_3_Def import *
from AFE20408_Page_4_Def import *
from AFE20408_Page_6_Def import *
from AFE20408_Page_Global_Def import *

if __name__ == '__main__':
    ftdiObject = FtdiController()   #initialize FTDI
    ftdiObject.getFtdiDeviceInfo()  #Get FTDI Info

    #SPI Communication Initialisation
    ftdiObject.initializeSPI(ft4222.SPIMaster.Mode.SINGLE, ft4222.SPIMaster.Clock.DIV_2, ft4222.SPI.Cpol.IDLE_LOW, ft4222.SPI.Cpha.CLK_TRAILING, ft4222.SPIMaster.SlaveSelect.SS0)
    
    """
    TO WRITE TO AFE20408:
    ftdiObject.spiWrite([REGISTER ADDRESS], [DATA])

    TO READ FROM AFE20408:
    ftdiObject.spiRead([REGISTER ADDRESS])
    """

    """Page 0 Setup - GENERAL CONFIGURATION"""
    ftdiObject.spiWrite(PAGE_ADDRESS, PAGE_GEN_CONFIG) #Set page to Gen Config, page 0
    ftdiObject.spiWrite(SDO_EN_ADDRESS, SDO_EN_SDOenabled) #enable SDO for reading
    print(ftdiObject.spiRead(CHIP_ID_ADDRESS))   #confirm AFE20408 is communicating

    #Setup PAON pin = Push-pull, Active High.
    ftdiObject.spiWrite(GEN_CFG_0_ADDRESS, GEN_CFG_0_FLEXIO_OUT_ODE_PushPull + GEN_CFG_0_PAON_POLARITY_ActiveHigh)
    #Setup VSS range. This sets the Mid Range. Sets the FLEXIO function as RESET.
    ftdiObject.spiWrite(GEN_CFG_1_ADDRESS, GEN_CFG_1_VSSA_RANGE_MidRange + GEN_CFG_1_VSSB_RANGE_MidRange + GEN_CFG_1_FLEXIO_FUNC_RESET)
    
    #Set up the ALARMOUT alarms. This only works if the FLEXIO pin is set to ALARMOUT.
    ftdiObject.spiWrite(ALARMOUT_SRC_0_ADDRESS, 0x0000) #Set to default
    ftdiObject.spiWrite(ALARMOUT_SRC_1_ADDRESS, 0x1833) #Set to default
    #Set up the PAON alarms. This does not matter if you do not use the PAON pin.
    ftdiObject.spiWrite(PAON_SRC_0_ADDRESS, 0x0133) #Set to all sources.
    ftdiObject.spiWrite(PAON_SRC_1_ADDRESS, 0x1833) #Set to default

    """Page 1 Setup - ADC CONFIGURATION"""
    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)

    """Page 2 Setup - ADC CCS CONFIGURATION"""
    ftdiObject.spiWrite(PAGE_ADDRESS, PAGE_ADC_CCS_CONFIG) #Set the page to ADC CCS CONFIG, Page 2
    #Example: Setup to read from SENSE0 after every other channel.
    ftdiObject.spiWrite(ADC_CCS_IDS_0_ADDRESS, ADC_CCS_IDS_0_CCS_ID_0_ADC0 + ADC_CCS_IDS_0_CCS_ID_1_SENSE0)
    ftdiObject.spiWrite(ADC_CCS_IDS_1_ADDRESS, ADC_CCS_IDS_1_CCS_ID_2_ADC1 + ADC_CCS_IDS_1_CCS_ID_3_SENSE0)
    ftdiObject.spiWrite(ADC_CCS_IDS_2_ADDRESS, ADC_CCS_IDS_2_CCS_ID_4_SENSE1 + ADC_CCS_IDS_2_CCS_ID_5_SENSE0)
    ftdiObject.spiWrite(ADC_CCS_IDS_3_ADDRESS, ADC_CCS_IDS_3_CCS_ID_6_TMP + ADC_CCS_IDS_3_CCS_ID_7_SENSE0)
    #Set the Start and Stop indices to 0 and 7
    ftdiObject.spiWrite(ADC_CCS_CFG_0_ADDRESS, 0x0007)

    """Page 3 Setup - DAC CONFIGURATION"""
    ftdiObject.spiWrite(PAGE_ADDRESS, PAGE_DAC_CONFIG) #Set the page to DAC CONFIG, Page 3
    #Set the DAC current limits. This sets all the DACs to max current limit, 120mA
    ftdiObject.spiWrite(DAC_CURRENT_ADDRESS, 0xFFFF)
    #Set the OUT CLAMPs. This sets OUTA0 CLAMP = DACA1, OUTA2 CLAMP = DACA3, OUTB0 CLAMP = DACB1, OUTB2 CLAMP = DACB3
    ftdiObject.spiWrite(DAC_CFG_ADDRESS, DAC_CFG_CLAMP_SEL_OUTA0_OUTA0clampvoltageisDACA1 + DAC_CFG_CLAMP_SEL_OUTA2_OUTA2clampvoltageisDACA3 + DAC_CFG_CLAMP_SEL_OUTB0_OUTB0clampvoltageisDACB1 + DAC_CFG_CLAMP_SEL_OUTB2_OUTB2clampvoltageisDACB3)
    #Disables DAC broadcast and Syncronous modes.
    ftdiObject.spiWrite(DAC_SYNC_CFG_ADDRESS, 0x0000)
    #Set the DAC Alarm Powerdown settings. This sets the register to default - All DACs power down to VSS during an Alarm.
    ftdiObject.spiWrite(DAC_APD_EN_ADDRESS, DAC_APD_EN_DEFAULT)
    #Configure what Alarms trigger each DACs. This enables all alarms)
    ftdiObject.spiWrite(DACA_APD_SRC_0_ADDRESS, 0x0133)
    ftdiObject.spiWrite(DACA_APD_SRC_1_ADDRESS, DACA_APD_SRC_1_DEFAULT)
    ftdiObject.spiWrite(DACB_APD_SRC_0_ADDRESS, 0x0133)
    ftdiObject.spiWrite(DACB_APD_SRC_1_ADDRESS, DACB_APD_SRC_1_DEFAULT)
    ftdiObject.spiWrite(OUTA_APD_SRC_0_ADDRESS, 0x0133)
    ftdiObject.spiWrite(OUTA_APD_SRC_1_ADDRESS, OUTA_APD_SRC_1_DEFAULT) 
    ftdiObject.spiWrite(OUTB_APD_SRC_0_ADDRESS, 0x0133)  
    ftdiObject.spiWrite(OUTB_APD_SRC_1_ADDRESS, OUTB_APD_SRC_1_DEFAULT) 
    #Set the DRVEN pin configuration. This sets the OUT pins to toggle with DRVEN0, and disables DRVEN1.
    ftdiObject.spiWrite(DRVEN0_EN_ADDRESS, DRVEN0_EN_DRVEN0_EN_DACA0_En + DRVEN0_EN_DRVEN0_EN_DACA2_En + DRVEN0_EN_DRVEN0_EN_DACB0_En + DRVEN0_EN_DRVEN0_EN_DACB2_En)
    ftdiObject.spiWrite(DRVEN1_EN_ADDRESS, 0x0000)

    """Setup Global Page"""
    #Disable Software DRVEN for the OUT pins
    ftdiObject.spiWrite(DRVEN_SW_EN_ADDRESS, 0x00AA)
    #Enable Software DRVEN on the odd DACs. REQUIRED for enabling DACA1/3, DACB1/3
    ftdiObject.spiWrite(DRVEN_ADDRESS, 0x00AA)
    #Enable all DACs
    ftdiObject.spiWrite(PWR_EN_ADDRESS, 0x00FF)

    """Set DAC voltage"""
    ftdiObject.spiWrite(PAGE_ADDRESS, PAGE_DAC_BUFFER) #Set DAC Buffer page, Page 4
    #DAC voltage (Positive) = (DAC_CODE * 10)/2^13
    #DAC Voltage (Negative) = (DAC_CODE * 10)/2^13 - 10
    ftdiObject.spiWrite(DACA0_ADDRESS, 0x1570) # -3.3V or 6.7V depending on output range.
    ftdiObject.spiWrite(DACB0_ADDRESS, 0x0A8F) # 3.3V or -6.7V depending on output range.

    #Start ADC
    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
    
    #close the FTDI when done.
    ftdiObject.closeHandle()