i2c_adc_ads7828  v2.0.2
Arduino library for TI ADS7828 I2C A/D converter.
ADS7828Channel Class Reference
Collaboration diagram for ADS7828Channel:

Public Member Functions

 ADS7828Channel (ADS7828 *const, uint8_t, uint8_t, uint16_t, uint16_t)
 
uint8_t commandByte ()
 Return command byte for channel object. More...
 
ADS7828device ()
 Return pointer to parent device object. More...
 
uint8_t id ()
 Return ID number of channel object (+IN connection). More...
 
uint8_t index ()
 Return index position within moving average array. More...
 
void newSample (uint16_t)
 Add (unscaled) sample value to moving average array, update totalizer. More...
 
void reset ()
 Reset moving average array, index, totalizer to zero. More...
 
uint16_t sample ()
 Return most-recent (unscaled) sample value from moving average array. More...
 
uint8_t start ()
 Initiate A/D conversion for channel object. More...
 
uint16_t total ()
 Return (unscaled) totalizer value for channel object. More...
 
uint8_t update ()
 Initiate A/D conversion, read data, update moving average for channel object. More...
 
uint16_t value ()
 Return moving average value for channel object. More...
 

Public Attributes

uint16_t maxScale
 Maximum value of moving average (defaults to 0x0FFF). More...
 
uint16_t minScale
 Minimum value of moving average (defaults to 0x0000). More...
 

Private Attributes

uint8_t commandByte_
 Command byte for channel object (SD C2 C1 C0 bits only).
 
ADS7828device_
 Pointer to parent device object.
 
uint8_t index_
 Index position within moving average array.
 
uint16_t samples_ [1<< 4]
 Array of (unscaled) sample values. More...
 
uint16_t total_
 (Unscaled) running total of moving average array elements.
 

Static Private Attributes

static const uint8_t MOVING_AVERAGE_BITS_ = 4
 Quantity of samples to be averaged = 2MOVING_AVERAGE_BITS_. More...
 

Detailed Description

Constructor & Destructor Documentation

§ ADS7828Channel()

ADS7828Channel::ADS7828Channel ( ADS7828 * const  device,
uint8_t  id,
uint8_t  options,
uint16_t  min,
uint16_t  max 
)
Remarks
Invoked by ADS7828 constructor; this function will not normally be called by end user.
34 {
35  this->device_ = device;
36  this->commandByte_ = (bitRead(options, 7) << 7) | (bitRead(id, 0) << 6) |
37  (bitRead(id, 2) << 5) | (bitRead(id, 1) << 4);
38  this->minScale = min;
39  this->maxScale = max;
40  reset();
41 }
void reset()
Reset moving average array, index, totalizer to zero.
Definition: i2c_adc_ads7828.cpp:149
ADS7828 * device()
Return pointer to parent device object.
Definition: i2c_adc_ads7828.cpp:71
ADS7828 * device_
Pointer to parent device object.
Definition: i2c_adc_ads7828.h:248
uint16_t minScale
Minimum value of moving average (defaults to 0x0000).
Definition: i2c_adc_ads7828.h:234
uint8_t commandByte_
Command byte for channel object (SD C2 C1 C0 bits only).
Definition: i2c_adc_ads7828.h:245
uint16_t maxScale
Maximum value of moving average (defaults to 0x0FFF).
Definition: i2c_adc_ads7828.h:222
Here is the call graph for this function:

Member Function Documentation

§ commandByte()

uint8_t ADS7828Channel::commandByte ( )

Return command byte for channel object.

Optional Function (Troubleshooting):
This function is for testing and troubleshooting.
Returns
command byte (0x00..0xFC)
Usage:
...
ADS7828 adc(0);
ADS7828Channel* temperature = adc.channel(0);
uint8_t command = temperature->commandByte();
...
56 {
57  return commandByte_ | device_->commandByte();
58 }
uint8_t commandByte()
Return command byte for device object (PD1 PD0 bits only).
Definition: i2c_adc_ads7828.cpp:400
ADS7828 * device_
Pointer to parent device object.
Definition: i2c_adc_ads7828.h:248
uint8_t commandByte_
Command byte for channel object (SD C2 C1 C0 bits only).
Definition: i2c_adc_ads7828.h:245
Here is the call graph for this function:
Here is the caller graph for this function:

§ device()

ADS7828 * ADS7828Channel::device ( )

Return pointer to parent device object.

Returns
pointer to parent ADS7828 object
Usage:
...
ADS7828 adc(0);
ADS7828Channel* temperature = adc.channel(0);
ADS7828* parentDevice = temperature->device();
...
Examples:
examples/two_devices/two_devices.ino.
72 {
73  return device_;
74 }
ADS7828 * device_
Pointer to parent device object.
Definition: i2c_adc_ads7828.h:248
Here is the caller graph for this function:

§ id()

uint8_t ADS7828Channel::id ( )

Return ID number of channel object (+IN connection).

Single-ended inputs use COM as -IN; Differential inputs are as follows:

  • 0 indicates CH0 as +IN, CH1 as -IN
  • 1 indicates CH1 as +IN, CH0 as -IN
  • 2 indicates CH2 as +IN, CH3 as -IN
  • ...
  • 7 indicates CH7 as +IN, CH6 as -IN
Returns
id (0..7)
Return values
0command byte C2 C1 C0 = 000
1command byte C2 C1 C0 = 100
2command byte C2 C1 C0 = 001
3command byte C2 C1 C0 = 101
4command byte C2 C1 C0 = 010
5command byte C2 C1 C0 = 110
6command byte C2 C1 C0 = 011
7command byte C2 C1 C0 = 111
Usage:
...
ADS7828 adc(0);
ADS7828Channel* temperature = adc.channel(0);
uint8_t channelId = temperature->id();
...
Examples:
examples/two_devices/two_devices.ino.
103 {
104  return ((bitRead(commandByte_, 5) << 2) | (bitRead(commandByte_, 4) << 1) |
105  (bitRead(commandByte_, 6)));
106 }
uint8_t commandByte_
Command byte for channel object (SD C2 C1 C0 bits only).
Definition: i2c_adc_ads7828.h:245

§ index()

uint8_t ADS7828Channel::index ( )

Return index position within moving average array.

Optional Function (Troubleshooting):
This function is for testing and troubleshooting.
Returns
index (0..2MOVING_AVERAGE_BITS_ - 1)
Usage:
...
ADS7828 adc(0);
ADS7828Channel* temperature = adc.channel(0);
uint8_t channelIndex = temperature->index();
...
121 {
122  return index_;
123 }
uint8_t index_
Index position within moving average array.
Definition: i2c_adc_ads7828.h:251

§ newSample()

void ADS7828Channel::newSample ( uint16_t  sample)

Add (unscaled) sample value to moving average array, update totalizer.

Parameters
samplesample value (0x0000..0xFFFF)
Remarks
Invoked by ADS7828::update() / ADS7828::updateAll() functions; this function will not normally be called by end user.
131 {
132  this->index_++;
133  if (index_ >= (1 << MOVING_AVERAGE_BITS_)) this->index_ = 0;
134  this->total_ -= samples_[index_];
135  this->samples_[index_] = sample;
136  this->total_ += samples_[index_];
137 }
uint16_t sample()
Return most-recent (unscaled) sample value from moving average array.
Definition: i2c_adc_ads7828.cpp:170
static const uint8_t MOVING_AVERAGE_BITS_
Quantity of samples to be averaged = 2MOVING_AVERAGE_BITS_.
Definition: i2c_adc_ads7828.h:264
uint16_t total_
(Unscaled) running total of moving average array elements.
Definition: i2c_adc_ads7828.h:258
uint16_t samples_[1<< 4]
Array of (unscaled) sample values.
Definition: i2c_adc_ads7828.h:255
uint8_t index_
Index position within moving average array.
Definition: i2c_adc_ads7828.h:251
Here is the call graph for this function:
Here is the caller graph for this function:

§ reset()

void ADS7828Channel::reset ( )

Reset moving average array, index, totalizer to zero.

Usage:
...
ADS7828 adc(0);
ADS7828Channel* temperature = adc.channel(0);
temperature->reset();
...
150 {
151  this->index_ = this->total_ = 0;
152  for (uint8_t k = 0; k < (1 << MOVING_AVERAGE_BITS_); k++)
153  {
154  this->samples_[k] = 0;
155  }
156 }
static const uint8_t MOVING_AVERAGE_BITS_
Quantity of samples to be averaged = 2MOVING_AVERAGE_BITS_.
Definition: i2c_adc_ads7828.h:264
uint16_t total_
(Unscaled) running total of moving average array elements.
Definition: i2c_adc_ads7828.h:258
uint16_t samples_[1<< 4]
Array of (unscaled) sample values.
Definition: i2c_adc_ads7828.h:255
uint8_t index_
Index position within moving average array.
Definition: i2c_adc_ads7828.h:251
Here is the caller graph for this function:

§ sample()

uint16_t ADS7828Channel::sample ( )

Return most-recent (unscaled) sample value from moving average array.

Optional Function (Troubleshooting):
This function is for testing and troubleshooting.
Returns
sample value (0x0000..0xFFFF)
Usage:
...
ADS7828 adc(0);
ADS7828Channel* temperature = adc.channel(0);
uint16_t sampleValue = temperature->sample();
...
171 {
172  return samples_[index_];
173 }
uint16_t samples_[1<< 4]
Array of (unscaled) sample values.
Definition: i2c_adc_ads7828.h:255
uint8_t index_
Index position within moving average array.
Definition: i2c_adc_ads7828.h:251
Here is the caller graph for this function:

§ start()

uint8_t ADS7828Channel::start ( )

Initiate A/D conversion for channel object.

Optional Function (Troubleshooting):
This function is for testing and troubleshooting.
Todo:
Determine whether this function is needed.
Return values
0success
1length too long for buffer
2address send, NACK received (device not on bus)
3data send, NACK received
4other twi error (lost bus arbitration, bus error, ...)
Usage:
...
ADS7828 adc(0);
ADS7828Channel* temperature = adc.channel(0);
uint8_t status = temperature->start();
...
193 {
194  return device_->start(id());
195 }
uint8_t start()
Initiate communication with device.
Definition: i2c_adc_ads7828.cpp:423
ADS7828 * device_
Pointer to parent device object.
Definition: i2c_adc_ads7828.h:248
Here is the call graph for this function:
Here is the caller graph for this function:

§ total()

uint16_t ADS7828Channel::total ( )

Return (unscaled) totalizer value for channel object.

Optional Function (Troubleshooting):
This function is for testing and troubleshooting.
Returns
totalizer value (0x0000..0xFFFF)
Usage:
...
ADS7828 adc(0);
ADS7828Channel* temperature = adc.channel(0);
uint16_t totalValue = temperature->total();
...
210 {
211  return total_;
212 }
uint16_t total_
(Unscaled) running total of moving average array elements.
Definition: i2c_adc_ads7828.h:258

§ update()

uint8_t ADS7828Channel::update ( )

Initiate A/D conversion, read data, update moving average for channel object.

Optional Function (Troubleshooting):
This function is for testing and troubleshooting.
Todo:
Determine whether this function is needed.
Return values
0success
1length too long for buffer
2address send, NACK received (device not on bus)
3data send, NACK received
4other twi error (lost bus arbitration, bus error, ...)
Usage:
...
ADS7828 adc(0);
ADS7828Channel* temperature = adc.channel(0);
uint8_t status = temperature->update();
...
232 {
233  device_->update(id());
234 }
ADS7828 * device_
Pointer to parent device object.
Definition: i2c_adc_ads7828.h:248
uint8_t update()
Update all unmasked channels on device.
Definition: i2c_adc_ads7828.cpp:469
Here is the call graph for this function:
Here is the caller graph for this function:

§ value()

uint16_t ADS7828Channel::value ( )

Return moving average value for channel object.

Required Function:
This is the most commonly-used channel function.
Returns
scaled value (0x0000..0xFFFF)
Usage:
...
ADS7828 adc(0);
ADS7828Channel* temperature = adc.channel(0);
uint16_t ambient = temperature->value();
...
Examples:
examples/one_device/one_device.ino, and examples/two_devices/two_devices.ino.
249 {
250  uint16_t r = (total_ >> MOVING_AVERAGE_BITS_);
251  return map(r, DEFAULT_MIN_SCALE, DEFAULT_MAX_SCALE, minScale, maxScale);
252 }
static const uint8_t MOVING_AVERAGE_BITS_
Quantity of samples to be averaged = 2MOVING_AVERAGE_BITS_.
Definition: i2c_adc_ads7828.h:264
uint16_t total_
(Unscaled) running total of moving average array elements.
Definition: i2c_adc_ads7828.h:258
uint16_t minScale
Minimum value of moving average (defaults to 0x0000).
Definition: i2c_adc_ads7828.h:234
uint16_t maxScale
Maximum value of moving average (defaults to 0x0FFF).
Definition: i2c_adc_ads7828.h:222

Member Data Documentation

§ maxScale

uint16_t ADS7828Channel::maxScale

Maximum value of moving average (defaults to 0x0FFF).

Usage:
...
ADS7828 device(0);
ADS7828Channel* temperature = device.channel(0);
uint16_t old = temperature->maxScale; // get current value and/or
temperature->maxScale = 100; // set new value
...
Examples:
examples/one_device/one_device.ino, and examples/two_devices/two_devices.ino.

§ minScale

uint16_t ADS7828Channel::minScale

Minimum value of moving average (defaults to 0x0000).

Usage:
...
ADS7828 device(0);
ADS7828Channel* temperature = device.channel(0);
uint16_t old = temperature->minScale; // get current value and/or
temperature->minScale = 0; // set new value
...
Examples:
examples/one_device/one_device.ino, and examples/two_devices/two_devices.ino.

§ samples_

uint16_t ADS7828Channel::samples_[1<< 4]
private

Array of (unscaled) sample values.

Note
Bit shift must match MOVING_AVERAGE_BITS_.

§ MOVING_AVERAGE_BITS_

const uint8_t ADS7828Channel::MOVING_AVERAGE_BITS_ = 4
staticprivate

Quantity of samples to be averaged = 2MOVING_AVERAGE_BITS_.

Note
MOVING_AVERAGE_BITS_ must match samples_ bit shift.

The documentation for this class was generated from the following files: