0.1.4 AD56X8

This commit is contained in:
Rob Tillaart 2023-09-21 11:49:22 +02:00
parent e727b7674e
commit f7fa184791
7 changed files with 90 additions and 38 deletions

View File

@ -1,7 +1,7 @@
//
// FILE: AD56X8.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.3
// VERSION: 0.1.4
// DATE: 2022-07-28
// PURPOSE: Arduino library for AD56X8, SPI 8 channel Digital Analog Convertor.
@ -92,6 +92,23 @@ uint8_t AD56X8::getType()
}
void AD56X8::setLDACPin(uint8_t ldac)
{
_ldac = ldac;
pinMode(_ldac, OUTPUT);
digitalWrite(_ldac, HIGH);
}
bool AD56X8::triggerLDAC()
{
if (_ldac == 255) return false;
digitalWrite(_ldac, LOW);
digitalWrite(_ldac, HIGH);
return true;
}
// value = 0..65535 (16 bit), 16383 (14 bit), 4095 (12 bit) depending on type)
bool AD56X8::setValue(uint8_t channel, uint16_t value)
{
@ -126,7 +143,7 @@ bool AD56X8::setPercentage(uint8_t channel, float percentage)
float AD56X8::getPercentage(uint8_t channel)
{
float value = getValue(channel);
if (value > 0)
if (value > 0)
{
if (_type == 16) return value * ( 1.0 / 655.35);
if (_type == 14) return value * ( 1.0 / 163.83);
@ -221,36 +238,36 @@ uint32_t AD56X8::getSPIspeed()
};
bool AD56X8::usesHWSPI()
bool AD56X8::usesHWSPI()
{
return _hwSPI;
return _hwSPI;
}
// ESP32 specific
#if defined(ESP32)
void AD56X8::selectHSPI()
void AD56X8::selectHSPI()
{
_useHSPI = true;
_useHSPI = true;
}
void AD56X8::selectVSPI()
void AD56X8::selectVSPI()
{
_useHSPI = false;
_useHSPI = false;
}
bool AD56X8::usesHSPI()
bool AD56X8::usesHSPI()
{
return _useHSPI;
return _useHSPI;
}
bool AD56X8::usesVSPI()
bool AD56X8::usesVSPI()
{
return !_useHSPI;
return !_useHSPI;
}
@ -326,9 +343,8 @@ void AD56X8::swSPI_transfer(uint8_t value)
/////////////////////////////////////////////////////////////////////////////
//
// DERIVED
// DERIVED CLASSES
//
AD5668_3::AD5668_3(uint8_t slaveSelect) : AD56X8(slaveSelect)
{
_type = 16;

View File

@ -2,7 +2,7 @@
//
// FILE: AD56X8.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.3
// VERSION: 0.1.4
// DATE: 2022-07-28
// PURPOSE: Arduino library for AD56X8, SPI 8 channel Digital Analog Convertor.
@ -10,7 +10,7 @@
#include "Arduino.h"
#include "SPI.h"
#define AD56X8_LIB_VERSION (F("0.1.3"))
#define AD56X8_LIB_VERSION (F("0.1.4"))
#define AD56X8_PWR_NORMAL 0x00
@ -35,6 +35,10 @@ public:
void begin();
uint8_t getType();
// optional hardware LDAC interface
void setLDACPin(uint8_t ldac);
bool triggerLDAC(); // return false if pin not set.
// SET DAC
// returns false if channel out of range
@ -93,6 +97,7 @@ protected:
uint8_t _dataOut = 255;
uint8_t _clock = 255;
uint8_t _select = 255;
uint8_t _ldac = 255;
uint16_t _value[8];
uint8_t _ldacMask = 0;
@ -115,7 +120,7 @@ protected:
/////////////////////////////////////////////////////////////////////////////
//
// DERIVED
// DERIVED CLASSES
//
class AD5668_3 : public AD56X8
{
@ -151,5 +156,4 @@ public:
};
// -- END OF FILE --
// -- END OF FILE --

View File

@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.1.4] - 2023-09-19
- add hardware LDAC support
- **void setLDACPin(ldac)** and **bool triggerLDAC()**
- update README.md
- minor edits
## [0.1.3] - 2023-01-18
- fix build
- add unit tests (get_setPercentage)
@ -13,7 +20,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- move code from .h to .cpp
- update README.md
## [0.1.2] - 2023-01-09
- update GitHub actions
- update license
@ -28,7 +34,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- initialize internal values\[] array.
- improve unit tests
- clean up code
- update readme.md
- update README.md
## [0.1.0] - 2022-07-28
- rework (add from DAC855x + MCP_DAC)

View File

@ -2,8 +2,11 @@
[![Arduino CI](https://github.com/RobTillaart/AD56X8/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/AD56X8/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/AD56X8/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/AD56X8/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/AD56X8/actions/workflows/jsoncheck.yml)
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/AD56X8.svg)](https://github.com/RobTillaart/AD56X8/issues)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/AD56X8/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/AD56X8.svg?maxAge=3600)](https://github.com/RobTillaart/AD56X8/releases)
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/AD56X8.svg)](https://registry.platformio.org/libraries/robtillaart/AD56X8)
# AD56X8
@ -37,18 +40,15 @@ The device allows to set the outputs directly, or prepare them and update them s
The library is usable but not functional complete yet.
At least it lacks support for:
- RESET pin,
- LDAC pin,
- VREF pin.
- other points mentioned in future section below.
## Links
## Related
This library is partly inspired by https://github.com/bobhart/AD5668-Library, kudo's to Bob!
Discussed here - https://forum.arduino.cc/t/new-library-for-the-ad5668-dac/340393
Furthermore it has the SPI part from https://github.com/RobTillaart/MCP_DAC a.o.
Some differences between this library and Bob Harts. This library
- caches the values of all channels, so they can be read back.
- has derived classes for every specific type DAC.
@ -60,6 +60,11 @@ This allows value range checking in the future. Not Implemented Yet.
- MIT license instead of GNU v3
- https://github.com/RobTillaart/AD568X (single channel 12, 14, 16 bit)
- https://github.com/RobTillaart/AD5680 (single channel 18 bit)
- https://github.com/RobTillaart/MCP_DAC (SPI interface)
## Interface
```cpp
@ -108,6 +113,18 @@ Read datasheet for details.
Returns also false if channel is out of range.
### LDAC (hardware pin)
The use of the LDAC interface is optional.
It allows a prepared value to be set in in the DAC register.
See **prepareValue()**.
If you control multiple devices the hardware LDAC allows you to
set a new value on all devices simultaneously.
- void **setLDACPin(uint8_t ldac)** set the LDAC pin.
- void **triggerLDAC()** give a pulse over the LDAC line.
#### Powermode
- **bool setPowerMode(uint8_t powerDownMode, uint8_t mask = 0x00)** powerDownMode = 0..3.
@ -206,16 +223,8 @@ Note that the library is not tested with hardware yet.
- support for RESET pin
- void **setResetPin(uint8_t pin)**
- void **triggerReset()**
- support for LDAC pin
- void **setLDACPin(uint8_t pin)**
- void **triggerLDAC()**
- support for EXTERNAL VREF
- ?
- investigate value range checking for AD5648 and AD5628
- now **setValue()** returns false if value > max,
- should value be clipped instead?
- **setPercentage()** idem.
- **bool loadLDAC()** TODO?
- how?
#### Could
@ -223,7 +232,21 @@ Note that the library is not tested with hardware yet.
- CCmode + reset implies start value for getValue(ch)
- is this implementable? costs?
#### Wont
- investigate value range checking for AD5648 and AD5628
- now **setValue()** returns false if value > max,
- should value be clipped instead?
- **setPercentage()** idem.
- user responsibility
## 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,

View File

@ -12,6 +12,9 @@ AD5668_3 KEYWORD1
begin KEYWORD2
getType KEYWORD2
setLDACPin KEYWORD2
triggerLDAC KEYWORD2
setValue KEYWORD2
getValue KEYWORD2
setPercentage KEYWORD2

View File

@ -15,9 +15,9 @@
"type": "git",
"url": "https://github.com/RobTillaart/AD56X8.git"
},
"version": "0.1.3",
"version": "0.1.4",
"license": "MIT",
"frameworks": "arduino",
"frameworks": "*",
"platforms": "*",
"headers": "AD56X8.h"
}

View File

@ -1,5 +1,5 @@
name=AD56X8
version=0.1.3
version=0.1.4
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for AD56X8, SPI 8 channel Digital Analog Convertor.