A collection of Analog Devices drivers for the mbed platform

Embed: (wiki syntax)

« Back to documentation index

AD7791 Class Reference

AD7791 Class Reference

Analog Devices AD7791 SPI 16-bit Buffered Sigma-Delta ADC. More...

#include <AD7791.h>

Public Types

enum  AD7791Register_t {
  COMMUNICATION_REG = 0, STATUS_REG = 0, MODE_REG, FILTER_REG,
  DATA_REG
}
 

AD7791 registers.

More...
enum  AD7791Channel_t { DIFFERENTIAL = 0, RESERVED, SHORT, VDDMONITOR }
 

AD7791 channel configuration.

More...
enum  ModeRegisterBits_t {
  MD1 = 0x80, MD0 = 0x40, BO = 0x08, UB = 0x04,
  BUF = 0x02
}
enum  FilterRegisterBits_t {
  CLKDIV1 = 0x40, CLKDIV0 = 0x20, FS2 = 0x04, FS1 = 0x02,
  FS0 = 0x01
}

Public Member Functions

 AD7791 (float reference_voltage, PinName CS=SPI_CS, PinName MOSI=SPI_MOSI, PinName MISO=SPI_MISO, PinName SCK=SPI_SCK)
 SPI configuration & constructor.
void frequency (int hz)
 Set AD7791 SPI frequency.
void reset (void)
 Low level SPI bus comm methods.
void set_channel (AD7791Channel_t channel)
 Register access methods.
void set_conversion_mode (AD7791Mode_t mode)
 Enables/disables continous_conversion mode In Single Conversion mode, read_u16 method will read the MODE register of the ADC, then write the Start single conversion bit and wait for the DOUT/RDY pin to go low, When the pin is driven low, data register is read back from the ADC.
uint32_t read_data_reg ()
 Reads the data register and returns its value.
uint8_t read_status_reg (void)
 Reads the status register of the ADC and returns its value.
void write_filter_reg (uint8_t regVal)
 Writes the filter register.
uint8_t read_filter_reg (void)
 Reads the filter register and returns its value.
void write_mode_reg (uint8_t regVal)
 Sets the mode register.
uint8_t read_mode_reg (void)
 Reads the mode register and returns its value.
void set_reference_voltage (float ref)
 Reference voltage methods.
float get_reference_voltage (void)
 Gets the reference voltage of the AD7790.
float read_voltage (void)
 Voltage read methods.
float data_to_voltage (uint32_t data)
 Converts an uint16_t to voltage.
uint32_t voltage_to_data (float voltage)
 Converts voltage to an uint16_t.
float read (void)
 AnalogIn API.
uint32_t read_u32 (void)
 
  • From mbed AnalogIn API -

 operator float ()
 
  • From mbed AnalogIn API - An operator shorthand for read() The float() operator can be used as a shorthand for read() to simplify common code sequences


Detailed Description

Analog Devices AD7791 SPI 16-bit Buffered Sigma-Delta ADC.

Definition at line 63 of file AD7791.h.


Member Enumeration Documentation

AD7791 channel configuration.

Enumerator:
DIFFERENTIAL 

AIN(+)-AIN(-)

RESERVED 

reserved

SHORT 

AIN(-)-AIN(-)

VDDMONITOR 

Monitor VDD.

Definition at line 76 of file AD7791.h.

AD7791 registers.

Enumerator:
COMMUNICATION_REG 

Communication register.

STATUS_REG 

Status register.

MODE_REG 

Mode register.

FILTER_REG 

Filter Register.

DATA_REG 

Data register.

Definition at line 67 of file AD7791.h.

Enumerator:
CLKDIV1 

Clock divider bit 1.

CLKDIV0 

Clock divider bit 0.

FS2 

Update rate bit 2.

FS1 

Update rate bit 1.

FS0 

Update rate bit 0.

Definition at line 99 of file AD7791.h.

Enumerator:
MD1 

Mode Select Bit 1.

MD0 

Mode Select Bit 0.

BO 

Burnout Current Enable bit.

UB 

Unipolar/Bipolar bit.

BUF 

Buffered mode bit.

Definition at line 89 of file AD7791.h.


Constructor & Destructor Documentation

AD7791 ( float  reference_voltage,
PinName  CS = SPI_CS,
PinName  MOSI = SPI_MOSI,
PinName  MISO = SPI_MISO,
PinName  SCK = SPI_SCK 
)

SPI configuration & constructor.

AD7791 constructor, sets CS pin and SPI format.

Parameters:
reference_voltage- the reference voltage to be used in computation
CS- (optional)chip select of the AD7791
MOSI- (optional)pin of the SPI interface
MISO- (optional)pin of the SPI interface
SCK- (optional)pin of the SPI interface

Definition at line 60 of file AD7791.cpp.


Member Function Documentation

float data_to_voltage ( uint32_t  data )

Converts an uint16_t to voltage.

Gain needs to be correctly set using set_gain in order to get accurate results

Parameters:
datain uint16_t format
Returns:
float value of voltage (in V)

Definition at line 340 of file AD7791.cpp.

void frequency ( int  hz )

Set AD7791 SPI frequency.

Parameters:
hz- SPI bus frequency in hz
Returns:
none

Definition at line 78 of file AD7791.cpp.

float get_reference_voltage ( void   )

Gets the reference voltage of the AD7790.

Returns:
reference voltage

Definition at line 319 of file AD7791.cpp.

operator float (  )

  • From mbed AnalogIn API - An operator shorthand for read() The float() operator can be used as a shorthand for read() to simplify common code sequences

Definition at line 387 of file AD7791.cpp.

float read ( void   )

AnalogIn API.

  • From mbed AnalogIn API - Read the input voltage, represented as a float in the range [0.0, 1.0] - uses the read_u16 method
Returns:
A floating-point value representing the current input voltage, measured as a percentage returns 1.0 along with a debug message if the conversion failed

Definition at line 371 of file AD7791.cpp.

uint32_t read_data_reg (  )

Reads the data register and returns its value.

Returns:
value of the data register

Definition at line 151 of file AD7791.cpp.

uint8_t read_filter_reg ( void   )

Reads the filter register and returns its value.

Returns:
the value of the filter register

Definition at line 142 of file AD7791.cpp.

uint8_t read_mode_reg ( void   )

Reads the mode register and returns its value.

Returns:
value of the mode register

Definition at line 124 of file AD7791.cpp.

uint8_t read_status_reg ( void   )

Reads the status register of the ADC and returns its value.

Returns:
value of the status reg

Definition at line 168 of file AD7791.cpp.

uint32_t read_u32 ( void   )

  • From mbed AnalogIn API -

Read the input voltage, represented as an unsigned short in the range [0x0, 0xFFFF] Depending on the conversion mode, this method will have different behavior. Conversion mode is set using set_continous_conversion_mode(bool).

In Single Conversion mode, read_u16 method will read the MODE register of the ADC, then write the Start single conversion bit and wait for the DOUT/RDY pin to go low, When the pin is driven low, data register is read back from the ADC.

In Continous conversion mode, read_u16 method will poll the DOUT/RDY pin, if it is low, the data register is read back from the ADC.

Returns:
16-bit unsigned short representing the current input voltage, normalised to a 16-bit value returns -1 (0xFFFF) along with a debug message if conversion failed.

Definition at line 211 of file AD7791.cpp.

float read_voltage ( void   )

Voltage read methods.

Reads the data register of the ADC and converts the result to volts Gain needs to be correctly set using set_gain in order to get accurate results.

Returns:
voltage of the ADC input

Definition at line 329 of file AD7791.cpp.

void reset ( void   )

Low level SPI bus comm methods.

Resets the AD7791.

Returns:
none

Definition at line 87 of file AD7791.cpp.

void set_channel ( AD7791Channel_t  channel )

Register access methods.

Sets the conversion channel.

Parameters:
channel

Definition at line 360 of file AD7791.cpp.

void set_conversion_mode ( AD7791Mode_t  mode )

Enables/disables continous_conversion mode In Single Conversion mode, read_u16 method will read the MODE register of the ADC, then write the Start single conversion bit and wait for the DOUT/RDY pin to go low, When the pin is driven low, data register is read back from the ADC.

In Continous conversion mode, read_u16 method will poll the DOUT/RDY pin, if it is low, the data register is read back from the ADC.

Parameters:
modetrue - continous conversion mode enabled false - single conversion mode enabled

Definition at line 187 of file AD7791.cpp.

void set_reference_voltage ( float  ref )

Reference voltage methods.

Sets the reference voltage of the AD7790.

Parameters:
refreference voltage to be set

Definition at line 310 of file AD7791.cpp.

uint32_t voltage_to_data ( float  voltage )

Converts voltage to an uint16_t.

Gain needs to be correctly set using set_gain in order to get accurate results

Parameters:
voltageto be converted
Returns:
data in uint16_t format

Definition at line 351 of file AD7791.cpp.

void write_filter_reg ( uint8_t  reg_val )

Writes the filter register.

Parameters:
regValuevalue to be written.

Definition at line 133 of file AD7791.cpp.

void write_mode_reg ( uint8_t  reg_val )

Sets the mode register.

Also sets continous mode and range based on the value written in reg_val

Parameters:
reg_val

Definition at line 106 of file AD7791.cpp.