ADS9324 Driver 0.1.0
API reference
Loading...
Searching...
No Matches
Classes | Namespaces | Enumerations | Functions | Variables
ads9324_types.hpp File Reference

Public types of the ADS9324 driver: errors, Result<T>, enumerations, configuration, the data frame and the pure helpers that decode it. More...

#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <span>
#include "ads9324_detail.hpp"
#include "ads9324_registers.hpp"
#include "ads9324_version.h"

Go to the source code of this file.

Classes

struct  ads9324::Result< T >
 The value of a call, or why there is none. More...
 
struct  ads9324::Result< void >
 The result of a call that returns no value. More...
 
struct  ads9324::Window
 The digital window comparator of one channel (section 7.3.12). More...
 
struct  ads9324::Input
 The configuration of one input channel. More...
 
struct  ads9324::Interface
 The data interface (GEN_CFG3, XOR_BITS_CTL, GEN_CFG4, DIG_DELAY_CFG1/2). More...
 
struct  ads9324::ChannelSelect
 Which channels the data frame carries (ANA_CFG2). More...
 
struct  ads9324::Filter
 The digital filter in the data path (DIG_FILTER, GEN_CFG5). More...
 
struct  ads9324::Alarm
 The DRDY/ALARM pin (DRDY_ALARM_SEL, GEN_CFG4). More...
 
struct  ads9324::Sampling
 CONVST timing and the ready wait (section 5.6). More...
 
struct  ads9324::Correction
 System offset and gain correction stages (GEN_CFG5 of the channel banks). More...
 
struct  ads9324::Calibration
 Calibration at start-up and the mode RunAdcCalibration() uses. More...
 
struct  ads9324::TestPattern
 A test pattern of one channel group (TP_CFG, TP_AIN). More...
 
struct  ads9324::DaisyChain
 Daisy chain settings: out of scope in this version, Validate() refuses enabled. More...
 
struct  ads9324::Supply
 Supplies in millivolts for the range checks; 0 means "not stated". More...
 
struct  ads9324::Config
 Everything EnsureInitialized() and ApplyConfig() write to the chip. More...
 
struct  ads9324::WindowFlags
 The latched digital window comparator flags, one bit per channel (bit 0 is AIN1). More...
 
class  ads9324::CheckedConfig
 A configuration proven valid when the program is built. An invalid one does not compile. More...
 
struct  ads9324::Frame
 One decoded data frame. More...
 

Namespaces

namespace  ads9324
 The ADS9324 driver: everything it declares lives here; internals in detail.
 

Enumerations

enum class  ads9324::Error : uint8_t {
  ads9324::Error::Ok = 0 , ads9324::Error::NotInitialized = 1 , ads9324::Error::InvalidArgument = 2 , ads9324::Error::Bus = 3 ,
  ads9324::Error::Timeout = 4 , ads9324::Error::DeviceIdMismatch = 5 , ads9324::Error::Crc = 6 , ads9324::Error::Busy = 7 ,
  ads9324::Error::DeviceFault = 8 , ads9324::Error::Unsupported = 9 , ads9324::Error::UnexpectedReset = 16 , ads9324::Error::VerifyFailed = 17 ,
  ads9324::Error::Refused = 18 , ads9324::Error::DataMismatch = 19
}
 Why a call failed. Every call of the driver returns one of these in its Result. More...
 
enum class  ads9324::LogLevel : uint8_t { ads9324::LogLevel::Error = 0 , ads9324::LogLevel::Warning , ads9324::LogLevel::Info , ads9324::LogLevel::Debug }
 Severity passed to the optional Log() hook. More...
 
enum class  ads9324::Verify : uint8_t { ads9324::Verify::None = 0 , ads9324::Verify::ReadBack = 1 }
 Whether a setter reads back what it wrote (costs one two-frame read per register). More...
 
enum class  ads9324::ResetKind : uint8_t { ads9324::ResetKind::Software = 0 , ads9324::ResetKind::Hardware = 1 }
 How Reset() resets the chip. More...
 
enum class  ads9324::InputType : uint8_t { ads9324::InputType::Differential = 0 , ads9324::InputType::SingleEnded = 5 , ads9324::InputType::SingleEndedOpenWireSafe = 6 }
 Input type of a channel (CM_RANGE_AINn, Table 7-1). More...
 
enum class  ads9324::InputRange : uint8_t {
  ads9324::InputRange::V5 = 0 , ads9324::InputRange::V2_5 = 2 , ads9324::InputRange::V6_25 = 3 , ads9324::InputRange::V10 = 4 ,
  ads9324::InputRange::V12_5 = 5
}
 Input range of a channel (INPUT_RANGE_AINn, Table 7-1). More...
 
enum class  ads9324::Bandwidth : uint8_t { ads9324::Bandwidth::Low = 0 , ads9324::Bandwidth::Wide = 1 }
 Analog low-pass filter of a channel (PGA_BW_SEL_AINn, Table 7-2). More...
 
enum class  ads9324::Lanes : uint8_t { ads9324::Lanes::Eight = 0 , ads9324::Lanes::Four = 1 , ads9324::Lanes::Two = 2 , ads9324::Lanes::One = 3 }
 Number of data lanes (DOUT_LANE_SEL, Table 7-11). More...
 
enum class  ads9324::WordLength : uint8_t { ads9324::WordLength::Bits16 = 0 , ads9324::WordLength::Bits24 = 2 }
 Bits per conversion result on the data interface (DOUT_LENGTH). More...
 
enum class  ads9324::DataFormat : uint8_t { ads9324::DataFormat::TwosComplement = 0 , ads9324::DataFormat::OffsetBinary = 1 }
 Coding of the conversion result (EN_OFS_BINARY). More...
 
enum class  ads9324::DriveStrength : uint8_t { ads9324::DriveStrength::Normal = 0 , ads9324::DriveStrength::Half = 1 , ads9324::DriveStrength::Double = 2 , ads9324::DriveStrength::OneAndHalf = 3 }
 Drive strength of the digital outputs (DRIVE_STRENGTH, Table 7-15). More...
 
enum class  ads9324::ReferenceSource : uint8_t { ads9324::ReferenceSource::Pin = 0 , ads9324::ReferenceSource::Internal = 1 , ads9324::ReferenceSource::External = 2 }
 Where the ADC reference comes from (Table 7-3). More...
 
enum class  ads9324::ChannelCount : uint8_t { ads9324::ChannelCount::All16 = 0 , ads9324::ChannelCount::Eight = 1 , ads9324::ChannelCount::Four = 2 , ads9324::ChannelCount::Two = 3 }
 How many channels the data frame carries (ADC_NUM_SEL, Table 7-12). More...
 
enum class  ads9324::AlarmFunction : uint8_t { ads9324::AlarmFunction::Drdy = 0 , ads9324::AlarmFunction::WindowAlert = 1 , ads9324::AlarmFunction::CalDone = 6 , ads9324::AlarmFunction::OrMasked = 8 }
 What the DRDY/ALARM pin shows (DRDY_ALRM_SEL, Table 7-10). More...
 
enum class  ads9324::AverageLength : uint8_t {
  None = 0 , X2 , X4 , X6 ,
  X8 , X10 , X12 , X16 ,
  X20 , X32 , X64 , X128
}
 Length of a block or moving average (BLK_AVG_OSR, MVG_AVG_LEN).
 
enum class  ads9324::FirFilter : uint8_t {
  ads9324::FirFilter::Fir1 = 1 , ads9324::FirFilter::Fir2 = 2 , ads9324::FirFilter::Fir3 = 3 , ads9324::FirFilter::Fir4 = 4 ,
  ads9324::FirFilter::Fir5 = 5 , ads9324::FirFilter::Fir7 = 7
}
 The FIR low-pass filters (FIR_FILT_SEL, Table 7-9). FIR6 is reserved and absent. More...
 
enum class  ads9324::FilterKind : uint8_t { ads9324::FilterKind::None = 0 , ads9324::FilterKind::BlockAverage = 1 , ads9324::FilterKind::MovingAverage = 2 , ads9324::FilterKind::Fir = 3 }
 Which one digital filter is in the data path (section 7.3.11). More...
 
enum class  ads9324::PatternKind : uint8_t { ads9324::PatternKind::Constant = 0 , ads9324::PatternKind::Ramp = 2 }
 Kind of a test pattern (TP_MODE, Table 7-14). More...
 
enum class  ads9324::ReadySource : uint8_t { ads9324::ReadySource::Time = 0 , ads9324::ReadySource::Pin = 1 }
 How WaitDataReady() learns that a result is ready. More...
 
enum class  ads9324::CalibrationMode : uint8_t { ads9324::CalibrationMode::Offset = 1 , ads9324::CalibrationMode::Gain = 2 , ads9324::CalibrationMode::OffsetAndGain = 3 }
 Which errors ADC_CAL removes (ADC_CAL_MODE). More...
 
enum class  ads9324::CalibrationTrigger : uint8_t { ads9324::CalibrationTrigger::SingleShot = 0 , ads9324::CalibrationTrigger::Continuous = 1 }
 How the CONVST clock behaves during ADC calibration (section 7.3.10). More...
 

Functions

constexpr const char * ads9324::ToString (Error error) noexcept
 The name of an error, for logs.
 
constexpr bool ads9324::IsValid (InputType v) noexcept
 Whether an input type holds a documented code.
 
constexpr bool ads9324::IsValid (InputRange v) noexcept
 Whether an input range holds a documented code.
 
constexpr bool ads9324::IsValid (WordLength v) noexcept
 Whether a word length holds a documented code (01b is reserved).
 
constexpr bool ads9324::IsValid (AlarmFunction v) noexcept
 Whether an alarm function holds a documented code.
 
constexpr bool ads9324::IsValid (FirFilter v) noexcept
 Whether a FIR filter holds a documented code (110b is reserved).
 
constexpr bool ads9324::IsValid (PatternKind v) noexcept
 Whether a test pattern kind holds a documented code (only 0 and 2 are reachable).
 
constexpr bool ads9324::IsValid (CalibrationMode v) noexcept
 Whether a calibration mode holds a documented code.
 
constexpr std::array< Input, 16 > ads9324::DefaultInputs () noexcept
 The default settings of the 16 inputs, spelled out because GCC skips nested member initialisers in inputs{}.
 
constexpr Config ads9324::ChipResetConfig () noexcept
 The chip's reset state as a Config: eight lanes on D7 to D0, everything else as Config{}.
 
constexpr Error ads9324::Validate (const Config &c) noexcept
 Check a configuration against the documented ranges and combinations, with no I/O.
 
constexpr int ads9324::GetDriverVersionMajor () noexcept
 
constexpr int ads9324::GetDriverVersionMinor () noexcept
 
constexpr int ads9324::GetDriverVersionPatch () noexcept
 
constexpr const char * ads9324::GetDriverVersion () noexcept
 
constexpr uint32_t ads9324::AverageFactor (AverageLength length) noexcept
 The averaging factor of a length code: 1, 2, 4, 6, 8, 10, 12, 16, 20, 32, 64, 128.
 
constexpr uint32_t ads9324::FirDecimation (FirFilter fir) noexcept
 The decimation of a FIR filter (Table 7-9).
 
constexpr uint32_t ads9324::ResultsPerOutput (const Filter &filter) noexcept
 Samples that make one result of the digital filter in the data path.
 
constexpr uint32_t ads9324::PulsesPerResult (const Filter &filter) noexcept
 CONVST falling edges the chip needs for one result.
 
constexpr uint32_t ads9324::OutputRateHz (const Config &config) noexcept
 Result rate of the data interface in hertz.
 
constexpr uint32_t ads9324::ConversionTimeUs (const Config &config) noexcept
 Time from the start of a conversion to a ready result, rounded up to microseconds, at least 2.
 
constexpr int16_t ads9324::OffsetCorrectionFor (int32_t expected_code, int32_t measured_code) noexcept
 The OFS value that removes a measured offset (equation 1, section 7.3.9).
 
constexpr int16_t ads9324::GainCorrectionFor (int32_t expected_code, int32_t measured_code) noexcept
 The GAN value that removes a measured gain error (equations 2 to 4, section 7.3.9).
 
constexpr int32_t ads9324::RangeMillivolts (InputRange range) noexcept
 Full-scale voltage of a range in millivolts.
 
constexpr int32_t ads9324::CodeToMicrovolts (int32_t code, InputRange range) noexcept
 Microvolts of a signed code: code x full scale / 32768, rounded half away from zero.
 
constexpr int16_t ads9324::ToSigned16 (uint16_t raw) noexcept
 Reinterpret a 16-bit wire value as a signed code (two's complement).
 
constexpr int16_t ads9324::WireToCode (uint16_t raw, DataFormat format) noexcept
 The signed code of a wire value.
 
constexpr uint16_t ads9324::DerandomizeMask (uint8_t prbs) noexcept
 The XOR mask of the randomizer (equations 7 and 8, section 7.3.14.4).
 
constexpr uint32_t ads9324::FrameChannels (const ChannelSelect &select) noexcept
 Number of channels in a frame.
 
constexpr uint8_t ads9324::FrameSlotChannel (const ChannelSelect &select, uint32_t slot) noexcept
 Which channel a slot of the frame carries (Table 7-12).
 
constexpr bool ads9324::HasDiagByte (const Interface &interface) noexcept
 Whether the frame ends with a DIAG byte: asked for, or implied by the randomizer (the datasheet shows the PRBS byte only together with the DIAG byte, assumption A14).
 
constexpr std::size_t ads9324::FrameBytes (const Interface &interface, const ChannelSelect &select) noexcept
 Bytes of one data frame (section 7.3.14).
 
constexpr bool ads9324::IsStuckFrame (std::span< const uint8_t > bytes) noexcept
 Whether a data frame could come from a stuck or floating line: every byte 0x00 or every byte 0xFF (hardware lessons, KB-CPP-116).
 

Variables

constexpr uint8_t ads9324::kAlarmSourceDrdy = 0x01
 Sources of the OR output; bit n of Alarm::sources is the source with code n.
 
constexpr uint8_t ads9324::kAlarmSourceWindow = 0x02
 Source code 1, window alert.
 
constexpr uint8_t ads9324::kAlarmSourceCalDone = 0x40
 Source code 6, ADC calibration done.
 
constexpr uint16_t ads9324::kDeviceId = 0x0004
 DEVICE_ID value of every ADS9324.
 
constexpr uint32_t ads9324::kPowerUpMs = 30
 Power-up wait before the first access, tPU (section 5.7).
 
constexpr uint32_t ads9324::kResetMs = 30
 Wait after a reset before the first access (tPU, A3).
 
constexpr uint32_t ads9324::kResetPulseUs = 1000
 Shortest RESET low pulse the driver drives (a design choice, section 7.4.1).
 
constexpr uint32_t ads9324::kConvstMinHz = 100'000
 Lowest CONVST frequency, fCONVST (section 5.6).
 
constexpr uint32_t ads9324::kConvstMaxHz = 1'000'000
 Highest CONVST frequency, fCONVST.
 
constexpr uint32_t ads9324::kConvstHighMinNs = 50
 Shortest CONVST high time.
 
constexpr uint32_t ads9324::kConvstLowMinNs = 50
 Shortest CONVST low time.
 
constexpr uint32_t ads9324::kDrdyLowDelayNs = 350
 Delay from the CONVST falling edge to the DRDY falling edge.
 
constexpr uint32_t ads9324::kConversionNs = 1250
 Conversion time without oversampling, tCONV.
 
constexpr uint32_t ads9324::kSclkMaxHz = 60'000'000
 Highest SCLK frequency (section 5.6).
 
constexpr uint32_t ads9324::kSingleShotCalMs = 125
 The single-shot ADC calibration time, TWAIT (Table 7-7).
 
constexpr uint32_t ads9324::kCalMarginMs = 25
 Extra time the driver polls CALIB_BUSY after the single-shot wait.
 
constexpr uint32_t ads9324::kContinuousCalConvst = 100'000
 The free-running ADC calibration time in CONVST periods (Table 7-7).
 
constexpr uint32_t ads9324::kReadyTimeoutMaxUs = 200'000
 Longest Sampling::ready_timeout_us.
 
constexpr uint32_t ads9324::kInternalVrefMv = 4096
 Internal reference voltage in millivolts (section 5.5).
 
constexpr uint32_t ads9324::kInputResistanceOhm = 1'000'000
 Input resistance of each AINnP and AINnM pin in ohms (section 7.3.3).
 
constexpr std::size_t ads9324::kMaxFrameBytes = 50
 Longest data frame in bytes: 16 channels of 24 bits, DIAG and PRBS.
 
constexpr uint8_t ads9324::kGlitchMax = 15
 Highest DWC glitch filter count (DWC_GLITCH_FILT, 4 bits).
 
constexpr uint8_t ads9324::kDelayMaxNs = 5
 Largest output delay in nanoseconds (3 bits, section 8.1.10).
 
constexpr int32_t ads9324::kOffsetMin = -512
 OFS range in quarter LSBs (10 bits, two's complement).
 
constexpr int32_t ads9324::kOffsetMax = 511
 OFS range in quarter LSBs.
 
constexpr int32_t ads9324::kGainMin = -8192
 GAN range (14 bits, two's complement).
 
constexpr int32_t ads9324::kGainMax = 8191
 GAN range.
 
constexpr uint8_t ads9324::kDiagWindowAlert = 0x40
 DIAG bit 6, DWC_ALERT_FLAG (Table 7-13).
 
constexpr uint8_t ads9324::kDiagResetDetect = 0x01
 DIAG bit 0, RESET_DETECT_FLAG.
 

Detailed Description

Public types of the ADS9324 driver: errors, Result<T>, enumerations, configuration, the data frame and the pure helpers that decode it.

Everything here is plain data and constexpr code with no platform dependency, so tests and tools can include it without the driver template. Channels are counted from 0: channel 0 is AIN1 and channel 15 is AIN16. Voltages are integer microvolts; the driver has no floating point.