0.2.4 DAC8554

This commit is contained in:
rob tillaart 2021-12-15 14:57:49 +01:00
parent d7d92e5f7d
commit 3288b31f43
15 changed files with 94 additions and 44 deletions

View File

@ -2,6 +2,10 @@ compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
- leonardo
- due
- zero
# - due
# - zero
# - leonardo
- m4
- esp32
# - esp8266
# - mega2560

View File

@ -2,7 +2,7 @@
// FILE: DAC8554.cpp
// AUTHOR: Rob Tillaart
// PURPOSE: Arduino library for DAC8554 SPI Digital Analog Convertor
// VERSION: 0.2.3
// VERSION: 0.2.4
// URL: https://github.com/RobTillaart/DAC8554
//
// HISTORY:
@ -10,11 +10,12 @@
// 0.1.2 2020-04-06 minor refactor, readme.md
// 0.1.3 2020-06-07 fix library.json
// 0.1.4 2020-07-20 fix URL's in demo's; MIT license; minor edits
// 0.2.0 2020-12-18 add arduino-ci + unit test
// 0.2.0 2020-12-18 add Arduino-CI + unit test
// 0.2.1 2021-01-10 fix slave select hardware SPI + getValue() + getPowerDownMode().
// fix unit test.
// 0.2.2 2021-06-02 compile ESP32
// 0.2.3 2021-08-29 add support for HSPI / VSPI ESP32 ++
// 0.2.4 2021-12-15 update library.json, license, unit test, minor edits
#include "DAC8554.h"
@ -34,7 +35,6 @@ DAC8554::DAC8554(uint8_t slaveSelect, uint8_t address)
}
// 0,1,2,4 resp 8550 8551 8552 8554
DAC8554::DAC8554(uint8_t spiData, uint8_t spiClock, uint8_t slaveSelect, uint8_t address)
{
_hwSPI = false;
@ -112,8 +112,8 @@ void DAC8554::setGPIOpins(uint8_t clk, uint8_t miso, uint8_t mosi, uint8_t selec
//
// SETVALUE
//
// channel = 0,1,2,3
// value = 0..65535
// channel = 0, 1, 2, 3
// value = 0..65535
void DAC8554::bufferValue(uint8_t channel, uint16_t value)
{
uint8_t configRegister = _address;
@ -134,7 +134,7 @@ void DAC8554::setValue(uint8_t channel, uint16_t value)
// channel = 0, 1, 2, 3 depending on type
// returns 0..65535
// returns 0..65535
uint16_t DAC8554::getValue(uint8_t channel)
{
return _value[channel];
@ -155,12 +155,13 @@ void DAC8554::setSingleValue(uint8_t channel, uint16_t value)
//
// POWERDOWN
//
// channel = 0,1,2,3
// channel = 0, 1, 2, 3
// powerDownMode =
// DAC8554_POWERDOWN_NORMAL 0x00
// DAC8554_POWERDOWN_1K 0x40
// DAC8554_POWERDOWN_100K 0x80
// DAC8554_POWERDOWN_HIGH_IMP 0xC0
// DAC8554_POWERDOWN_NORMAL 0x00
// DAC8554_POWERDOWN_1K 0x40
// DAC8554_POWERDOWN_100K 0x80
// DAC8554_POWERDOWN_HIGH_IMP 0xC0
//
void DAC8554::bufferPowerDown(uint8_t channel, uint8_t powerDownMode)
{
_register[channel] = powerDownMode;
@ -278,4 +279,6 @@ void DAC8554::swSPI_transfer(uint8_t value)
}
}
// -- END OF FILE --

View File

@ -3,7 +3,7 @@
// FILE: DAC8554.h
// AUTHOR: Rob Tillaart
// PURPOSE: Arduino library for DAC8554 SPI Digital Analog Convertor
// VERSION: 0.2.3
// VERSION: 0.2.4
// HISTORY: See DAC8554.cpp
// URL: https://github.com/RobTillaart/DAC8554
//
@ -11,13 +11,12 @@
#include "Arduino.h"
#include "SPI.h"
#define DAC8554_LIB_VERSION (F("0.2.3"))
#define DAC8554_LIB_VERSION (F("0.2.4"))
#define DAC8554_POWERDOWN_NORMAL 0x00
#define DAC8554_POWERDOWN_1K 0x40
#define DAC8554_POWERDOWN_100K 0x80
#define DAC8554_POWERDOWN_HIGH_IMP 0xC0
#define DAC8554_POWERDOWN_NORMAL 0x00
#define DAC8554_POWERDOWN_1K 0x40
#define DAC8554_POWERDOWN_100K 0x80
#define DAC8554_POWERDOWN_HIGH_IMP 0xC0
class DAC8554
@ -31,17 +30,20 @@ public:
void begin();
void bufferValue(uint8_t channel, uint16_t value);
void setValue(uint8_t channel, uint16_t value);
uint16_t getValue(uint8_t channel);
//writes the value to the channel but does not affect buffered ones
void setSingleValue(uint8_t channel, uint16_t value);
void bufferPowerDown(uint8_t channel, uint8_t powerDownMode);
void setPowerDown(uint8_t channel, uint8_t powerDownMode);
uint8_t getPowerDownMode(uint8_t channel);
void setSinglePowerDown(uint8_t channel, uint8_t powerDownMode);
// write all buffers to all(up to 4) 8554's channel's
void broadcastBuffer();
// write value to all(up to 4) 8554's channel's
@ -49,12 +51,15 @@ public:
// write powerDownMode to all 8554's channel's
void broadcastPowerDown(uint8_t powerDownMode);
// speed in Hz
void setSPIspeed(uint32_t speed);
uint32_t getSPIspeed() { return _SPIspeed; };
bool usesHWSPI() { return _hwSPI; };
// ESP32 specific
#if defined(ESP32)
void selectHSPI() { _useHSPI = true; };
@ -62,6 +67,7 @@ public:
bool usesHSPI() { return _useHSPI; };
bool usesVSPI() { return !_useHSPI; };
// to overrule ESP32 default hardware pins
void setGPIOpins(uint8_t clk, uint8_t miso, uint8_t mosi, uint8_t select);
#endif
@ -83,6 +89,7 @@ private:
void writeDevice(uint8_t configRegister, uint16_t value);
void swSPI_transfer(uint8_t value);
SPIClass * mySPI;
SPISettings _spi_settings;
@ -91,4 +98,6 @@ private:
#endif
};
// -- END OF FILE --

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2017-2021 Rob Tillaart
Copyright (c) 2017-2022 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

@ -7,7 +7,7 @@
# DAC8554
Arduino library for DAC8554 SPI Digital Analog Convertor
Arduino library for DAC8554 SPI Digital Analog Convertor.
## Description
@ -23,10 +23,12 @@ The DAC8554 is a SPI based 16 bit DAC with four channels.
- **DAC8554(uint8_t slaveSelect, uint8_t address = 0)** Constructor for hardware SPI,
since 0.2.0 the slaveSelect pin needs to be defined.
- **DAC8554(uint8_t spiData, uint8_t spiClock, uint8_t slaveSelect, uint8_t address = 0)** Constructor for the software SPI
- **DAC8554(uint8_t spiData, uint8_t spiClock, uint8_t slaveSelect, uint8_t address = 0)**
Constructor for the software SPI
- **void begin()** initializes all pins to default state
- **void setValue(uint8_t channel, uint16_t value)** set the value of the channel to 0 - 65535
- **void setSingleValue(uint8_t channel, uint16_t value)** writes the value to the channel but does not affect buffered ones. TODO - elaborate.
- **void setSingleValue(uint8_t channel, uint16_t value)** writes the value to the channel but
does not affect buffered ones. TODO - elaborate.
- **uint16_t getValue(uint8_t channel)** returns the last value written.
@ -52,8 +54,9 @@ BEFORE the **begin()** function.
#### experimental
- **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.
- **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.
### Power down
@ -75,13 +78,9 @@ Check datasheet for details.
### Broadcast
- **void bufferValue(uint8_t channel, uint16_t value)** prepare a new value for a channel.
- **void broadcastBuffer()** write all buffers to all(up to 4) 8554's channel's
- **void broadcastValue(uint16_t value)** write value to all(up to 4) 8554's channel's
- **void broadcastPowerDown(uint8_t powerDownMode)** write powerDownMode to all 8554's channel's
## Future
- testing
- **void broadcastBuffer()** write all buffers to all(up to 4) 8554's channel's.
- **void broadcastValue(uint16_t value)** write value to all(up to 4) 8554's channel's.
- **void broadcastPowerDown(uint8_t powerDownMode)** write powerDownMode to all 8554's channel's.
## Operation
@ -105,3 +104,8 @@ See examples
**demo_powerdown.ino**
- idem
## Future
- testing

View File

@ -13,6 +13,7 @@
DAC8554 DAC_A(10, 0);
DAC8554 DAC_B(11, 1);
void setup()
{
Serial.begin(115200);
@ -57,4 +58,6 @@ void loop()
{
}
// -- END OF FILE --

View File

@ -11,6 +11,7 @@
DAC8554 mydac(10);
void setup()
{
Serial.begin(115200);
@ -38,7 +39,7 @@ void loop()
// minimal sinus
for (long i = 0; i < 360; i++ )
{
long s = 32768 + 32768 * sin( i * (PI / 180.0));
long s = 32767 + 32767 * sin( i * (PI / 180.0));
mydac.setValue(channel, s);
int av = analogRead(A0);
Serial.print(i);
@ -51,4 +52,6 @@ void loop()
if (channel >= 4) channel = 0;
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -18,6 +18,7 @@ uint8_t chanB = 1;
uint8_t chanC = 2;
uint8_t chanD = 3;
void setup()
{
Serial.begin(115200);
@ -31,6 +32,7 @@ void setup()
mydac.setPowerDown(chanD, DAC8554_POWERDOWN_1K);
}
void loop()
{
Serial.println("Start sawtooth");
@ -58,4 +60,6 @@ void loop()
mydac.setPowerDown(chanA, DAC8554_POWERDOWN_NORMAL);
}
// END OF FILE
// -- END OF FILE --

View File

@ -15,6 +15,7 @@ DAC8554 mydac(10);
uint32_t lastTime = 0;
uint16_t state = 0;
void setup()
{
Serial.begin(115200);
@ -23,6 +24,7 @@ void setup()
mydac.begin();
}
void loop()
{
uint8_t chanA = 0;
@ -55,4 +57,6 @@ void loop()
}
}
// END OF FILE
// -- END OF FILE --

View File

@ -16,6 +16,7 @@ DAC8554 mydac(10);
uint32_t lastTime = 0;
uint16_t state = 0;
void setup()
{
Serial.begin(115200);
@ -57,4 +58,6 @@ void loop()
}
}
// END OF FILE
// -- END OF FILE --

View File

@ -51,4 +51,6 @@ void loop()
}
}
// END OF FILE
// -- END OF FILE --

View File

@ -35,6 +35,7 @@ setGPIOpins KEYWORD2
# Constants (LITERAL1)
DAC8554_LIB_VERSION LITERAL1
DAC8554_POWERDOWN_NORMAL LITERAL1
DAC8554_POWERDOWN_1K LITERAL1
DAC8554_POWERDOWN_100K LITERAL1

View File

@ -15,8 +15,9 @@
"type": "git",
"url": "https://github.com/RobTillaart/DAC8554"
},
"version": "0.2.3",
"version": "0.2.4",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*"
"platforms": "*",
"headers": "DAC8554.h"
}

View File

@ -1,5 +1,5 @@
name=DAC8554
version=0.2.3
version=0.2.4
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for DAC8554 SPI Digital Analog Convertor

View File

@ -30,14 +30,23 @@
unittest_setup()
{
fprintf(stderr, "DAC8554_LIB_VERSION: %s\n", (char *) DAC8554_LIB_VERSION);
}
unittest_teardown()
{
}
unittest(test_constants)
{
assertEqual(0x00, DAC8554_POWERDOWN_NORMAL );
assertEqual(0x40, DAC8554_POWERDOWN_1K );
assertEqual(0x80, DAC8554_POWERDOWN_100K );
assertEqual(0xC0, DAC8554_POWERDOWN_HIGH_IMP);
}
unittest(test_HW_constructor)
{
DAC8554 mydac(10); // not used address parameter