AD525x  0.6.0
Library for I2C communication with AD5253 and AD5254 digital potentiometers using an Arduino.
Public Member Functions | Protected Attributes | List of all members
AD525x Class Reference

#include <AD525x.h>

Inheritance diagram for AD525x:
AD5253 AD5254

Public Member Functions

 AD525x ()
 
uint8_t initialize (uint8_t AD_addr)
 
uint8_t write_RDAC (uint8_t RDAC, uint8_t value)
 
uint8_t read_RDAC (uint8_t RDAC)
 
uint8_t write_EEMEM (uint8_t reg, uint8_t value)
 
uint8_t read_EEMEM (uint8_t reg)
 
float read_tolerance (uint8_t RDAC)
 
uint8_t reset_device (void)
 
uint8_t restore_RDAC (uint8_t RDAC)
 
uint8_t restore_all_RDAC (void)
 
uint8_t store_RDAC (uint8_t RDAC)
 
uint8_t decrement_RDAC (uint8_t RDAC)
 
uint8_t increment_RDAC (uint8_t RDAC)
 
uint8_t decrement_RDAC_6dB (uint8_t RDAC)
 
uint8_t increment_RDAC_6dB (uint8_t RDAC)
 
uint8_t decrement_all_RDAC (void)
 
uint8_t increment_all_RDAC (void)
 
uint8_t decrement_all_RDAC_6dB (void)
 
uint8_t increment_all_RDAC_6dB (void)
 
virtual uint8_t get_max_val (void)
 
uint8_t get_err_code (void)
 
char * get_error_text (void)
 

Protected Attributes

uint8_t max_val
 

Detailed Description

Definition at line 14 of file AD525x.h.

Constructor & Destructor Documentation

AD525x::AD525x ( )
inline

Definition at line 17 of file AD525x.h.

Member Function Documentation

uint8_t AD525x::decrement_all_RDAC ( void  )

Decrements the current wiper value for all RDAC potentiometers by 1.

Takes the current wiper value for all RDAC potentiometers and decrements them by 1.

Returns
Returns 0 on no error, otherwise returns the error code. In addition to errors raised indirectly through a call to write_cmd(), this also raises:
  • EC_NOT_INITIALIZED: Raised if communication has not been initialized.

Definition at line 412 of file AD525x.cpp.

uint8_t AD525x::decrement_all_RDAC_6dB ( void  )

Decrements the current wiper value for all RDAC potentiometers by 6dB

Takes the current wiper value for all RDAC potentiometers and decrements them by 6dB (i.e. cuts them in half).

Returns
Returns 0 on no error, otherwise returns the error code. In addition to errors raised indirectly through a call to write_cmd(), this also raises:
  • EC_NOT_INITIALIZED: Raised if communication has not been initialized.

Definition at line 440 of file AD525x.cpp.

uint8_t AD525x::decrement_RDAC ( uint8_t  RDAC)

Decrements the current RDAC wiper value by 1.

Takes the current wiper value for the potentiometer specified by RDAC and decrements its value by 1.

Parameters
[in]RDACThe 2-bit register address of the RDAC to decrement [0-3]
Returns
Returns 0 on no error, otherwise returns the error code. In addition to errors raised indirectly through a call to write_cmd(), this also raises:
  • EC_NOT_INITIALIZED: Raised if communication has not been initialized.
  • EC_BAD_REGISTER: Raised if RDAC exceeds 3.

Definition at line 332 of file AD525x.cpp.

uint8_t AD525x::decrement_RDAC_6dB ( uint8_t  RDAC)

Decrements the current RDAC wiper value for the specified RDAC by 6dB

Takes the current RDAC wiper value for the potentiometer specified by RDAC and decrements it by 6dB (i.e. cuts it in half).

Parameters
[in]RDACThe 2-bit register address of the RDAC to decrement [0-3]
Returns
Returns 0 on no error, otherwise returns the error code. In addition to errors raised indirectly through a call to write_cmd(), this also raises:
  • EC_NOT_INITIALIZED: Raised if communication has not been initialized.
  • EC_BAD_REGISTER: Raised if RDAC exceeds 3.

Definition at line 372 of file AD525x.cpp.

uint8_t AD525x::get_err_code ( void  )

Retrieve the error code stored in a private variable.

Retrieves the error code stored in the private err_code variable. If non-zero, use AD525xGetErrorString() from AD525x_ErrorStrings.h to retrieve the human-readable error string, or see AD525x_Errors.h for details.

Returns
Returns the error code set in the current object. Non-zero value is an error.

Definition at line 518 of file AD525x.cpp.

char* AD525x::get_error_text ( void  )
uint8_t AD525x::get_max_val ( void  )
virtual

Interface function to be implemented by child classes - retrieve the maximum wiper value.

The AD5253 and AD5254 differ only in their maximum wiper value, [0, 64) for AD5253 and [0, 256) for AD5254. This function is an interface that should return the maximum wiper value when called from the child class objects. See AD5253::get_max_val() and AD5254::get_max_val();

Returns
Returns 0 on error. (Always returns an error on AD525x). As this is not implemented, it sets the error code to EC_NOT_IMPLEMENTED.

Reimplemented in AD5254, and AD5253.

Definition at line 474 of file AD525x.cpp.

uint8_t AD525x::increment_all_RDAC ( void  )

Increments the current wiper value for all RDAC potentiometers by 1.

Takes the current wiper value for all RDAC potentiometers and increments them by 1.

Returns
Returns 0 on no error, otherwise returns the error code. In addition to errors raised indirectly through a call to write_cmd(), this also raises:
  • EC_NOT_INITIALIZED: Raised if communication has not been initialized.

Definition at line 426 of file AD525x.cpp.

uint8_t AD525x::increment_all_RDAC_6dB ( void  )

Increments the current wiper value for all RDAC potentiometers by 6dB

Takes the current wiper value for all RDAC potentiometers and increments them by 6dB (i.e. doubles them).

Returns
Returns 0 on no error, otherwise returns the error code. In addition to errors raised indirectly through a call to write_cmd(), this also raises:
  • EC_NOT_INITIALIZED: Raised if communication has not been initialized.

Definition at line 455 of file AD525x.cpp.

uint8_t AD525x::increment_RDAC ( uint8_t  RDAC)

Increments the current RDAC wiper value by 1.

Takes the current wiper value for the potentiometer specified by RDAC and increments its value by 1.

Parameters
[in]RDACThe 2-bit register address of the RDAC to increment [0-3]
Returns
Returns 0 on no error, otherwise returns the error code. In addition to errors raised indirectly through a call to write_cmd(), this also raises:
  • EC_NOT_INITIALIZED: Raised if communication has not been initialized.
  • EC_BAD_REGISTER: Raised if RDAC exceeds 3.

Definition at line 352 of file AD525x.cpp.

uint8_t AD525x::increment_RDAC_6dB ( uint8_t  RDAC)

Increments the current RDAC wiper value for the specified RDAC by 6dB

Takes the current RDAC wiper value for the potentiometer specified by RDAC and increments it by 6dB (i.e. doubles it)

Parameters
[in]RDACThe 2-bit register address of the RDAC to increment [0-3]
Returns
Returns 0 on no error, otherwise returns the error code. In addition to errors raised indirectly through a call to write_cmd(), this also raises:
  • EC_NOT_INITIALIZED: Raised if communication has not been initialized.
  • EC_BAD_REGISTER: Raised if RDAC exceeds 3.

Definition at line 392 of file AD525x.cpp.

uint8_t AD525x::initialize ( uint8_t  AD_addr)

Initialize the potentiometer - pass (AD1<<1 | AD0) to AD_addr to set the device address.

Starts I2C communications with the specified device (specified via the AD1 and AD0 pins on the device itself - high = 1, low = 0). This two-bit input parameter is used to construct the full 7-bit I2C address.

If an invalid address is specified, err_code is set to EC_BAD_DEVICE_ADDR. This can be queried via get_err_code().

Parameters
[in]AD_addrThe two bit user-specified address of the device with which you are communicating. Should be (AD1<<1 | AD0).
Returns
Returns 0 on no error or the error code on error.

Definition at line 9 of file AD525x.cpp.

uint8_t AD525x::read_EEMEM ( uint8_t  reg)

Read EEMEM value from register.

Reads the value stored in the EEMEM value with the specified register address (reg). There are 16 EEMEM registers, and the first 4 are reserved for storing RDAC values, in the sense that certain commands (e.g. CMD_RESTORE_RDAC) push/pull the values to/from these registers.

On error, this sets the error code and returns 0. Since 0 is a valid wiper value, check get_err_code() if this returns 0. This raises I2C errors indirectly from a call to read_data_byte(), and raises EC_BAD_REGISTER if an invalid register is passed to reg.

Parameters
[in]regThe EEMEM register whose value you want to query [0-15].
Returns
Returns the value stored in the specified register or 0 on error. Check get_err_code() if return value is 0 to determine if an error has occurred. This raises I2C errors via a call to read_data_byte(), and also raises the following errors directly:
  • EC_NOT_INITIALIZED: Raised of the potentiometer object is not initialized.
  • EC_BAD_REGISTER: An invalid register address was provided.

Definition at line 155 of file AD525x.cpp.

uint8_t AD525x::read_RDAC ( uint8_t  RDAC)

Read the wiper setting from the specified RDAC register.

Reads the current wiper setting of the RDAC register specified by RDAC. On error, this sets error code and returns 0. Because 0 is a valid wiper setting, always check the error code via get_error_code() before trusting a 0 return value for this function. In addition to I2C errors raised by read_data_byte(), this function also raises EC_BAD_REGISTER if the supplied RDAC register exceeds the maximum value (3).

Parameters
[in]RDACThe address of one of the 4 RDAC registers (0-3), representing the 4 potentiometers in the IC.
Returns
Returns the wiper value or 0 on error (0 is also a valid wiper value). I2C errors are raised indirectly via a call to read_data_byte(). This function also raises the following error codes:
  • EC_NOT_INITIALIZED: Raised of the potentiometer object is not initialized.
  • EC_BAD_REGISTER: Raised if the supplied RDAC register exceeds the maximum value (3).

Definition at line 78 of file AD525x.cpp.

float AD525x::read_tolerance ( uint8_t  RDAC)

Reads the RAB tolerance, written at the factory, in percentage (signed float).

Reads the RAB tolerance programmed into the device at the factory for the specified RDAC (RDAC), returning the percent tolerance as a signed float. These values will vary from device to device and register to register.

This returns 0.0 on error, but since 0.0 is a valid output, in the event of a 0.0 return value, check get_err_code() to determine if an error has occurred. This raises I2C errors indirectly via calls to read_data_byte(), and raises EC_BAD_REGISTER if the provided RDAC value exceeds the maximum (3).

Parameters
[in]RDACThe RDAC register whose tolerance you would like to query.
Returns
Returns the RAB tolerance set at the factory and stored in read-only memory on the chip, represented as a signed float as a percentage of the total device resistance. On error, returns 0 and sets err_code to a non-zero value. Check err_code in the event of a non-zero return value. Raises I2C errors indirectly through a call to read_data_byte() and directly raises:
  • EC_NOT_INITIALIZED Raised if the object has not been initialized.
  • EC_BAD_REGISTER Raised if an invalid register is passed to the function.

Definition at line 196 of file AD525x.cpp.

uint8_t AD525x::reset_device ( void  )

Return the device to idle state.

Returns
Returns 0 on no error, otherwise returns the error code. In addition to errors raised indirectly through a call to write_cmd(), this also raises:
  • EC_NOT_INITIALIZED: Raised if communication has not been initialized.

Definition at line 269 of file AD525x.cpp.

uint8_t AD525x::restore_all_RDAC ( void  )

Restores the wiper value for all RDAC registers from their corresponding EEMEM registers.

Returns
Returns 0 on no error, otherwise returns the error code, I2C errors are raised indirectly through a call to write_cmd(), and EC_NOT_INITIALIZED is raised if the object has not been initialized.

Definition at line 301 of file AD525x.cpp.

uint8_t AD525x::restore_RDAC ( uint8_t  RDAC)

Restore the wiper value for RDAC register RDAC from the EEMEM registers.

Restores the wiper value for the specified RDAC register from the corresponding EEMEM register.

Parameters
[in]RDACThe 2-bit register address specifying the RDAC to restore. [0-3]
Returns
Returns 0 on no error, otherwise returns the error code. In addition to errors raised indirectly through a call to write_cmd(), this also raises:
  • EC_NOT_INITIALIZED: Raised if communication has not been initialized.
  • EC_BAD_REGISTER: Raised if RDAC exceeds 3.

Definition at line 281 of file AD525x.cpp.

uint8_t AD525x::store_RDAC ( uint8_t  RDAC)

Store the current RDAC value for RDAC register RDAC in the EEMEM registers.

Stores the wiper value for the specified RDAC register in the relevant EEMEM register.

Parameters
[in]RDACThe 2-bit register address specifying the RDAC to store. [0-3]
Returns
Returns 0 on no error, otherwise returns the error code. In addition to errors raised indirectly through a call to write_cmd(), this also raises:
  • EC_NOT_INITIALIZED: Raised if communication has not been initialized.
  • EC_BAD_REGISTER: Raised if RDAC exceeds 3.

Definition at line 313 of file AD525x.cpp.

uint8_t AD525x::write_EEMEM ( uint8_t  reg,
uint8_t  value 
)

Write to the EEMEM non-volatile memory register.

Write to the EEMEM non-volatile memory register. The first 4 registers (0, 1, 2, 3) are the RDAC storage registers. The remainder can store user data. There are 16 total registers.

Parameters
regThe register to which to write the EEMEM data. The first 4 are reserved for RDAC in that certain commands (such as CMD_RESTORE_RDAC) will automatically push/pull the RDAC values to/from these registers, though setting the RDAC-reserved EEMEM registers will not immediately set the RDAC registers.
valueThe value to store in the register.
Returns
Returns 0 on no error. Raises I2C errors indirectly via a call to write_data. Also raises:
  • EC_NOT_INITIALIZED: Raised of the potentiometer object is not initialized.
  • EC_BAD_WIPER_SETTING: Register selected is an RDAC register and value exceeds maximum allowed RDAC value.
  • EC_BAD_REGISTER: An invalid register address was provided.

Definition at line 117 of file AD525x.cpp.

uint8_t AD525x::write_RDAC ( uint8_t  RDAC,
uint8_t  value 
)

Write value to RDAC register specified by RDAC. RDAC registers are zero-based index.

Writes the specified value (value) to the RDAC register with RDAC address RDAC. There are four RDAC registers, addressed using 2-bits on a zero-based index.

Parameters
[in]RDACThe address of one of the 4 RDAC registers (0-3), representing the 4 potentiometers in the IC.
[in]valueThe wiper value to set the specified RDAC. This value must be in the span [0, max_val].
Returns
Returns 0 on no error, otherwise returns an error code and sets the err_code parameter (queried via get_err_code()). I2C errors are raised indirectly via a call to write_data(). This function also raises the following error codes:
  • EC_NOT_INITIALIZED: Raised of the potentiometer object is not initialized.
  • EC_BAD_REGISTER: Raised if the supplied RDAC register exceeds the maximum value (3).
  • EC_BAD_WIPER_SETTING: Raised if the wiper setting (value) eceeds the maximum value (63 for AD5253(), 255 for AD5254())

Definition at line 40 of file AD525x.cpp.

Member Data Documentation

uint8_t AD525x::max_val
protected

Definition at line 54 of file AD525x.h.


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