GY-63_MS5611/libraries/AD5680/README.md
2023-09-24 20:15:57 +02:00

4.6 KiB

Arduino CI Arduino-lint JSON check GitHub issues

License: MIT GitHub release PlatformIO Registry

AD5680

Arduino library for the AD5680 series digital analog convertor (18 bit).

Description

Experimental

The AD5680 is a 18 bit DAC on paper but in fact it is a 16 bit DAC. To get the 18 bits a 2 bit duty cycle is used to implement the last two bits. This means that the output voltage will be fluctuating unless the two least significant bits are 0 (zero). To dampen this fluctuation the datasheet advises to add a LOW pass filter after the output.

Feedback, issues, improvements are welcome. Please file an issue on GitHub.

Interface

#include "AD5680.h"

Base class

  • AD5680(uint8_t slaveSelect) constructor base class, sets HW SPI. Sets internal values to zero.
  • AD5680(uint8_t spiData, uint8_t spiClock, uint8_t slaveSelect) constructor, sets SW SPI. Sets internal values to zero.
  • begin() initializes the SPI and sets internal state.

Set DAC

  • bool setValue(uint16_t value) set value to the output immediately, effectively a prepare + update in one call. Returns false if value out of range.
  • uint16_t getValue() returns set value. At power up the AD5680 will be reset to 0 (== 0 volt).
  • bool setPercentage(float percentage) idem.
  • float getPercentage() idem.

SPI

  • void setSPIspeed(uint32_t speed) sets SPI clock in Hz, please read datasheet of the ADC first to get optimal speed.
  • uint32_t getSPIspeed() gets current speed in Hz.
  • bool usesHWSPI() returns true if HW SPI is used.

SPI ESP32 specific

("inherited" from MPC_DAC library)

  • void selectHSPI() in case hardware SPI, the ESP32 has two options HSPI and VSPI.
  • void selectVSPI() see above.
  • bool usesHSPI() returns true if HSPI is used.
  • bool usesVSPI() returns true if VSPI is used.

The selectVSPI() or the selectHSPI() needs to be called BEFORE the begin() function.

(experimental)

  • void setGPIOpins(uint8_t clk, uint8_t miso, uint8_t mosi, uint8_t select) overrule GPIO pins of ESP32 for hardware SPI. Needs to be called AFTER the begin() function.

Note: earlier experiments (other device) shows that on a ESP32 SW-SPI is equally fast as HW-SPI and in fact a bit more stable. The SW pulses are a bit slower than the HW pulses and therefore more square. The HW-SPI has some overhead SW-SPI hasn't.

Performance

Measurements with AD5680_demo.ino - setValue() most important. (numbers are rounded).

| version | board | clock | SPI | samples / second | Notes | |:---------:|:-------:}:---------:|:-----:}:------------------:|:--------| | 0.1.1 | UNO | 16 MHz | HW | 53500 | | 0.1.1 | UNO | 16 MHz | SW | 2800 | | 0.1.1 | ESP32 | 240 MHz | HW | 91000 | 1 | 0.1.1 | ESP32 | 240 MHz | SW | 111000 |

  1. ESP32 HW is equal performant for HSPI and VSPI. Unknown why HW SPI is 20% slower than SW SPI (transaction overhead?)

50000 - 100000 samples per second means that a 1 KHz wave can be constructed with 50-100 values per period.

Future

Must

  • improve documentation
  • get test hardware
  • test the library

Should

  • add examples

Could

  • make a 16 bit interface?

Wont

Support

If you appreciate my libraries, you can support the development and maintenance. Improve the quality of the libraries by providing issues and Pull Requests, or donate through PayPal or GitHub sponsors.

Thank you,