Uncategorized

ADS1256 ADC notes

2

I am using the AD/DA Hat from WaveShare https://www.waveshare.com/wiki/High-Precision_AD/DA_Board I want to realize a continuous readout of the data. It worked very well so far, but I am not so experienced with SPI (or serial communcation in gerneral) My two questions are:

1) Is it possible that any data will be lost, if for example the AD/DA Hat writes faster than the refresh rate of my program. Or will all data be saved in a buffer and I can read them afterwards?

2) If I set the sample rate to very low (e.g. 5 Hz).. I will get data from SPI like [12, 125, 85, 0, 0, 0, 0, 0, 0, 0, 0, 15, 114, 43, 0, 0, …] My readout of the ADC consits of 3 Bytes, so the rest is low. Because SPI has no start-, stop-bits I dont know how to extract the 3 bytes from the contiuous readout… For the given example I could program a logic which extract the bytes afterwards But it is not very safe because the first or last bit of my actual readout could be zero as well.

Thanks for your help my friends

 New contributor

3 Answers

7

Any answer might only be of limited help to you as long as you have not understood how SPI actually works, so you should take a detailed look at this interface.

Concerning question 1: SPI is a master-slave-system where any interaction has to be initiated by the master. The sensor itself is not able to write to the master, instead it is read by the master (raspberry pi). Therefore the sensor will not “write” more often than your loop “makes it write” by calling the corresponding SPI-read-function. The sensor might (or probably will) have done several measurements between two read-outs, but that’s usually the case. It wouldn’t be better if the sensor was slower than your program. If it turns out that this is actually the case you better make use of the data-ready-pin mentioned in RogerJones’ answer.

Question 2: Instead of using start-/stop-bits a transmission is triggered by selecting the slave (pulling its select pin low). You usually have to write the register address you want to read first, after that you can read a specific amount of bytes. As you know the address and length of the measurement data, you don’t need to parse or “extract” any bytes. You simply select the bytes you desire and will get those back right away.

5

In addition to the other answer about the SPI protocol I notice that the product page you linked to shows that, as well as the SPI CS pin on GPIO 15 (BCM22), the ADS1256 ADC has a “Data Ready” pin connected to GPIO 11 (BCM17). You could monitor this and only fetch a new sample when the data is available rather than just reading the data back constantly — you might be getting the same data repeated if there’s no new conversion between your read attempts. By using the “Data Ready” pin in this way you’d get the fastest data rate from the board (assuming you can read the data out fast enough) without missing or replicating data points. How you’d do this would depend on the programming language you’ve used but using an interrupt on pin 11 would appear to be a good start.

Looking at the provided code and datasheet it looks like you can also change the ADC sample rate so if you are having problems keeping up you can slow the chip down, the slowest sample frequency is about 50Hz giving your code 20ms to read the data.

-1

Question

How to read ADC results from ADS1256?

Short Answer

Getting to know SPI

As pointed out by @Sim Son, you need to know basic SPI and have some practical hardware/software experience, before you can understand how SPI ADS1256 programming.

Getting to know ADC

Then you need to know basics of ADC, like what is the meaning of single end and differential end channels, gain factors etc,

Getting to know ADS1256

Then you need to read the data sheet, to get a rough idea of the functions of the pinout, eg, AN-~AN7, Reset, DataReady (Note 1), Beside the SPI pins (CLK, MOSI, MISO, CS), and the functions of the 11 registers.

Getting to know the WaveShare ADS1256 Demo Program

Then you can now study the program and get a rough idea of what the program is doing its job by 3 big steps:

  1. Define Gain Channels, Data Rates, Register Addresses, ADC Commands
  2. Define ADS1256 Class with methods init, reset, writeCommand, writeReg, ReadData
  3. Define ADC1256 methods readChipId, config, setSingleEndChannel, setDiffChannel, setScanMode, init, waitReady, readData, getOneChannelValue, getAllChannelValues, …

Note 1 – As pointed out by @Roger Jones, the DataReay pin is important if you wish to get the highest sample rate. The following picture show how to roughly calculate the maximum data rate for a particular SPI frequency.

ads1256 data rate

Now I am connecting Rpi to the ADS1256 Module

ads1256_connect

ads1256 wiring

ADS1256 Test Rig

ads1256 test rig 1

Long Answer

References

ADS1256 Datasheet – TI

[ADS1256] Measuring Single-Ended 0- to 5-V Signals with Differential Delta-Sigma ADCs Application Report – TI 2015may

[ADS1256] How delta-sigma ADCs work, Part 1 – TI

How can ADS1256 Read Negative Values?

How can ADS1256 Read Full Scale Values?

ADS1256 Python Libraries

C library for Broadcom BCM 2835 [GPIO] as used in Raspberry Pi [v1.59 2012 26 pin Rpi 2]

WaveShare ADS1250 ADC Module Tutorial

WaveShare ADS1250 ADC Module Schematic

Waveshare/High-Precision-AD-DA-Board Python 3 Demo Program

AliExpress ADS1256 24 Bit ADC Modules

AliExpress ADS1256IDB ADC Module – US$30

Appendices

Appendix A – WaveShare ADS1256 ADC Module Picture

waveshare adc

Appendix B – WaveShare ADS1256 ADC Module Schematic

Waveshare adc schematic

Appendix C – ADS1256 Characteristics

ads1256 char

Appendix D – ADS1256 Overview

ads1256 overview

Appendix E – ADS1256 Connection Diagram

ads1256 connection diagram

Appendix F – Rpi3B+ ADS1256 Wiring V0.2

Rpi3B+ ADS1256 Wiring V0.2

Circuit URL

rpi ads1526 wiring

Appendix G – ADS1256 Register Map

reg map

Appendix H – Commands

commands

Appendix I – One shot mode ADC

For one short mode of standby-wakeUp-readData, the wake up delay is only 33.3 uS.

one short mode ADC

Appendix J – Write Register and Read Register

wreg

rreg

Appendix K – Status Register 0x00

status reg

/ to continue, …

  • 1
    Thanks a lot for the detailed information. I read the datasheet and tried to set up the timing correctly. But waitiing for the “data rdy poin” led to a delay of roughly 0.5 seconds. However, I realized that the delay corresponds with the sample rate which I set up. Now it seems to work fine. – markus321 20 hours ago
  • Just a quick reply. I am just starting to learn this ADC, so I have not yet read the datasheet thoroughly. My first feeling is that if your data rate is low, you DO NOT NEED to read the data ready signal which is useful for very high data rate. But I am only 60% sure. – tlfong01 19 hours ago   
  • Another quick note. ADS1256 has two conversion modes: (1) one shot, (2) continuous. A wild guess is that for both modes, the conversion time should be much much less than 1mS (if SPI frequency is 100kHz, say). Again I am only 60% sure. I need to read the datasheet carefully, and of course verify by engineering experimentation. Perhaps I can try tomorrow. – tlfong01 19 hours ago   
  • One reason you have the ridiculously long 0.5 second delay is perhaps you UNNECESSARILY set data rate to a very low value. See Appendix I of my answer. Again I am only 60% sure. I need to do engineering experimentation to verify my guess. – tlfong01 29 mins ago   

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: