0.1.1 AD5680

This commit is contained in:
Rob Tillaart 2023-09-24 20:15:57 +02:00
parent d6a25f1b67
commit 164c9927ba
9 changed files with 144 additions and 21 deletions

View File

@ -1,7 +1,7 @@
//
// FILE: AD5680.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// VERSION: 0.1.1
// DATE: 2023-09-19
// PURPOSE: Arduino library for AD5680 Digital Analog Convertor (18 bit).
@ -34,7 +34,7 @@ void AD5680::begin()
pinMode(_select, OUTPUT);
digitalWrite(_select, HIGH);
_spi_settings = SPISettings(_SPIspeed, MSBFIRST, SPI_MODE1);
_spi_settings = SPISettings(_SPIspeed, MSBFIRST, SPI_MODE0);
if(_hwSPI)
{
@ -117,14 +117,14 @@ float AD5680::getPercentage()
void AD5680::setSPIspeed(uint32_t speed)
{
_SPIspeed = speed;
_spi_settings = SPISettings(_SPIspeed, MSBFIRST, SPI_MODE1);
_spi_settings = SPISettings(_SPIspeed, MSBFIRST, SPI_MODE0);
};
uint32_t AD5680::getSPIspeed()
{
return _SPIspeed;
};
}
bool AD5680::usesHWSPI()
@ -184,7 +184,7 @@ void AD5680::updateDevice(uint32_t value)
{
uint8_t a = (value >> 14) & 0x0F; // bit 14-17
uint8_t b = (value >> 6) & 0xFF; // bit 06-13
uint8_t c = (value << 2) & 0xF0; // bit 00-05
uint8_t c = (value << 2) & 0xFC; // bit 00-05
digitalWrite(_select, LOW);
if (_hwSPI)

View File

@ -2,7 +2,7 @@
//
// FILE: AD5680.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// VERSION: 0.1.1
// DATE: 2023-09-19
// PURPOSE: Arduino library for AD5680 Digital Analog Convertor (18 bit).
@ -10,7 +10,7 @@
#include "Arduino.h"
#include "SPI.h"
#define AD5680_LIB_VERSION (F("0.1.0"))
#define AD5680_LIB_VERSION (F("0.1.1"))
class AD5680
{

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.1] - 2023-09-22
- fix SPI_MODE to SPI_MODE0 for hardware SPI.
- fix **updateDevice()**
- add **AD5680_triangle.ino** example
- add **AD5680_sawtooth.ino** example
## [0.1.0] - 2023-09-19
- initial version

View File

@ -55,8 +55,8 @@ Sets internal values to zero.
- **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 OR prepared value.
At power up the DAC's will be reset to 0 Volt.
- **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.
@ -85,10 +85,30 @@ BEFORE the **begin()** function.
- **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 shows that on a ESP32 SW-SPI is equally fast as
HW-SPI and in fact a bit more stable.
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.
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
@ -99,12 +119,9 @@ The HW-SPI has some overhead SW-SPI hasn't.
- get test hardware
- test the library
#### Should
- add examples
- performance
#### Could
@ -121,5 +138,3 @@ donate through PayPal or GitHub sponsors.
Thank you,

View File

@ -18,6 +18,8 @@ void setup()
Serial.print("AD5680_LIB_VERSION: ");
Serial.println(AD5680_LIB_VERSION);
// AD16_HW.selectVSPI();
AD16_HW.begin();
AD16_SW.begin();
@ -25,6 +27,7 @@ void setup()
Serial.println(AD16_HW.usesHWSPI());
Serial.print("HWSPI: ");
Serial.println(AD16_SW.usesHWSPI());
delay(100);
}
@ -36,8 +39,10 @@ void loop()
AD16_HW.setValue(i);
// AD16_SW.setValue(i);
}
uint32_t stop = micros();
Serial.println(stop - start);
uint32_t duration = micros() - start;
Serial.print(duration);
Serial.print("\t");
Serial.println(1e9 / duration);
delay(1000);
}

View File

@ -0,0 +1,45 @@
//
// FILE: AD5680_sawtooth.ino
// AUTHOR: Rob Tillaart
// PUPROSE: test basic behaviour and performance
#include "AD5680.h"
AD5680 AD16_HW(8);
AD5680 AD16_SW(9, 10, 11);
float frequency = 50;
float amplitude = 262144; // 18 bits
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println(__FILE__);
Serial.print("AD5680_LIB_VERSION: ");
Serial.println(AD5680_LIB_VERSION);
AD16_HW.begin();
AD16_SW.begin();
Serial.print("HWSPI: ");
Serial.println(AD16_HW.usesHWSPI());
Serial.print("HWSPI: ");
Serial.println(AD16_SW.usesHWSPI());
}
void loop()
{
float period = 1000000.0 / frequency;
float value = fmod(micros(), period); // 0..period
// value = period - value; // reverse
value = amplitude * value / period;
AD16_HW.setValue(value);
Serial.println(value);
}
// -- END OF FILE --

View File

@ -0,0 +1,51 @@
//
// FILE: AD5680_triangle.ino
// AUTHOR: Rob Tillaart
// PUPROSE: test basic behaviour and performance
#include "AD5680.h"
AD5680 AD16_HW(8);
AD5680 AD16_SW(9, 10, 11);
float frequency = 1.0;
float amplitude = 262144; // 18 bits
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println(__FILE__);
Serial.print("AD5680_LIB_VERSION: ");
Serial.println(AD5680_LIB_VERSION);
AD16_HW.begin();
AD16_SW.begin();
Serial.print("HWSPI: ");
Serial.println(AD16_HW.usesHWSPI());
Serial.print("HWSPI: ");
Serial.println(AD16_SW.usesHWSPI());
}
void loop()
{
float period = 1000000.0 / frequency;
float value = 2 * fmod(micros(), period); // 0..period
if (value < period)
{
value = amplitude * value / period;
}
else
{
value -= period;
value = amplitude * (1 - value / period);
}
AD16_HW.setValue(value);
Serial.println(value);
}
// -- END OF FILE --

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/AD5680.git"
},
"version": "0.1.0",
"version": "0.1.1",
"license": "MIT",
"frameworks": "*",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=AD5680
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 AD5680 Digital Analog Convertor (18 bit).