High-Precision AD HAT

From Waveshare Wiki
Jump to: navigation, search
High-Precision AD HAT
High-Precision-AD-HAT-1.jpg

Raspberry Pi AD Expansion
{{{name2}}}

{{{name3}}}

{{{name4}}}

{{{name5}}}

Overview

High-Precision AD HAT For Raspberry Pi, ADS1263 10-Ch 32-Bit ADC.

Specification

  • Resolution (Bits): 32
  • Input channels: 10
  • Sample rate (MAX): 38 kSPS
  • PGA Magnification (MAX): 32
  • BUS: SPI
  • Structure: Delta-Sigma
  • Input type: Differential, Single-end
  • Reference voltage: Internal, External
  • Input voltage range (MAX): 2.5V, 5V
  • Input voltage range (MIN): -2.5V, 0V

Fatures

  • Adopts ADS1263 chip, low noise, low-temperature drift, 10-ch 32-bit high precision ADC (5-ch differential input), 38.4kSPS Max sampling rate.
  • with embedded 24-bit auxiliary ADC, internal ADC test signal, IDAC, 2.5V internal reference voltage, 8 x multiplexing GPIO, PGA (32 times Max).
  • Onboard AD header input, compatible with Waveshare sensor pinout, for connecting sorts of sensor modules.
  • Onboard AD screw terminal input, allows connecting analog signal and analog power supply, general-purpose interface.
  • Onboard control header, make it easy to control the module by other hosts in addition to Raspberry Pi.
  • Three-wire RTD (resistor temperature detector) circuit, enabled by soldering 0R resistor.

Pinout

PIN Raspberry Pi(BCM) Raspberry Pi(WiringPi) Description
DRDY P17 P0 ADS1263 data output ready, low active
RESET P18 P1 ADS1263 reset input
CS P22 P3 ADS1263 chip select, low active
DIN P10 P12 SPI data input
DOUT P9 P13 SPI data output
SCK P11 P14 SPI clock
SCK P11 P14 SPI clock
DIN0 D6 P22 Digits input signal
DIN1 D13 P23 Digits input signal
DIN2 D19 P24 Digits input signal
DIN3 D26 P25 Digits input signal

Hardware Configuration

PS: If you use other controllers (i.e., use the 8Pin SMD connector to input control signals), AVDD must also be connected to the power supply (5V), otherwise the chip does not work.

Configure Single-end

This board is set to single-end mode by default. That is AVDD is connected to 5V, AVSS is connected to GND, and COM is connected to GND and set as negative end input.
You can connect the GND (or COM) and any IN pin to the target device for measuring.

Configure Differential

  • (Optional) Adapting the GND pin (or COM port) of the AD HAT for connecting to the GND pin of the target board.
  • Connect your differential signal to the differential signal input port of the AD HAT. (IN0 & IN1 or one of the differential signal input ports in the other four groups).
  • (Optional) if the signal that you want to test is so small, you can use PGA. You need to set the reference voltage as the internal ±2.5V in the demo (AVDD-AVSS is single-end and does not support PGA by default). Also, You should modify the REF value to 2.5 in the main.c file and adjust the PGA according to the actual situation.
#Modify the internal REF voltage:
#Change the define in the ADS1263_ConfigADC1() of ADS1263.c from
UBYTE REFMUX = 0x24;
#to 
UBYTE REFMUX = 0x00;
  • Use the differential mode for measuring.
#Modify line 33 of main.c (Python code also has the function of the same name)
#change 
ADS1263_SetMode(0);
#to 
ADS1263_SetMode(1);
Note: The channel number for Differential measuring should be smaller than 5. You can change it according to the actual situation.

Configure RTD

If you need to use the RTD function, please configure it as below:

  • Solder four 0ohm resistors on the "RTD 0R" pads which is on the backside.

High AD HAT RTD1.png

  • Remove the jumpers of COM-GND.

High AD HAT Jump1.png

  • Connect the positive end of the three-wire RTD module to IN7 and the less two to IN6 and IN4.

High AD HAT RTD2.png

  • Modify the codes.

Communication Protocol

SPI Protocol

The AD HAT uses an SPI interface, for more information about the protocol, you can refer to datasheet Pages 11-12.
SPI timing:
High AD HAT SPI 0.png
High AD HAT SPI.png
CS is chip select. The chip is active when the CS is low;
SCLK is the clock pin of SPI;
DIN is the data input pin, that is MOSI, master output, and slave input;
DOUT is the data output pin, that is MISO, master input, and slave output;
DRDY is the data ready output pin, when the data of ADC1 is ready to output, it is low.
SPI communication has data transfer timing, which is combined by CPHA and CPOL.

  • CPOL determines the level of the serial synchronous clock at the idle state. When CPOL = 0, the level is Low. However, CPOL has little effect on transmission.
  • CPHA determines whether data is collected at the first clock edge or at the second clock edge of the serial synchronous clock; when CPHL = 0, data is collected at the first clock edge.

There are 4 SPI communication modes. SPI0 is commonly used, in which CPHL = 0, CPOL = 0.
As you can see from the figure above, data transmission starts at the first falling edge of SCLK, and 8 bits of data are transferred in one clock cycle. Here, SPI0 is in use, and data is transferred by bits, MSB first.

C examples and Python examples are provided for quick starting.

Configure interface

Enable SPI interface

PS: If you are using a system with a Bullseye branch, you need to change "apt-get" to "apt", and the system of the Bullseye branch only supports Python3.
  • Open the terminal, and use the command to enter the configuration page.
sudo raspi-config
Choose Interfacing Options -> SPI -> Yes  to enable the SPI interface

RPI open spi.png
Reboot Raspberry Pi:

sudo reboot

Make sure that the SPI is not occupied by other devices, you can check in the middle of the /boot/config .txt.


Install Library

If you use the bookworm system, you can only use lgpio library, bcm2835 and wiringPi can't be installed and used.

BCM2835

#Open the Raspberry Pi terminal and run the following command
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.71.tar.gz
tar zxvf bcm2835-1.71.tar.gz 
cd bcm2835-1.71/
sudo ./configure && sudo make && sudo make check && sudo make install
# For more, you can refer to the official website at: http://www.airspayce.com/mikem/bcm2835/

WiringPi

#Open the Raspberry Pi terminal and run the following command
cd
sudo apt-get install wiringpi
#For Raspberry Pi systems after May 2019 (earlier than that can be executed without), an upgrade may be required:
wget https://project-downloads.drogon.net/wiringpi-latest.deb
sudo dpkg -i wiringpi-latest.deb
gpio -v
# Run gpio -v and version 2.52 will appear, if it doesn't it means there was an installation error

# Bullseye branch system using the following command:
git clone https://github.com/WiringPi/WiringPi
cd WiringPi
. /build
gpio -v
# Run gpio -v and version 2.70 will appear, if it doesn't it means there was an installation error

lgpio

#Open the Raspberry Pi terminal and run the following command
wget https://github.com/joan2937/lg/archive/master.zip
unzip master.zip
cd lg-master
sudo make install

# You can refer to the official website for more: https://github.com/gpiozero/lg

python

sudo apt-get update
sudo apt-get install ttf-wqy-zenhei
sudo apt-get install python-pip 
sudo pip install RPi.GPIO
sudo pip install spidev

Download Demo Codes

Open a terminal and run the following commands to download demo codes:

cd ~
git clone https://github.com/waveshare/High-Pricision_AD_HAT

Examples

C

  • Compile the codes:
cd ~/High-Pricision_AD_HAT_Code/c
sudo make clean
sudo make
  • In Jetson Nano:
cd ~/High-Precision_AD_HAT_Code/c
sudo make clean
sudo make JETSON
  • If you want to use other libraries, you need to modify the Makefile file.
sudo vim Makefile
Change USELIB_RPIwhich is on line 13-15
  • main file is generated after compiling, then you can run the file:
sudo ./main
  • For this demo, you can also make some modifications to achieve different functions. For the details, please refer to the following part "Function Introduction".

Python

  • Open a terminal and run the Python codes:
cd ~/High-Pricision_AD_HAT_Code/python

sudo python main.py
or
sudo python3 main.py
  • If you use the Jetson Nano, you should enable the SPI first:
sudo /opt/nvidia/jetson-io/jetson-io.py
The GPIO tools menu will pop up, select "Configure 40-pin expansion header" and press "Enter" to enter the secondary menu.
Then check spi1 and return to the upper menu, and finally select "Save and reboot to reconfigure pins" to make the device reboot configuration take effect.
  • If you fail to enable the SPI, you can refer to NVIDIA Jetson Linux Developer Guide.
  • For this demo, you can also make some modifications to achieve different functions. For the details, please refer to the following part "Function Introduction".

Function Introduction

Hardware section

The ADC of this module used is ADS1263 using the SPI communication, which needs to pay attention to those three parameters: mode (mode 1), rate (maximum 8M), data format (MSB).

  • It is mainly used to send commands and read/write registers: The commands are used to start/end ADC conversion, read/write registers, restart, etc; The registers are mainly used to write the configuration parameters, and the core of the demo is to read and write the registers.
  • The Read/Write register is a special command, which is different from an ordinary command(a single byte), it uses multi-byte(read/write register command + data to be written/received).

Software section

Because the functions of the C code and the Python code are the same, the following takes the code of ADS1263.c as an example, the corresponding function can also be found in ADS1263.py:

  • Reset function, DEV_RST_PIN is the IC reset pin, low level active. The reset operation is required before each use, and then the register configuration will be restored to the default value after reset and it needs to be reconfigured for the next use.
static void ADS1263_reset(void)
  • Data read and write functions, these are three functions: write command, write register, read register. Each SPI operation needs to pull down the DEV_CS_PIN (chip select, CS) pin, read and write registers will send 0x00 once because the command is two bytes.
static void ADS1263_WriteCmd(UBYTE Cmd)
static void ADS1263_WriteReg(UBYTE Reg, UBYTE data)
static UBYTE ADS1263_Read_data(UBYTE Reg)
  • Data check function——Sum Check function, the read data of this demo uses Sum Check, you can also configure to use CRC Check through the register.

The main principle of the Sum Check is to add the low eight bits of the data, and finally add a fixed parameter. Use the low eight bits of this final sum XOR with the check byte which is read. If the data is read correctly, it will return 0.

static UBYTE ADS1263_Checksum(UDOUBLE val, UBYTE byt)
  • Data waiting function, DEV_DRDY_PIN is the DRDY pin, which is valid when ADC1 performs data conversion and sends a low level after the data is ready.

【Note】 ADC2 is not applicable to this function.

static void ADS1263_WaitDRDY(void)
  • Chip Read function, if the return value is 1, which means the IC is ADS1263, and return 0 for ADS1262.
UBYTE ADS1263_ReadChipID(void)
  • Mode setting function, set to 1 for the differential mode, the default value is 0 for single-ended mode
void ADS1263_SetMode(UBYTE Mode)
  • ADC config function, which can set the ADC rate, PGA gain multiple, reference voltage, etc.

The information on the register you can check in the ADS1263. If you need to configure other registers, it is better to read and verify after each writing according to the routine manner.

In order to ensure data stability and reduce crosstalk between multiple channels and two ADCs, the data conversion delay used by the demo is relatively large and the conversion rate is relatively slow. But you can modify it if you need to increase the speed.

【Note】 It is not recommended to turn on PGA when using single-ended measurement for ADC1. The PGA is off by default.

void ADS1263_ConfigADC1(ADS1263_GAIN gain, ADS1263_DRATE drate)
void ADS1263_ConfigADC2(ADS1263_ADC2_GAIN gain, ADS1263_ADC2_DRATE drate)
  • Chip initialization functions, including resetting, verifying, and configuring the ADC device.
UBYTE ADS1263_init(void)
  • Select the channel function, and call this function before switching the ADC channel.
static void ADS1263_SetChannal(UBYTE Channal)
static void ADS1263_SetChannal_ADC2(UBYTE Channal)
void ADS1263_SetDiffChannal(UBYTE Channal)
void ADS1263_SetDiffChannal_ADC2(UBYTE Channal)
  • Read ADC data function, the return value of ADC1 is 32-bit data, and for ADC2 is 24-bit data.
static UDOUBLE ADS1263_Read_ADC1_Data(void)
static UDOUBLE ADS1263_Read_ADC2_Data(void)
  • Obtain the data of the specified channel, there will be different effects depending on the mode.
UDOUBLE ADS1263_GetChannalValue(UBYTE Channel)
UDOUBLE ADS1263_GetChannalValue_ADC2(UBYTE Channel)
  • Obtain the data of all channels, encapsulate it for other files to call, and get the data cyclically of a specified number of channels.

To obtain 32-bit or 24-bit raw data, and then use this data by the maximum range and then multiply it by the reference voltage, you can get the voltage data. For example, the voltage of Raspberry Pi used with the demo is 5V (measured 5.08V), so the final voltage data is: ADC[i]/0x7fffffff*REF, the same applies to the negative voltage.

void ADS1263_GetAll(UDOUBLE *ADC_Value)
void ADS1263_GetAll_ADC2(UDOUBLE *ADC_Value)
  • RTD test function, including the RTD register configuration, the data conversion, and the reading of ADC1.

To get temperature data

You need to calculate the resistance of the thermal resistance first. According to R=U/I, divide the two resistances (thermal resistance, reference resistance):

R(thermal resistance)/R(reference resistance) = U (thermal resistance) * U (reference resistance) * 2

So, RES = (ADC[0] / 0x7fffffff * 1) * 1 * 2 * 2000

Finally, the temperature can be obtained according to the thermal resistance formula, and the thermal resistance of the demo uses Pt100.

So the TEMP = (RES/100-1) / 0.00385

UDOUBLE ADS1263_RTD(ADS1263_DELAY delay, ADS1263_GAIN gain, ADS1263_DRATE drate)
  • DAC test function, used for the voltage setting, output pin setting (positive and negative polarity), open or close the DAC output.
void ADS1263_DAC(ADS1263_DAC_VOLT volt, UBYTE isPositive, UBYTE isOpen)

【Note】In the main file, you can modify the macro definition to quickly convert the required test(ADC/RTD). The REF is the reference voltage, you may need to modify it according to the actual situation for measuring accurately.

Resource

Documents

Demo codes

Datasheet

Software

FAQ

 Answer:

The sample program turns on 8-channel high-precision ADC by default. In order to ensure stability and accuracy, the program adds a delay when reading and processing data. If a higher rate is required, the delay can be commented out. The demo for optimizing the input is as follows: 30K_High-Precision_AD_HAT_Code


 Answer:
High-Precision AD HAT01.png

Check the config.txt file, confirm that the SPI is turned on, and comment out other SPI devices. After the configuration is complete, restart and run:

sudo nano /boot/config.txt

High-Precision AD HAT02.png

{{{5}}}


 Answer:
The following are some possible reasons and ways to improve them:
  • The sampling rate is too high, you can try to reduce the rate.
  • Single-ended mode is easy to be interfered with, the use of differential mode can be reduced to a certain extent.
  • Switching channels may introduce noise, reducing channel switching when measuring can improve the results to some extent.
  • The reference voltage is unstable, using a stable external reference voltage (AVDD-AVSS) can reduce noise and improve stability.

{{{5}}}


 Answer:
  • Unconnected idle channel shows 5.08V; chip internal structure reasons are a normal phenomenon.
  • The default floating voltage is 5.08V, which does not affect the use, if you do not need other channels, you can turn off the channel or connect GND.

{{{5}}}


Support



Technical Support

If you need technical support or have any feedback/review, please click the Submit Now button to submit a ticket, Our support team will check and reply to you within 1 to 2 working days. Please be patient as we make every effort to help you to resolve the issue.
Working Time: 9 AM - 6 AM GMT+8 (Monday to Friday)