Post Go back to editing

How to setup ADC4116 for reading sample data from individual channel ?

Category: Software
Product Number: AD4116

I just started using ADC AD4116-datasheet for sensing multiple voltage signals connected to individual VIN channel on AD4116 

I have this ADC connected to  STM32 Nucleo-f446re board  via SPI interface.

I want to know what are the steps needs to perform below requirement :

1. initialize, configure ADC for using all VIN pins to sense voltage readings
2. get sample data from particular VIN at a time

I have looked into this driver code but didn't get it how to use this to perform above mentioned requirement
ad717x driver


Note:I already know low level SPI transmit, receive functionality so just want to know what packets needs to transfer for performing above requirement 

Any sample code which can shows to perform above requirement,
as I am not getting what and how to configure in order to make ADC ready to use for sampling as well as how to get sample from particular channel 

Edit Notes

updated notes
[edited by: ercjethava at 4:04 AM (GMT -5) on 9 Jan 2025]
  • Hi  ,

    You may refer on figure 37 in the datasheet for the suggested configuration flow of the AD4116. 

    One thing to take note that at default settings of the Setup configuration, the default channel does not operate correctly because the input buffers are also disabled. When measuring input voltages is that the input buffers must be enabled correctly for a VIN input.

    The analog input buffers should be enabled for voltage Analog Inputs as these provide a low source impedance to the sampling ADC. If these buffers were disabled, then a large resistance would exist. This combined with any parasitic capacitance from the resistive front end driving the ADC input will result in a large gain error. 

    When multiple channels are enabled, The ADC automatically sequences through the enabled channels, performing one conversion on each channel from lowest enabled channel to the highest enabled channel. To read the conversion, if CS is low, the RDY output also goes low signifying the end of conversion of a channel. You can readback the data conversion by a write to the Communications register indicating that the next operation is a read of the data register. When the data-word has been read from the data register, the DOUT/RDY pin goes high. 

    To determine which channel the data corresponds to, you must set the DATA_STAT bit in the interface mode register to 1 so that the contents of the status register is appended along with the conversion data. The four LSBs of the status register indicates the channel to which the conversion corresponds.

    You may refer on the Operating Modes section of the datasheet for additional information.

    We also have available sample codes which you may used as a reference. The links below are all available in the product page

    GitHub - analogdevicesinc/precision-converters-firmware: Precision Converters Embedded Firmware Repository

    AD717x IIO Application [Analog Devices Wiki]

    EVAL-AD717x-AD411x-IIO - IIO firmware for the AD717x and AD411x family of … | Mbed

    AD717x/AD411x Console Application [Analog Devices Wiki]

    Hope this helps.

    Regards,

    JC

  •   

    Thanks for replying.


    As I am first time using Analog Device chipset I am requesting further information to use mentioned driver to work with this ADC 

    so based on above links to work with ADC4116 I need to use this API:   Am I correct?

    https://github.com/analogdevicesinc/no-OS/blob/main/drivers/adc/ad717x/ad717x.h


    Sample code provided in this link:
    wiki.analog.com/.../ad717x


    1.  This code initialize ADC:

    -> here I can see its mostly setting up SPI parameters as well as default ad717x_init_param which I have to configure before calling this API to setup sampling rate, filter, input type, reference volatge and all other configuration to work with ADC

    /* Create a new driver instance */
    ad717x_device *my_ad7176_2;
    ad717x_init_param ad7176_2_init;
     
    ad7176_2_init.spi_init.chip_select = 0x01;
    ad7176_2_init.spi_init.id = 0;
    ad7176_2_init.spi_init.max_speed_hz = 1000000;
    ad7176_2_init.spi_init.mode = SPI_MODE_3;
    ad7176_2_init.spi_init.type = GENERIC_SPI;
    ad7176_2_init.regs = ad7176_2_regs;
    ad7176_2_init.num_regs = sizeof(ad7176_2_regs) / sizeof(ad7176_2_regs[0]);
     
    /* Other variables */
    long timeout = 1000;
    long ret;
    long sample;
    .
    .
    .
    /* Initialize the driver instance and let's use the ad7176_2_regs array defined in ad7176_2_regs.h */
    ret = AD717X_Init(&my_ad7176_2, ad7176_2_init);
    
    


    2.  Below API is showing usage of getting sample values from ADC 
    -> wait for sample is ready

    /* wait for data to be available from the ADC */
    AD717X_WaitForReady(my_ad7176_2, timeout);

    -> read sample values once is available

    /* read once data is available */
    AD717X_ReadData(my_ad7176_2, &sample);




    Questions:
    1. from ad717x driver code I can see it internally using  no_os_spi API for SPI communication so will it internally manages to use STM32 SPI_HAL interface for SPI communication or I have to do some configuration as I am not using any OS in my case developing firmware without any OS setting up SPI Master device using STM32 CubeMX which generates auto code to setup SPI master device.


    2. Do I have to configure this driver code that  I am using ADC device type: ad717x_device_type  = ID_AD4116 if so how as not able to find reference for this usage ?

    3. To get single ADC raw value from specific channel in single mode need to use this API: ad717x_single_read , Am I correct ?
    If I have not setup any filter, sampling profile what is default filter, sampling rate will it use ?


    4. How to configure single ended input,  sampling rate, higher resolution for individual channel to get accurate voltage reading sense by ADC input pin ?


    5. I am not using VREF+, VREF- pin for external references I have connected these pins to ground. AVDD connected to 5V, AVSS connected to ground
    -> then which reference Enum to use ? How to determine whether to use INTERNAL_REF (2.5 v) OR AVDD(5v) ?

    enum ad717x_reference_source {
    EXTERNAL_REF = 0x0, /* External Reference REF+/-*/
    INTERNAL_REF = 0x2, /* Internal 2.5V Reference */
    AVDD_AVSS = 0x3 /* AVDD - AVSS */
    };


    6. What is Min and Max SPI speed this ADC support ?

  • Hi  ,

    I will ask someone knowledgeable on the driver to help you in your queries.

    For item 4:

    It is best to short all ground of your voltage input to the ADC ground when configuring single ended input. 

    In terms of the output data rate, the AD4116 has a flexible digital filter which allows you to trade-off between speed and noise performance. This would really depend on the required speed of your application. In general, a lower output data rate provides better noise performance. You may refer to Table 7-10. 

    For item 5:

    I would recommend using a stable voltage reference as it would directly affect the ADC conversion. The AD4116 includes an internal reference with ±0.12% accuracy at 25°C that can be enabled by setting the REF_EN bit to 1 in the ADC Mode Register. You can select this if you are already okay with its accuracy and gives the benefit of a reduced board size and BOM cost as no external voltage reference is needed. Otherwise you could select a voltage reference with better accuracy.

    One thing to note is that the Full-Scale Range of the ADC is dependent on the and affects the resolution.

    For item 6:

    The datasheet provides this specification. 

    Regards,

    JC

  • Hi  ,

    Thank you for your questions. 

    Please find my answers below:

    1) You would have to configure the parameters for the platform_ops specific to stm32 platform. Doing this would route all the no_os_spi function calls to the STM32 HAL APIs

    2) Please find the example code for the AD717x/AD411x application here. This should give you an idea on how to configure the ADC parameters using the AD717x driver. The Active device needs to be configured manually to AD4116, in order to apply the configurations wrt that. Please note that this example is based on mbed platform.

    3) You are right. The ad717x_single_read() would do a single sample read via the SPI lines.

    BR,

    Jan