mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.3.0 AD520X
This commit is contained in:
parent
13216d9f07
commit
64e9b6503b
@ -1,3 +1,18 @@
|
||||
platforms:
|
||||
rpipico:
|
||||
board: rp2040:rp2040:rpipico
|
||||
package: rp2040:rp2040
|
||||
gcc:
|
||||
features:
|
||||
defines:
|
||||
- ARDUINO_ARCH_RP2040
|
||||
warnings:
|
||||
flags:
|
||||
|
||||
packages:
|
||||
rp2040:rp2040:
|
||||
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
|
||||
|
||||
compile:
|
||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||
platforms:
|
||||
@ -7,5 +22,7 @@ compile:
|
||||
# - leonardo
|
||||
- m4
|
||||
- esp32
|
||||
# - esp8266
|
||||
# - mega2560
|
||||
- esp8266
|
||||
# - mega2560
|
||||
- rpipico
|
||||
|
||||
|
@ -2,29 +2,12 @@
|
||||
// FILE: AD520X.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2020-07-24
|
||||
// VERSION: 0.2.2
|
||||
// PURPOSE: Arduino library for AD5204 and AD5206 digital potentiometers (+ older AD8400, AD8402, AD8403)
|
||||
// VERSION: 0.3.0
|
||||
// PURPOSE: Arduino library for AD5204 and AD5206 digital potentiometers
|
||||
// (+ AD8400, AD8402, AD8403)
|
||||
// URL: https://github.com/RobTillaart/AD520X
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.0.1 2020-07-24 initial version
|
||||
// 0.0.2 2020-07-25 support for AD8400 series in documentation.
|
||||
//
|
||||
// 0.1.0 2020-07-26 refactor, fix #2 select pin for HW SPI; add shutdown.
|
||||
// 0.1.1 2020-12-08 Arduino-CI + unit test + isPowerOn()
|
||||
// 0.1.2 2021-08-19 VSPI / HSPI support for ESP32 only
|
||||
// add setGPIOpins for ESP32 only
|
||||
// add SetSPIspeed (generic)
|
||||
//
|
||||
// 0.2.0 2021-10-16 update build-CI
|
||||
// add get- and setPercentage()
|
||||
// 0.2.1 2021-12-10 update library.json, licence
|
||||
// default value for setAll()
|
||||
// 0.2.2 2022-09-19 update readme.md
|
||||
// add "stereo functions" for setting 2 channels in one call
|
||||
// setValue() and setPercentage()
|
||||
// performance update
|
||||
|
||||
// HISTORY: see CHANGELOG.md
|
||||
|
||||
#include "AD520X.h"
|
||||
|
||||
@ -47,11 +30,11 @@ void AD520X::begin(uint8_t value)
|
||||
pinMode(_select, OUTPUT);
|
||||
digitalWrite(_select, HIGH);
|
||||
pinMode(_reset, OUTPUT);
|
||||
digitalWrite(_reset, LOW);
|
||||
digitalWrite(_reset, HIGH);
|
||||
pinMode(_shutdown, OUTPUT);
|
||||
digitalWrite(_shutdown, LOW);
|
||||
digitalWrite(_shutdown, HIGH);
|
||||
|
||||
_spi_settings = SPISettings(_SPIspeed, MSBFIRST, SPI_MODE1);
|
||||
_spi_settings = SPISettings(_SPIspeed, MSBFIRST, SPI_MODE0);
|
||||
|
||||
if(_hwSPI)
|
||||
{
|
||||
@ -165,8 +148,8 @@ float AD520X::getPercentage(uint8_t pm)
|
||||
|
||||
void AD520X::reset(uint8_t value)
|
||||
{
|
||||
digitalWrite(_reset, HIGH);
|
||||
digitalWrite(_reset, LOW);
|
||||
digitalWrite(_reset, HIGH);
|
||||
setAll(value);
|
||||
}
|
||||
|
||||
@ -174,7 +157,7 @@ void AD520X::reset(uint8_t value)
|
||||
void AD520X::setSPIspeed(uint32_t speed)
|
||||
{
|
||||
_SPIspeed = speed;
|
||||
_spi_settings = SPISettings(_SPIspeed, MSBFIRST, SPI_MODE1);
|
||||
_spi_settings = SPISettings(_SPIspeed, MSBFIRST, SPI_MODE0);
|
||||
};
|
||||
|
||||
|
||||
|
@ -3,20 +3,19 @@
|
||||
// FILE: AD520X.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2020-07-24
|
||||
// VERSION: 0.2.2
|
||||
// PURPOSE: Arduino library for AD5204 and AD5206 digital potentiometers (+ older AD8400, AD8402, AD8403)
|
||||
// VERSION: 0.3.0
|
||||
// PURPOSE: Arduino library for AD5204 and AD5206 digital potentiometers
|
||||
// (+ AD8400, AD8402, AD8403)
|
||||
// URL: https://github.com/RobTillaart/AD520X
|
||||
//
|
||||
// HISTORY:
|
||||
// see AD520X.cpp file
|
||||
//
|
||||
// HISTORY: see CHANGELOG.md
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "SPI.h"
|
||||
|
||||
|
||||
#define AD520X_LIB_VERSION (F("0.2.2"))
|
||||
#define AD520X_LIB_VERSION (F("0.3.0"))
|
||||
|
||||
|
||||
#ifndef AD520X_MIDDLE_VALUE
|
||||
@ -27,11 +26,10 @@
|
||||
class AD520X
|
||||
{
|
||||
public:
|
||||
AD520X(uint8_t select, uint8_t reset, uint8_t shutdown, uint8_t dataOut, uint8_t clock);
|
||||
AD520X(uint8_t select, uint8_t reset, uint8_t shutdown, uint8_t dataOut, uint8_t clock);
|
||||
|
||||
void begin(uint8_t value = AD520X_MIDDLE_VALUE);
|
||||
|
||||
|
||||
// MONO / SINGLE
|
||||
bool setValue(uint8_t pm = 0, uint8_t value = AD520X_MIDDLE_VALUE);
|
||||
// STEREO / DOUBLE
|
||||
@ -45,16 +43,12 @@ public:
|
||||
bool setPercentage(uint8_t pmA, uint8_t pmB, float percentage);
|
||||
float getPercentage(uint8_t pm = 0);
|
||||
|
||||
|
||||
void reset(uint8_t value = AD520X_MIDDLE_VALUE);
|
||||
uint8_t pmCount() { return _pmCount; };
|
||||
|
||||
|
||||
void powerOn() { digitalWrite(_shutdown, LOW); };
|
||||
void powerOff() { digitalWrite(_shutdown, HIGH); };
|
||||
void powerDown() { powerOff(); }; // obsolete, remove in 0.3.0
|
||||
bool isPowerOn() { return digitalRead(_shutdown) == LOW; };
|
||||
|
||||
void powerOn() { digitalWrite(_shutdown, HIGH); };
|
||||
void powerOff() { digitalWrite(_shutdown, LOW); };
|
||||
bool isPowerOn() { return digitalRead(_shutdown) == HIGH; };
|
||||
|
||||
// speed in Hz
|
||||
void setSPIspeed(uint32_t speed);
|
||||
@ -74,7 +68,6 @@ public:
|
||||
void setGPIOpins(uint8_t clk, uint8_t miso, uint8_t mosi, uint8_t select);
|
||||
#endif
|
||||
|
||||
|
||||
protected:
|
||||
uint8_t _dataOut;
|
||||
uint8_t _clock;
|
||||
@ -113,28 +106,28 @@ public:
|
||||
class AD5204 : public AD520X
|
||||
{
|
||||
public:
|
||||
AD5204(uint8_t select, uint8_t reset, uint8_t shutdown, uint8_t dataOut = 255, uint8_t clock = 255);
|
||||
AD5204(uint8_t select, uint8_t reset, uint8_t shutdown, uint8_t dataOut = 255, uint8_t clock = 255);
|
||||
};
|
||||
|
||||
|
||||
class AD8400 : public AD520X
|
||||
{
|
||||
public:
|
||||
AD8400(uint8_t select, uint8_t reset, uint8_t shutdown, uint8_t dataOut = 255, uint8_t clock = 255);
|
||||
AD8400(uint8_t select, uint8_t reset, uint8_t shutdown, uint8_t dataOut = 255, uint8_t clock = 255);
|
||||
};
|
||||
|
||||
|
||||
class AD8402 : public AD520X
|
||||
{
|
||||
public:
|
||||
AD8402(uint8_t select, uint8_t reset, uint8_t shutdown, uint8_t dataOut = 255, uint8_t clock = 255);
|
||||
AD8402(uint8_t select, uint8_t reset, uint8_t shutdown, uint8_t dataOut = 255, uint8_t clock = 255);
|
||||
};
|
||||
|
||||
|
||||
class AD8403 : public AD520X
|
||||
{
|
||||
public:
|
||||
AD8403(uint8_t select, uint8_t reset, uint8_t shutdown, uint8_t dataOut = 255, uint8_t clock = 255);
|
||||
AD8403(uint8_t select, uint8_t reset, uint8_t shutdown, uint8_t dataOut = 255, uint8_t clock = 255);
|
||||
};
|
||||
|
||||
// -- END OF FILE --
|
||||
// -- END OF FILE --
|
||||
|
53
libraries/AD520X/CHANGELOG.md
Normal file
53
libraries/AD520X/CHANGELOG.md
Normal file
@ -0,0 +1,53 @@
|
||||
# Change Log AD520X
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.3.0] - 2022-10-12
|
||||
- Fix 13 shutdown / reset. (kudos to Ale11Re)
|
||||
- Fix 14 wrong SPI mode. (kudos to Ale11Re)
|
||||
- Add RP2040 support to build-CI.
|
||||
- Add CHANGELOG.md
|
||||
|
||||
----
|
||||
|
||||
## [0.2.2] - 2022-09-19
|
||||
- update readme.md
|
||||
- add "stereo functions" for setting 2 channels in one call
|
||||
- setValue() and setPercentage()
|
||||
- performance update.
|
||||
|
||||
## [0.2.1] - 2021-12-10
|
||||
- update library.json,
|
||||
- update licence
|
||||
- default value for setAll()
|
||||
|
||||
## [0.2.0] - 2021-10-16
|
||||
- update build-CI
|
||||
- add get- and setPercentage()
|
||||
|
||||
----
|
||||
|
||||
## [0.1.2] - 2021-08-19
|
||||
- VSPI / HSPI support for ESP32 only
|
||||
- add setGPIOpins for ESP32 only
|
||||
- add SetSPIspeed (generic)
|
||||
|
||||
## [0.1.1] - 2020-12-08
|
||||
- Arduino-CI + unit test
|
||||
- add isPowerOn()
|
||||
|
||||
## [0.1.0] - 2020-07-26
|
||||
- refactor,
|
||||
- fix #2 select pin for HW SPI;
|
||||
- add shutdown().
|
||||
|
||||
## [0.0.2] - 2020-07-25
|
||||
- support for AD8400 series in documentation
|
||||
|
||||
## [0.0.1] - 2020-07-24
|
||||
- initial version
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
Arduino library for SPI AD5204 and AD5206 digital potentiometers.
|
||||
|
||||
Should work with the AD840x series too (not tested).
|
||||
Works with the AD840x series too (see PR #15)
|
||||
|
||||
|
||||
## Description
|
||||
@ -28,12 +28,10 @@ The interface is straightforward, one can set a value per channels between 0..25
|
||||
| AD5206 | 6 | | V | V | V | confirmed |
|
||||
| AD8400 | 1 | V | V | V | V | confirmed |
|
||||
| AD8402 | 2 | V | V | V | V |
|
||||
| AD8403 | 4 | V | V | V | V |
|
||||
| AD8403 | 4 | V | V | V | V | confirmed | see PR #15
|
||||
|
||||
The library is not yet confirmed to work for **AD8402** (2 channels) and **AD8403** (4 channels).
|
||||
These devices have a very similar interface (datasheet comparison) so it should work.
|
||||
|
||||
If you can confirm these models works, please let me know._
|
||||
The library is not yet confirmed to work for **AD8402** (2 channels).
|
||||
This device has a very similar interface (datasheet comparison) so it should work. If you can confirm the AD8402 works, please let me know.
|
||||
|
||||
|
||||
## Interface
|
||||
@ -121,7 +119,7 @@ The **selectVSPI()** or the **selectHSPI()** needs to be called BEFORE the **beg
|
||||
|
||||
### Obsolete
|
||||
|
||||
- **void powerDown()** OBSOLETE => use powerOff() instead.
|
||||
- **void powerDown()** OBSOLETE since 0.3.0 => use powerOff() instead.
|
||||
|
||||
|
||||
## Operations
|
||||
@ -131,6 +129,16 @@ See examples.
|
||||
|
||||
## Future
|
||||
|
||||
|
||||
#### 0.3.1
|
||||
|
||||
- **setGroupValue(mask, value)** bit mask to set 0..8 channels in one call
|
||||
- loop over mask ?
|
||||
- **setGroupPercentage(mask, value)** bit mask to set 0..8 channels in one call
|
||||
- wrapper
|
||||
- move all code to .cpp file
|
||||
|
||||
|
||||
#### Must
|
||||
|
||||
|
||||
@ -143,20 +151,18 @@ See examples.
|
||||
- how does this work with **stereo** functions.
|
||||
- at what level should invert work.
|
||||
- **bool getInvert(uint8_t pm)**
|
||||
- **setGroupValue(mask, value)** bitmask to set 0..8 channels in one call
|
||||
- loop over mask ?
|
||||
- **setGroupPercentage(mask, value)** bitmask to set 0..8 channels in one call
|
||||
- wrapper
|
||||
|
||||
#### Could
|
||||
|
||||
- **AD520X_MIDDLE_VALUE** 127 ?
|
||||
#### Could (only if requested.)
|
||||
|
||||
- **AD520X_MIDDLE_VALUE** 127 ? (0.4.0?)
|
||||
- **setSWSPIdelay()** to tune software SPI?
|
||||
- only if requested.
|
||||
- bit delay / not byte delay
|
||||
- unit microseconds
|
||||
|
||||
|
||||
#### Wont
|
||||
|
||||
|
||||
- **void setGamma(uint8_t pm, float gamma)**
|
||||
- logarithmic effect? easier with setPercentage()
|
||||
- see gamma library.
|
||||
|
@ -12,8 +12,10 @@ uint32_t start, stop;
|
||||
|
||||
|
||||
// select, reset, shutdown, data, clock
|
||||
// AD5204 pot(10, 255, 255, 8, 9); // SW SPI
|
||||
AD5204 pot = AD5204(10, 12, 13); // HW SPI
|
||||
AD5206 pot(10, 255, 255, 8, 9); // SW SPI
|
||||
|
||||
// select, reset, shutdown
|
||||
// AD5206 pot = AD5206(5, 6, 7); // HW SPI UNO clock = 13, data = 11
|
||||
|
||||
|
||||
void setup()
|
||||
@ -23,8 +25,9 @@ void setup()
|
||||
|
||||
pot.begin(4);
|
||||
|
||||
test_sinus();
|
||||
test_sawtooth();
|
||||
// test_extremes();
|
||||
// test_sinus();
|
||||
// test_sawtooth();
|
||||
test_timing();
|
||||
|
||||
Serial.println("\nDone...");
|
||||
@ -35,6 +38,24 @@ void loop()
|
||||
{
|
||||
}
|
||||
|
||||
void test_extremes()
|
||||
{
|
||||
Serial.println(__FUNCTION__);
|
||||
delay(10);
|
||||
|
||||
Serial.println("0");
|
||||
pot.setValue(0, 0);
|
||||
delay(2000);
|
||||
|
||||
Serial.println("127");
|
||||
pot.setValue(0, 127);
|
||||
delay(2000);
|
||||
|
||||
Serial.println("255");
|
||||
pot.setValue(0, 255);
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
|
||||
// connect all A GND and B 5V
|
||||
// every W will have a different signal (same freq).
|
||||
@ -47,7 +68,7 @@ void test_sinus()
|
||||
uint32_t i = 0;
|
||||
while (millis() - start < 10000)
|
||||
{
|
||||
uint8_t value = 127 * sin(i * TWO_PI / 100);
|
||||
int8_t value = 127 * sin(i * TWO_PI / 100);
|
||||
pot.setValue(0, 128 + value);
|
||||
pot.setValue(1, 128 + value / 2);
|
||||
pot.setValue(2, 64 + value / 2);
|
||||
@ -66,9 +87,10 @@ void test_sawtooth()
|
||||
|
||||
start = millis();
|
||||
uint8_t i = 0;
|
||||
while (millis() - start < 10000)
|
||||
while (millis() - start < 25500)
|
||||
{
|
||||
pot.setValue(0, i++); // auto wrap is fast...
|
||||
delay(100);
|
||||
}
|
||||
}
|
||||
|
||||
|
23
libraries/AD520X/examples/AD5204_demo/performance_0.3.0.txt
Normal file
23
libraries/AD520X/examples/AD5204_demo/performance_0.3.0.txt
Normal file
@ -0,0 +1,23 @@
|
||||
|
||||
IDE: 1.8.19
|
||||
Board: UNO
|
||||
Mode: HWSPI
|
||||
|
||||
D:\Rob\WORK\Arduino\libraries\AD520X\examples\AD5204_demo\AD5204_demo.ino
|
||||
test_timing
|
||||
10000 x setValue(): 74500
|
||||
1000 x setAll(): 45204
|
||||
1000 x getValue(): 692
|
||||
|
||||
Done...
|
||||
|
||||
|
||||
IDE: 1.8.19
|
||||
Board: UNO
|
||||
Mode: software SPI (bit bang)
|
||||
|
||||
D:\Rob\WORK\Arduino\libraries\AD520X\examples\AD5204_demo\AD5204_demo.ino
|
||||
test_timing
|
||||
10000 x setValue(): 1062232
|
||||
1000 x setAll(): 638272
|
||||
1000 x getValue(): 696
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/AD520X.git"
|
||||
},
|
||||
"version": "0.2.2",
|
||||
"version": "0.3.0",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=AD520X
|
||||
version=0.2.2
|
||||
version=0.3.0
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for SPI AD5204 and AD5206 digital potentiometers
|
||||
|
Loading…
x
Reference in New Issue
Block a user