Modular Electronics  0.1
 All Classes Namespaces Functions Variables Pages
Public Member Functions | Protected Member Functions | List of all members
AdcSpi Class Referenceabstract

#include <adc.h>

Inheritance diagram for AdcSpi:
AD7734

Public Member Functions

 AdcSpi (uint8_t sync_pin, uint8_t spi_bus_config_pin, uint8_t data_ready_pin, uint8_t bit_resolution, uint8_t reset_pin=0, uint8_t clock_divider=7, BitOrder bit_order=MSBFIRST, uint8_t spi_mode=SPI_MODE3)
 
bool Begin (void)
 
double ReadVoltage (uint8_t channel=0)
 
uint8_t ReadVoltage (uint8_t channel, byte previous_meas[], bool send)
 

Protected Member Functions

virtual double BytesToVoltage (spi_utils::Message message)=0
 
virtual spi_utils::Message SingleConversionModeMessage (uint8_t channel=0)=0
 
virtual spi_utils::Message ReadDataRegisterMessage (uint8_t channel=0)=0
 

Detailed Description

AdcSpi class

Author
Carlos Kometter
Version
0.1
Date
2018

Constructor & Destructor Documentation

AdcSpi::AdcSpi ( uint8_t  sync_pin,
uint8_t  spi_bus_config_pin,
uint8_t  data_ready_pin,
uint8_t  bit_resolution,
uint8_t  reset_pin = 0,
uint8_t  clock_divider = 7,
BitOrder  bit_order = MSBFIRST,
uint8_t  spi_mode = SPI_MODE3 
)

Constructor

Parameters
[in]sync_pinThe sync or chip select of the adc chip. Different than spi_bus_config_pin
[in]spi_bus_config_pinThe pin that identifies the bus. More than one adc can share the same pin.
[in]data_ready_pinThis pin tells whether the adc has finished measuring a voltage.
[in]bit_resolutionThe bit resolution of the adc (eg. 16 for AD7734).
[in]clock_dividerSets the spi frequency. spi_freq = clock_freq (84 MHz for arduino due) / clock_divider (default: 7)
[in]bit_orderPossible values:
  • MSBFIRST Most significant bit first. (default)
  • LSBFIRST Least significant bit first.
[in]spi_modePossible values:
  • SPI_MODE0
  • SPI_MODE1
  • SPI_MODE2
  • SPI_MODE3 (default)
[in]reset_pinThe reset pin for the dac pin. Set to 0 if not used. (default: 0)

Member Function Documentation

bool AdcSpi::Begin ( void  )

Configures pins for SPI and initializes SPI communication. This function must be called before calling any other function.

virtual double AdcSpi::BytesToVoltage ( spi_utils::Message  message)
protectedpure virtual

Uses chip specifications (e.g. bit resolution, registers, range) to convert a set of bytes stored in a Message object to voltage. Each ADC has its own convertion function. Check the datasheet of each chip and override the function below accordingly.

Parameters
[in]messageMessage object which stores the bytes for conversion.
Returns
The measured voltage.

Implemented in AD7734.

virtual spi_utils::Message AdcSpi::ReadDataRegisterMessage ( uint8_t  channel = 0)
protectedpure virtual
Parameters
[in]channelThe channel to be read.
Returns
Message object to read the data register.

Implemented in AD7734.

double AdcSpi::ReadVoltage ( uint8_t  channel = 0)

Read the voltage at one of the analog inputs of the adc.

Parameters
[in]channelThe analog input to be read. (default: 0)
Returns
The voltage at the analog input.
uint8_t AdcSpi::ReadVoltage ( uint8_t  channel,
byte  previous_meas[],
bool  send 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This function takes of the dead time the adc is converting (meausering) a new voltage. During this dead time the arduino sends the previous measurement via serial.

Parameters
[in]channelThe analog input to be read. (default: 0)
[in,out]previous_meas[]stores values of previous measurement to be sent vias spi. After the adc finishes converting the new voltage, it stores the new values.
[in]sendPossible values:
  • true Content of previous_meas[] is sent via serial while the adc is converting current voltage.
  • false Content of previous_meas[] is non sent via serial while the adc is converting current voltage.
Returns
The voltage at the analog input.
virtual spi_utils::Message AdcSpi::SingleConversionModeMessage ( uint8_t  channel = 0)
protectedpure virtual
Parameters
[in]channelThe channel to start single conversion mode on dump mode.
Returns
Message object to start single conversion mode on dump mode.

Implemented in AD7734.


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