0.1.2 AD56X8

This commit is contained in:
rob tillaart 2023-01-10 19:34:29 +01:00
parent 811b3539f2
commit aa20622e3c
12 changed files with 88 additions and 18 deletions

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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 --

View File

@ -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);

View File

@ -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.

View File

@ -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

View File

@ -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?

View File

@ -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 --

View File

@ -13,6 +13,8 @@ getType
setValue KEYWORD2
getValue KEYWORD2
setPercentage KEYWORD2
getPercentage KEYWORD2
prepareChannel KEYWORD2
updateChannel KEYWORD2

View File

@ -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": "*",

View File

@ -1,5 +1,5 @@
name=AD56X8
version=0.1.1
version=0.1.2
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.