From aa20622e3cecd96bba47fa2b723642d7d6c402bc Mon Sep 17 00:00:00 2001 From: rob tillaart Date: Tue, 10 Jan 2023 19:34:29 +0100 Subject: [PATCH] 0.1.2 AD56X8 --- .../AD56X8/.github/workflows/arduino-lint.yml | 2 +- .../.github/workflows/arduino_test_runner.yml | 2 +- .../AD56X8/.github/workflows/jsoncheck.yml | 2 +- libraries/AD56X8/AD56X8.cpp | 30 +++++++++++--- libraries/AD56X8/AD56X8.h | 6 ++- libraries/AD56X8/CHANGELOG.md | 9 ++++- libraries/AD56X8/LICENSE | 2 +- libraries/AD56X8/README.md | 8 ++-- .../examples/AD56X8_wave/AD56X8_wave.ino | 39 +++++++++++++++++++ libraries/AD56X8/keywords.txt | 2 + libraries/AD56X8/library.json | 2 +- libraries/AD56X8/library.properties | 2 +- 12 files changed, 88 insertions(+), 18 deletions(-) create mode 100644 libraries/AD56X8/examples/AD56X8_wave/AD56X8_wave.ino diff --git a/libraries/AD56X8/.github/workflows/arduino-lint.yml b/libraries/AD56X8/.github/workflows/arduino-lint.yml index b2ca058c..8a26f14a 100644 --- a/libraries/AD56X8/.github/workflows/arduino-lint.yml +++ b/libraries/AD56X8/.github/workflows/arduino-lint.yml @@ -6,7 +6,7 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: arduino/arduino-lint-action@v1 with: library-manager: update diff --git a/libraries/AD56X8/.github/workflows/arduino_test_runner.yml b/libraries/AD56X8/.github/workflows/arduino_test_runner.yml index 096b975b..fadfa904 100644 --- a/libraries/AD56X8/.github/workflows/arduino_test_runner.yml +++ b/libraries/AD56X8/.github/workflows/arduino_test_runner.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: ruby/setup-ruby@v1 with: ruby-version: 2.6 diff --git a/libraries/AD56X8/.github/workflows/jsoncheck.yml b/libraries/AD56X8/.github/workflows/jsoncheck.yml index 04603d08..37a11298 100644 --- a/libraries/AD56X8/.github/workflows/jsoncheck.yml +++ b/libraries/AD56X8/.github/workflows/jsoncheck.yml @@ -10,7 +10,7 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: json-syntax-check uses: limitusus/json-syntax-check@v1 with: diff --git a/libraries/AD56X8/AD56X8.cpp b/libraries/AD56X8/AD56X8.cpp index 88b3a73e..665fc282 100644 --- a/libraries/AD56X8/AD56X8.cpp +++ b/libraries/AD56X8/AD56X8.cpp @@ -1,7 +1,7 @@ // // FILE: AD56X8.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.1.1 +// VERSION: 0.1.2 // DATE: 2022-07-28 // PURPOSE: Arduino library for AD56X8, SPI 8 channel Digital Analog Convertor. @@ -127,6 +127,29 @@ uint16_t AD56X8::getValue(uint8_t channel) } +bool AD56X8::setPercentage(uint8_t channel, float percentage) +{ + uint16_t value = 0; + if (_type == 16) value = round(655.35 * percentage); + else if (_type == 14) value = round(163.83 * percentage); + else /* type = 12 */ value = round( 40.95 * percentage): + return setValue(channel, value); +} + + +float AD56X8::getPercentage(uint8_t channel) +{ + float value = getValue(channel); + if (value > 0) + { + if (_type == 16) return value * ( 1.0 / 655.35); + if (_type == 14) return value * ( 1.0 / 163.83); + if (_type == 12) return value * ( 1.0 / 40.95); + } + return 0; +} + + bool AD56X8::prepareChannel(uint8_t channel, uint16_t value) { if (channel > 7) return false; @@ -148,8 +171,6 @@ bool AD56X8::updateChannel(uint8_t channel) void AD56X8::updateAllChannels() { - // TODO test - // TODO replace with hardware LDAC if supported. updateDevice(AD56X8_REG_WRITE_LDAC, 0, _value[0]); } @@ -327,8 +348,5 @@ AD5628::AD5628(uint8_t spiData, uint8_t spiClock, uint8_t slaveSelect) } - - - // -- END OF FILE -- diff --git a/libraries/AD56X8/AD56X8.h b/libraries/AD56X8/AD56X8.h index 59139995..15abeb61 100644 --- a/libraries/AD56X8/AD56X8.h +++ b/libraries/AD56X8/AD56X8.h @@ -2,7 +2,7 @@ // // FILE: AD56X8.h // AUTHOR: Rob Tillaart -// VERSION: 0.1.1 +// VERSION: 0.1.2 // 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.1")) +#define AD56X8_LIB_VERSION (F("0.1.2")) #define AD56X8_PWR_NORMAL 0x00 @@ -41,6 +41,8 @@ public: // sets output immediately = prepare + update. bool setValue(uint8_t channel, uint16_t value); uint16_t getValue(uint8_t channel); + bool setPercentage(uint8_t channel, float percentage); + float getPercentage(uint8_t channel); // prep & update separately bool prepareChannel(uint8_t channel, uint16_t value); diff --git a/libraries/AD56X8/CHANGELOG.md b/libraries/AD56X8/CHANGELOG.md index 76013a6f..501698a2 100644 --- a/libraries/AD56X8/CHANGELOG.md +++ b/libraries/AD56X8/CHANGELOG.md @@ -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.2] - 2023-01-09 +- update GitHub actions +- update license +- add wave example (triangle) +- add bool setPercentage(channel, percentage) +- add float getPercentage(channel) + + ## [0.1.1] - 2022-12-01 - initial release - add changelog.md @@ -15,7 +23,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - clean up code - update readme.md - ## [0.1.0] - 2022-07-28 - rework (add from DAC855x + MCP_DAC) - not released. diff --git a/libraries/AD56X8/LICENSE b/libraries/AD56X8/LICENSE index cb502675..7ff52579 100644 --- a/libraries/AD56X8/LICENSE +++ b/libraries/AD56X8/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022-2022 Rob Tillaart +Copyright (c) 2022-2023 Rob Tillaart Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/libraries/AD56X8/README.md b/libraries/AD56X8/README.md index d21322cf..d5d8ee1f 100644 --- a/libraries/AD56X8/README.md +++ b/libraries/AD56X8/README.md @@ -85,6 +85,8 @@ Sets internal values to zero. Returns false if channel out of range. - **uint16_t getValue(uint8_t channel)** returns set OR prepared value. At power up the DAC's will be reset to 0 V except the AD5668-3 (2.5V). +- **bool setPercentage(uint8_t channel, float percentage)** idem. +- **float getPercentage(uint8_t channel)** idem. - **bool prepareChannel(uint8_t channel, uint16_t value)** prepares the value for a channel. Returns false if channel out of range. - **bool updateChannel(uint8_t channel)** writes the prepared value to ADC. @@ -185,6 +187,7 @@ Note that the library is not tested with hardware yet. ## Future #### Must + - update and improve documentation - get test hardware - test the library @@ -192,8 +195,8 @@ Note that the library is not tested with hardware yet. - check TODO's in code #### Should + - write examples - - get/setValue - LDAC - power mode - support for RESET pin @@ -202,12 +205,11 @@ Note that the library is not tested with hardware yet. - investigate value range checking for AD5648 and AD5628 - now setValue() returns false if value > max, - should value be clipped instead? -- voltage interface(?) - - convenient. - **bool loadLDAC()** TODO? - investigate different type for AD5668_3 (as it does midscale) #### Could + - CCmode + reset implies start value for getValue(ch) - is this implementable? costs? diff --git a/libraries/AD56X8/examples/AD56X8_wave/AD56X8_wave.ino b/libraries/AD56X8/examples/AD56X8_wave/AD56X8_wave.ino new file mode 100644 index 00000000..d5c9f15a --- /dev/null +++ b/libraries/AD56X8/examples/AD56X8_wave/AD56X8_wave.ino @@ -0,0 +1,39 @@ +// +// FILE: AD56X8_wave.ino +// AUTHOR: Rob Tillaart +// PUPROSE: performance test + + +#include "AD56X8.h" + +AD56X8 AD16_SW(9, 10, 11); + +uint32_t start, stop; + +int value = 0; + + +void setup() +{ + Serial.begin(115200); + Serial.println(); + Serial.println(__FILE__); + Serial.print("AD56X8_LIB_VERSION: "); + Serial.println(AD56X8_LIB_VERSION); + + AD16_SW.begin(); + + value = AD16_SW.getValue(0); +} + + +void loop() +{ + AD16_SW.setValue(0, value); + value++; + if (value == 4096) value = 0; + delay(10); +} + + +// -- END OF FILE -- diff --git a/libraries/AD56X8/keywords.txt b/libraries/AD56X8/keywords.txt index 89f74d96..8a3af1fb 100644 --- a/libraries/AD56X8/keywords.txt +++ b/libraries/AD56X8/keywords.txt @@ -13,6 +13,8 @@ getType setValue KEYWORD2 getValue KEYWORD2 +setPercentage KEYWORD2 +getPercentage KEYWORD2 prepareChannel KEYWORD2 updateChannel KEYWORD2 diff --git a/libraries/AD56X8/library.json b/libraries/AD56X8/library.json index 44b508ab..c1d41ed6 100644 --- a/libraries/AD56X8/library.json +++ b/libraries/AD56X8/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/AD56X8.git" }, - "version": "0.1.1", + "version": "0.1.2", "license": "MIT", "frameworks": "arduino", "platforms": "*", diff --git a/libraries/AD56X8/library.properties b/libraries/AD56X8/library.properties index 997873e1..ff0899f8 100644 --- a/libraries/AD56X8/library.properties +++ b/libraries/AD56X8/library.properties @@ -1,5 +1,5 @@ name=AD56X8 -version=0.1.1 +version=0.1.2 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for AD56X8, SPI 8 channel Digital Analog Convertor.