mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.1 DAC8571
This commit is contained in:
parent
e906d37ad6
commit
1d3d4594fb
@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.1.1] - 2024-04-18
|
||||
- implement more powerDown modi
|
||||
- update examples
|
||||
- add percentage wrappers
|
||||
- update keywords.txt
|
||||
- update readme.md
|
||||
- minor edits
|
||||
|
||||
## [0.1.0] - 2024-04-16
|
||||
- initial version
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
// FILE: DAC8571.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2024-04-16
|
||||
// VERSION: 0.1.0
|
||||
// VERSION: 0.1.1
|
||||
// PURPOSE: Arduino library for DAC8571 I2C.
|
||||
// URL: https://github.com/RobTillaart/DAC8571
|
||||
|
||||
@ -41,7 +41,7 @@ bool DAC8571::begin(uint16_t val)
|
||||
bool DAC8571::isConnected()
|
||||
{
|
||||
_wire->beginTransmission(_address);
|
||||
_error = _wire->endTransmission(); // default == 0 == DAC8571_OK
|
||||
_error = _wire->endTransmission(); // default == 0 ==> DAC8571_OK
|
||||
return (_error == DAC8571_OK);
|
||||
}
|
||||
|
||||
@ -88,14 +88,14 @@ uint16_t DAC8571::read()
|
||||
{
|
||||
uint8_t highByte = 0;
|
||||
uint8_t lowByte = 0;
|
||||
uint8_t control = 0;
|
||||
// uint8_t control = 0; // not used.
|
||||
|
||||
uint8_t n = _wire->requestFrom(_address, uint8_t(3));
|
||||
if (n == 3)
|
||||
{
|
||||
highByte = _wire->read();
|
||||
lowByte = _wire->read();
|
||||
control = _wire->read(); // not used.
|
||||
_wire->read(); // control = _wire->read(); // not used.
|
||||
_error = DAC8571_OK;
|
||||
}
|
||||
else
|
||||
@ -103,8 +103,6 @@ uint16_t DAC8571::read()
|
||||
_error = DAC8571_I2C_ERROR;
|
||||
return 0;
|
||||
}
|
||||
// keep compiler happy.
|
||||
if (control == 0) _error = DAC8571_OK;
|
||||
_error = DAC8571_OK;
|
||||
uint16_t value = highByte * 256 + lowByte;
|
||||
return value;
|
||||
@ -142,11 +140,29 @@ bool DAC8571::write(uint16_t * arr, uint8_t length)
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//
|
||||
// MODE PART
|
||||
// PERCENTAGE WRAPPER
|
||||
//
|
||||
void DAC8571::setPercentage(float percentage)
|
||||
{
|
||||
if (percentage < 0) percentage = 0;
|
||||
else if (percentage > 100) percentage = 100;
|
||||
write(percentage * 655.35);
|
||||
}
|
||||
|
||||
|
||||
float DAC8571::getPercentage()
|
||||
{
|
||||
return read() * 0.0015259022; // === / 655.35;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//
|
||||
// WRITE MODE PART
|
||||
//
|
||||
void DAC8571::setWriteMode(uint8_t mode)
|
||||
{
|
||||
// 3 and 4 not supported.
|
||||
// broadcast modi (3,4,5) not supported.
|
||||
if (mode > DAC8571_MODE_WRITE_CACHE)
|
||||
{
|
||||
mode = DAC8571_MODE_NORMAL;
|
||||
@ -166,19 +182,38 @@ uint8_t DAC8571::getWriteMode()
|
||||
//
|
||||
// POWER DOWN PART
|
||||
//
|
||||
void DAC8571::powerDown(uint8_t pMode)
|
||||
void DAC8571::powerDown(uint8_t pdMode)
|
||||
{
|
||||
// overwrite parameter for now.
|
||||
uint16_t pdMask = 0x0000;
|
||||
// table 6, page 22.
|
||||
pMode = 0;
|
||||
switch(pdMode)
|
||||
{
|
||||
default:
|
||||
case DAC8571_PD_LOW_POWER:
|
||||
pdMask = 0x0000;
|
||||
break;
|
||||
case DAC8571_PD_FAST:
|
||||
pdMask = 0x2000;
|
||||
break;
|
||||
case DAC8571_PD_1_KOHM:
|
||||
pdMask = 0x4000;
|
||||
break;
|
||||
case DAC8571_PD_100_KOHM:
|
||||
pdMask = 0x8000;
|
||||
break;
|
||||
case DAC8571_PD_HI_Z:
|
||||
pdMask = 0xC000;
|
||||
break;
|
||||
}
|
||||
// specific power down code.
|
||||
_control = 0x11;
|
||||
write(0);
|
||||
write(pdMask);
|
||||
}
|
||||
|
||||
|
||||
void DAC8571::wakeUp(uint16_t value)
|
||||
{
|
||||
_control = 0x10;
|
||||
setWriteMode(DAC8571_MODE_NORMAL);
|
||||
write(value);
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
// FILE: DAC8571.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2024-04-16
|
||||
// VERSION: 0.1.0
|
||||
// VERSION: 0.1.1
|
||||
// PURPOSE: Arduino library for DAC8571 I2C 16 bit DAC.
|
||||
// URL: https://github.com/RobTillaart/DAC8571
|
||||
|
||||
@ -11,8 +11,7 @@
|
||||
#include "Arduino.h"
|
||||
#include "Wire.h"
|
||||
|
||||
|
||||
#define DAC8571_LIB_VERSION (F("0.1.0"))
|
||||
#define DAC8571_LIB_VERSION (F("0.1.1"))
|
||||
|
||||
// ERROR CODES
|
||||
#define DAC8571_OK 0x00
|
||||
@ -25,15 +24,26 @@
|
||||
#define DAC8571_MODE_STORE_CACHE 0x00
|
||||
#define DAC8571_MODE_NORMAL 0x01
|
||||
#define DAC8571_MODE_WRITE_CACHE 0x02
|
||||
// broadcast modes need more investigation
|
||||
#define DAC8571_MODE_BRCAST_0 0x03 // not supported.
|
||||
#define DAC8571_MODE_BRCAST_1 0x04 // not supported.
|
||||
#define DAC8571_MODE_BRCAST_2 0x05 // not supported.
|
||||
|
||||
|
||||
// VALUES
|
||||
#define DAC8571_VALUE_MIN 0x0000
|
||||
#define DAC8571_VALUE_MIDDLE 0x8000
|
||||
#define DAC8571_VALUE_MAX 0xFFFF
|
||||
// DAC VALUES (percentages)
|
||||
#define DAC8571_VALUE_00 0x0000
|
||||
#define DAC8571_VALUE_25 0x4000
|
||||
#define DAC8571_VALUE_50 0x8000
|
||||
#define DAC8571_VALUE_75 0xC000
|
||||
#define DAC8571_VALUE_100 0xFFFF
|
||||
|
||||
|
||||
// POWER DOWN MODI
|
||||
#define DAC8571_PD_LOW_POWER 0x00
|
||||
#define DAC8571_PD_FAST 0x01
|
||||
#define DAC8571_PD_1_KOHM 0x02
|
||||
#define DAC8571_PD_100_KOHM 0x03
|
||||
#define DAC8571_PD_HI_Z 0x04
|
||||
|
||||
|
||||
class DAC8571
|
||||
@ -42,29 +52,33 @@ public:
|
||||
explicit DAC8571(uint8_t address = 0x4C, TwoWire *wire = &Wire);
|
||||
|
||||
// set initial value for DAC, default 0
|
||||
bool begin(uint16_t value = 0);
|
||||
bool begin(uint16_t value = DAC8571_VALUE_00);
|
||||
bool isConnected();
|
||||
// convenience
|
||||
uint8_t getAddress();
|
||||
|
||||
// DAC
|
||||
bool write(uint16_t value = 0); // returns true on success.
|
||||
bool write(uint16_t value); // returns true on success.
|
||||
uint16_t lastWrite(); // returns last successful write from cache.
|
||||
uint16_t read(); // returns last successful write from device.
|
||||
|
||||
// length is max 6 (depends on internal I2C BUFFER; to be investigated)
|
||||
// length is max 14 (depends on internal I2C BUFFER; to be investigated)
|
||||
// to be used to do a fast pulse or ramp up.
|
||||
bool write(uint16_t * arr, uint8_t length); // returns true on success.
|
||||
|
||||
// MODE (see defines above)
|
||||
// PERCENTAGE WRAPPER
|
||||
void setPercentage(float percentage);
|
||||
float getPercentage();
|
||||
|
||||
// WRITE MODE (see defines above)
|
||||
void setWriteMode(uint8_t mode = DAC8571_MODE_NORMAL);
|
||||
uint8_t getWriteMode(); // 0..4 from last write (cached)
|
||||
|
||||
// POWER DOWN
|
||||
void powerDown(uint8_t pMode = 0); // default PD mode
|
||||
void wakeUp(uint16_t value = 0); // wake up, default with value zero.
|
||||
// POWER DOWN (see defines above)
|
||||
void powerDown(uint8_t pdMode = DAC8571_PD_LOW_POWER);
|
||||
void wakeUp(uint16_t value = DAC8571_VALUE_00);
|
||||
|
||||
// ERROR HANDLING
|
||||
// ERROR HANDLING (see defines above)
|
||||
int lastError();
|
||||
|
||||
|
||||
|
@ -13,7 +13,6 @@
|
||||
|
||||
Arduino library for DAC8571 I2C 16 bit DAC.
|
||||
|
||||
|
||||
## Description
|
||||
|
||||
**Experimental**
|
||||
@ -81,6 +80,24 @@ Tested on Arduino UNO.
|
||||
| 400000 | read() | |
|
||||
|
||||
|
||||
Test ESP32 (Kudos to Paul)
|
||||
|
||||
| Speed | write() | read() | write(array) | Notes |
|
||||
|:--------:|:---------:|:--------:|:--------------:|:--------|
|
||||
| 50000 | 800.01 | 800.04 | |
|
||||
| 100000 | 439.02 | 441.18 | 2100.01 | array == 10 elements!
|
||||
| 200000 | 239.12 | 242.41 | 1090.82 |
|
||||
| 300000 | 178.05 | 181.81 | 757.57 |
|
||||
| 400000 | 148.94 | 156.83 | 595.24 |
|
||||
| 500000 | 131.57 | 142.93 | 497.99 |
|
||||
| 600000 | 120.68 | 136.35 | 428.59 |
|
||||
| 700000 | 113.19 | 130.40 | 384.64 |
|
||||
| 800000 | 108.12 | 128.18 | 351.85 |
|
||||
| 900000 | 98.21 | 106.67 | 317.45 |
|
||||
| 1000000 | 94.11 | 94.58 | 296.88 |
|
||||
|
||||
|
||||
|
||||
#### I2C multiplexing
|
||||
|
||||
Sometimes you need to control more devices than possible with the default
|
||||
@ -132,10 +149,15 @@ Returns **true** if successful.
|
||||
|
||||
The DAC8571 has one 16 bit DAC. The output value can be set from 0..65535.
|
||||
|
||||
- **bool write(uint16_t value = 0)** writes a value 0..65535 to the DAC.
|
||||
- **bool write(uint16_t value)** writes a value 0..65535 to the DAC.
|
||||
NO default, user must explicit set value.
|
||||
- **uint16_t lastWrite()** get last value written from cache (fast).
|
||||
- **uint16_t read()** get last written value from device.
|
||||
|
||||
Percentage wrappers
|
||||
- **void setPercentage(float perc)** set 0.00 .. 100.00
|
||||
- **float getPercentage()** returns 0.0 .. 100.0
|
||||
|
||||
|
||||
#### Write modi
|
||||
|
||||
@ -159,9 +181,37 @@ Setting the mode will be applied for all writes until mode is changed.
|
||||
| other | maps onto default **DAC8571_MODE_NORMAL**.
|
||||
|
||||
|
||||
#### Write multiple values - High speed mode.
|
||||
|
||||
The maximum length depends on the internal I2C BUFFER of the board.
|
||||
For Arduino this is typical 32 bytes so it allows 14 values.
|
||||
|
||||
- **void write(uint16_t arr[n], uint8_t length)** Writes a buffer with
|
||||
max 14 values in one I2C call.
|
||||
The last value written will be remembered in **lastWrite()**.
|
||||
|
||||
|
||||
#### Power Down mode
|
||||
|
||||
To investigate: Mixes also with broadcast ==> complex API.
|
||||
|
||||
- **void powerDown(uint8_t pdMode = 0)** default low power.
|
||||
- **void wakeUp(uint16_t value = 0)** wake up, DAC value set to zero by default.
|
||||
|
||||
See table 6, page 22 datasheet for details.
|
||||
|
||||
| Power Down Mode | Meaning |
|
||||
|:-----------------------|:----------|
|
||||
| DAC8571_PD_LOW_POWER | 170 uA
|
||||
| DAC8571_PD_FAST | 250 uA
|
||||
| DAC8571_PD_1_KOHM | 200 nA, GND 1 KOhm
|
||||
| DAC8571_PD_100_KOHM | 200 nA, GND 100 KOhm
|
||||
| DAC8571_PD_HI_Z | 200 nA, open circuit, high impedance
|
||||
|
||||
|
||||
#### Broadcast mode
|
||||
|
||||
**Not supported yet**
|
||||
**Not supported**
|
||||
|
||||
Different ways possible, need to investigate API. (page 19)
|
||||
|
||||
@ -174,30 +224,10 @@ Three broadcast commands exists:
|
||||
| DAC8571_MODE_BRCAST_2 | Power down all devices
|
||||
|
||||
|
||||
#### Power Down mode
|
||||
|
||||
Different ways possible, need to investigate API. (table 6, page 22)
|
||||
Mixes also with broadcast ==> complex API.
|
||||
|
||||
Minimal interface is implemented to support default mode.
|
||||
|
||||
- **void powerDown(uint8_t pMode = 0)** default power down only for now.
|
||||
- **void wakeUp(uint16_t value = 0)** wake up, value set to zero by default.
|
||||
|
||||
|
||||
#### Write multiple values - High speed mode.
|
||||
|
||||
The maximum length depends on the internal I2C BUFFER of the board.
|
||||
For Arduino this is typical 32 bytes so it allows 14 values.
|
||||
|
||||
- **void write(uint16_t arr[n], uint8_t length)** Writes a buffer with
|
||||
max 14 values in one I2C call.
|
||||
The last value written will be remembered in **lastWrite()**.
|
||||
|
||||
|
||||
#### Error codes
|
||||
|
||||
- **int lastError()** always check this value after a read / write
|
||||
- **int lastError()** always check this value after a read() / write()
|
||||
to see if it was DAC8571_OK.
|
||||
After the call to **lastError()** the error value is reset to DAC8571_OK.
|
||||
|
||||
@ -219,7 +249,6 @@ After the call to **lastError()** the error value is reset to DAC8571_OK.
|
||||
|
||||
#### Should
|
||||
|
||||
- implement more power down modes. (table 6, page 22)
|
||||
- extend performance table
|
||||
- replace magic numbers
|
||||
|
||||
|
@ -13,6 +13,9 @@ DAC8571 dev(0x4C);
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while(!Serial);
|
||||
delay(2000);
|
||||
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("DAC8571_LIB_VERSION: ");
|
||||
Serial.println(DAC8571_LIB_VERSION);
|
||||
@ -24,7 +27,7 @@ void setup()
|
||||
dev.begin(); // implicit 0
|
||||
|
||||
Serial.print("Address: ");
|
||||
Serial.println(dev.getAddress());
|
||||
Serial.println(dev.getAddress(), HEX);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,9 @@ DAC8571 dev(0x4C);
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while(!Serial);
|
||||
delay(2000);
|
||||
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("DAC8571_LIB_VERSION: ");
|
||||
Serial.println(DAC8571_LIB_VERSION);
|
||||
@ -24,7 +27,7 @@ void setup()
|
||||
dev.begin(); // implicit 0
|
||||
|
||||
Serial.print("Address: ");
|
||||
Serial.println(dev.getAddress());
|
||||
Serial.println(dev.getAddress(), HEX);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
@ -13,18 +13,21 @@ DAC8571 dev(0x4C, &Wire1);
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while(!Serial);
|
||||
delay(2000);
|
||||
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("DAC8571_LIB_VERSION: ");
|
||||
Serial.println(DAC8571_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
Wire.begin();
|
||||
Wire.setClock(100000UL);
|
||||
Wire1.begin();
|
||||
Wire1.setClock(100000UL);
|
||||
|
||||
dev.begin(); // implicit 0
|
||||
|
||||
Serial.print("Address: ");
|
||||
Serial.println(dev.getAddress());
|
||||
Serial.println(dev.getAddress(), HEX);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,9 @@ uint16_t arr[14]; // MAX buffer (Arduino UNO)
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while(!Serial);
|
||||
delay(2000);
|
||||
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("DAC8571_LIB_VERSION: ");
|
||||
Serial.println(DAC8571_LIB_VERSION);
|
||||
@ -26,7 +29,7 @@ void setup()
|
||||
dev.begin(); // implicit 0
|
||||
|
||||
Serial.print("Address: ");
|
||||
Serial.println(dev.getAddress());
|
||||
Serial.println(dev.getAddress(), HEX);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
#include "DAC8571.h"
|
||||
|
||||
DAC8571 dev(0x48);
|
||||
DAC8571 dev(0x4E);
|
||||
|
||||
uint32_t start, stop;
|
||||
|
||||
@ -21,6 +21,9 @@ volatile uint16_t x;
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while(!Serial);
|
||||
delay(2000);
|
||||
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("DAC8571_LIB_VERSION: ");
|
||||
Serial.println(DAC8571_LIB_VERSION);
|
||||
@ -36,6 +39,10 @@ void setup()
|
||||
}
|
||||
delay(100);
|
||||
|
||||
Serial.print("Address: ");
|
||||
Serial.println(dev.getAddress(), HEX);
|
||||
Serial.println();
|
||||
|
||||
test1();
|
||||
|
||||
// to elaborate
|
||||
|
@ -0,0 +1,45 @@
|
||||
|
||||
|
||||
ESP32 performance test (indication)
|
||||
|
||||
DAC8571_LIB_VERSION: 0.1.0
|
||||
|
||||
| Wire clock | write() | read() |
|
||||
|:----------:|:-------:|:------:|
|
||||
| 50000 | 800.01 | 800.04 |
|
||||
| 100000 | 439.02 | 441.18 |
|
||||
| 150000 | 320.05 | 323.07 |
|
||||
| 200000 | 239.12 | 242.41 |
|
||||
| 250000 | 201.75 | 205.13 |
|
||||
| 300000 | 178.05 | 181.81 |
|
||||
| 350000 | 161.29 | 166.55 |
|
||||
| 400000 | 148.94 | 156.83 |
|
||||
| 450000 | 138.46 | 142.87 |
|
||||
| 500000 | 131.57 | 142.93 |
|
||||
| 550000 | 125.01 | 138.87 |
|
||||
| 600000 | 120.68 | 136.35 |
|
||||
| 650000 | 115.79 | 132.05 |
|
||||
| 700000 | 113.19 | 130.40 |
|
||||
| 750000 | 111.11 | 129.02 |
|
||||
| 800000 | 108.12 | 128.18 |
|
||||
| 850000 | 100.01 | 121.96 |
|
||||
| 900000 | 98.21 | 106.67 |
|
||||
| 950000 | 95.25 | 100.83 |
|
||||
| 1000000 | 94.11 | 94.58 |
|
||||
|
||||
|
||||
Write Array
|
||||
|
||||
100000 2100.01 210.00
|
||||
200000 1090.82 109.08
|
||||
300000 757.57 75.76
|
||||
400000 595.24 59.52
|
||||
500000 497.99 49.80
|
||||
600000 428.59 42.86
|
||||
700000 384.64 38.46
|
||||
800000 351.85 35.19
|
||||
900000 317.45 31.74
|
||||
1000000 296.88 29.69
|
||||
|
||||
done...
|
||||
|
@ -37,3 +37,15 @@ DAC8571_MODE_BRCAST_0 LITERAL1
|
||||
DAC8571_MODE_BRCAST_1 LITERAL1
|
||||
DAC8571_MODE_BRCAST_2 LITERAL1
|
||||
|
||||
DAC8571_VALUE_00 LITERAL1
|
||||
DAC8571_VALUE_25 LITERAL1
|
||||
DAC8571_VALUE_50 LITERAL1
|
||||
DAC8571_VALUE_75 LITERAL1
|
||||
DAC8571_VALUE_100 LITERAL1
|
||||
|
||||
DAC8571_PD_LOW_POWER LITERAL1
|
||||
DAC8571_PD_FAST LITERAL1
|
||||
DAC8571_PD_1_KOHM LITERAL1
|
||||
DAC8571_PD_100_KOHM LITERAL1
|
||||
DAC8571_PD_HI_Z LITERAL1
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/DAC8571.git"
|
||||
},
|
||||
"version": "0.1.0",
|
||||
"version": "0.1.1",
|
||||
"license": "MIT",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=DAC8571
|
||||
version=0.1.0
|
||||
version=0.1.1
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for DAC8571 16 bit DAC.
|
||||
|
Loading…
Reference in New Issue
Block a user