This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linux/ADS7841: ADS7841Q Data conversion formula and corresponding linux driver and application

Part Number: ADS7841

Tool/software: Linux

Dear TI,

    We are working on i.MX8QXP with ADS7841Q for one of the project. We connected the ADS7841Q to one of the spi bus of the processor. Here we couldn't find the driver for ADS7841. So we configured the spidev device like below.

&lpspi3 {
        #address-cells = <1>;
        #size-cells = <0>;
        fsl,spi-num-chipselects = <1>;
        pinctrl-names = "default";
        pinctrl-0 = <&pinctrl_lpspi3 &pinctrl_lpspi3_cs>;
        cs-gpios = <&gpio0 16 GPIO_ACTIVE_LOW>;
        status = "okay";

        spidev@0x00 {
                compatible = "spidev";
                spi-max-frequency = <20000000>;
                reg = <0>;
        };
};

Using spidevtest able to send the spi packets like 0x9F, 0x00 ( 8 bit mode). But while reading from the SPI we are getting the exactly half of the CH0 voltage.

Why ADC is behaving like this.?

Calculation used here is static

void adcout_process(short int sampled_data)
{
        float volt,vref,adc_bit;
        vref = VREF_5V;
        //adc_bit = ADC_12BIT;
        adc_bit = 256; //8bit mode
//      adc_bit = 1024; //10bit mode
        printf("adcout_process::RAW data 0x%X\r\n",sampled_data);
        volt = ((vref/adc_bit)*(float)sampled_data);
        printf("Voltage : %f\r\n",volt);
}

Running command : ./spidev_test -v -b 16 -O

output : half of the voltage in the CH0

please help us to get the exact voltage. we are taking 10 samples.

If you share the linux driver and the application to use it will be a great help.

Best  Regards,

Ranjith Hebbar

  • Hello Ranjith,

    Thank you for your post.

    I'm sorry, but I cannot understand your firmware routine.

    In 12-bit Mode with Vref = 5 V, 1 LSB is equal to 5 V / 2^12 codes = 1.22 mV / code. Can you describe how you are configuring the ADC? 

    • Single-ended or differential input
    • Conversion Rate
    • Supply Voltage
    • Reference Voltage
    • Conversion Mode

    We do not have Linux drivers to distribute for this device.

    Best Regards,

  • Dear Ryan,

          We are using 8 bit mode with Vref and Vcc =5V.

    • Single ended mode    
    • Conversion rate 5khz
    • supply voltage 5v
    • Reference voltage 5v
    • Conversion mode 8 bit mode

        We need below clarifications :

        1. we configure the ADC7841 spi using the spidev driver. Right now we are configure the spi mode as 0 .i.e, CPOH = 0 and CPOL =0. Please tell us in which mode ADC will work. (SPI mode to be configured ?

        2. What is the spi-frequency it can operate ? Is SPI clock frequency and the Conversion rate one and the same?

        3. We used below commands to send over spi

             MOSI 0x9F 0x00 (since 8 bit mode single ended)

        4. Conversion formula used here is 

            static void adcout_process(short int sampled_data)
    {
            float volt,vref,adc_bit;
            vref = VREF_5V;
                 adc_bit = 256; //8bit mode
            printf("adcout_process::RAW data 0x%X\r\n",sampled_data);
            volt = ((vref/adc_bit)*(float)sampled_data);
            printf("Voltage : %f\r\n",volt);
    }    

     we are taking 10 samples and taking the average and passed to sampled_data.

    root@imx8qxpmek:~# ./spidev_test -v -O
    spi mode: 0x2
    bits per word: 8
    max speed: 500000 Hz (500 KHz)
    TX | 9F 00 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  | �.
    RX | FF 7F __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  | .
    size of tx 2
    Main: offset 0 : 0xff
    Main: offset 1 : 0x7f
    Main : x0= 0x7f
    Main : sampled_data 0x7F at sampling_count 1

     Problem here is we are getting exactly half of the voltage in Channel 0. For ex: we supposed to get 4V but we are getting 2V., changing the voltage through potentiometer to 5V we are getting 2.5V and for 3V we are getting 1.5V. Please help us to resolve this issue.

    Best Regards,

    Ranjith Hebbar V S

  • Hi Ranjith,

    Most likely, you are missing the MSB of the conversion result. The MSB will always be latched on the 10th DCLK rising edge. This would mean that you must use SPI Mode 0 (CPOL = CPHA = 0).

    I also forgot to ask, how many clocks per conversion are you sending?

    To answer your other questions, the DCLK and conversion rate are not the same. The DCLK is your only clock input to the device and used both for conversions and for serial interface. The DCLK frequency and the number of clocks per conversion (15, 16, or 24) set the conversion rate.

    For example, if you are aiming for 5 kSPS with 16 clocks per conversion, DCLK must be at least 80 kHz. The command byte will overlap with the conversion data from the previous acquisition in that case (see Figure 4).


    Best Regards,