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.

ADS8681: Regarding Configuration

Part Number: ADS8681


Hello Everyone, 

I am a New user of ADS8681 ADC and Also New to this Type of ADC After Reading The Datasheet I Have some Questions Please Help me

1) I am Trying to Read the Adc value So this is +- Adc so How do the Resolution Values vary (I Read the Datasheet but I didn't Understand).

2) What is the Programming Flow for the Configure Adc For +-1.25*Vref (we are using Internal ref.) (Which Register are Required to Configure) which Command is used for set the Register like Hword or Write. and How I Create Register Values. 

3) I am Using Beagle bone Black For Interfacing Adc So I using C code, Right Now I Am Not Configuring anything So when I read through Spi it Gives me Approx 41795 Resolutions for 3.3v Input and Approx 32764 for 0v/ GND is it Correct?

4) What the Formula for Calcuate the Voltage with Resolution for +- Adc (I know the Normal one i.e.  vout= (vref/ 2^no of bits Adc) * Resolution Value) but I think it is not working with this.

I am Using the Following Code

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/spi/spidev.h>

#define SPI_DEVICE "/dev/spidev1.0"
#define SPI_MODE SPI_MODE_0
#define SPI_SPEED 100000 // 100 kHz

int spi_fd;


// Function to initialize SPI communication
int spi_init() {
spi_fd = open(SPI_DEVICE, O_RDWR);
if (spi_fd == -1) {
perror("Error opening SPI device");
return -1;
}

uint8_t mode = SPI_MODE;
if (ioctl(spi_fd, SPI_IOC_WR_MODE, &mode) == -1) {
perror("Error setting SPI mode");
close(spi_fd);
return -1;
}

uint32_t speed = SPI_SPEED;
if (ioctl(spi_fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed) == -1) {
perror("Error setting SPI speed");
close(spi_fd);
return -1;
}

return 0;
}

// Function to transmit data over SPI
void spi_transmit(uint16_t *data, size_t len) {
struct spi_ioc_transfer transfer = {
.tx_buf = (unsigned long)data,
.len = len,
};

if (ioctl(spi_fd, SPI_IOC_MESSAGE(1), &transfer) == -1) {
perror("Error transmitting SPI data");
}
}

// Function to receive data over SPI
void spi_receive(uint16_t *data, size_t len) {
struct spi_ioc_transfer transfer = {
.rx_buf = (unsigned long)data,
.len = len,
};

if (ioctl(spi_fd, SPI_IOC_MESSAGE(1), &transfer) == -1) {
perror("Error receiving SPI data");
}
}

// Function to close SPI communication
void spi_close() {
close(spi_fd);
}

int main() {
if (spi_init() == -1) {
return 1;
}


// Example data
uint16_t tx_data[] = {0x0000};
size_t len = sizeof(tx_data);

// Transmit data
spi_transmit(tx_data, len);

while(1)
{

// Receive data
uint16_t rx_data[len];
spi_receive(rx_data, len);



printf("Received data In Decimal: ");
for (size_t i = 0; i < len; ++i) {
printf("%d ", rx_data[i]);
}
printf("\n");

printf("Received data In hex: ");
for (size_t i = 0; i < len; ++i) {
printf("0x%X", rx_data[i]);
}
printf("\n");
usleep(1000000);


}
// Close SPI communication
spi_close();

return 0;
}

6) if Any one Has the C code for the ADS8681 or its Library/Driver Please Provide me.

  • Hi Atul,

    Welcome to TI E2E forum.

    1) I guess the "Resolution" you are talking is code, can you clarify your question about code "value vary"?   

    2)  There is no special programming flow. You only need to program RANGE_SEL_REG register to set the input range of the ADC. I would recommend you to check the details for the commands in the 7.5.2 section of Input Command Word and Register Write Operation on page 41 of the datasheet. The register value can be found in the RANGE_SEL_REG register on the page 53 of the datasheet, 0011b should be written into RANGE_SEL[3:0] bits for +/-1.25Vref input range. The following E2E posts should be  helpful for you to understand:

    E2E:  ADS8681: Cannot change range select register

    E2E:  ADS8681: Configuration Issues

    3) The code you got for a 3.3V input is a little higher than the expected code. The ideal code for single-ended 3.3V input is 41568 for default +/-3Vref input range. You can provide more information including your schematic and signal source and so on so I can help you identify the issue. The code for a grounded input is around 32767, see the transfer function and the table 7-4 below:

    4) As you can see the transfer function which is shown above, the middle of the code is the center of the full scale input range. LSB=FSR/2^16=2*3Vref/2^16 for +/-3Vref input range, so the voltage= (code-2^15)*LSB.

    5) We do not have an example code for this ADC, all information have been covered by the datasheet, but do let me know if you have any trouble in terms of coding or timing.

    Regards,

    Dale