Skip to content

Commit

Permalink
Merge pull request #6 from janelia-arduino/multichip
Browse files Browse the repository at this point in the history
Multichip Support
  • Loading branch information
peterpolidoro authored Oct 4, 2023
2 parents 35ecfde + 1ea88fb commit a009794
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 100 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
/sftp-config.json
.tags
.tags_sorted_by_file
.pio
.venv
48 changes: 22 additions & 26 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
License Agreement
(3-clause BSD License)
Janelia Research Campus Software Copyright 1.1
Janelia Open-Source Software (3-clause BSD License)

Copyright (c) 2014, Howard Hughes Medical Institute
All rights reserved.
Copyright 2023 Howard Hughes Medical Institute

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

* Neither the name of the Howard Hughes Medical Institute nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written
permission.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.PHONY: venv
venv:
rm -rf .venv;\
mkdir .venv;\
python3 -m venv .venv;\
source .venv/bin/activate;\
pip install platformio

.PHONY: clean
clean:
rm -rf .pio

firmware: clean
. .venv/bin/activate; pio run -e teensy41

.PHONY: upload
upload: clean
. .venv/bin/activate; pio run -e teensy41 --target upload --upload-port /dev/ttyACM0

.PHONY: monitor
monitor:
. .venv/bin/activate; pio device monitor
22 changes: 12 additions & 10 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

* Library Information
- Name :: AD57X4R
- Version :: 4.0.1
- Version :: 5.0.0
- License :: BSD
- URL :: https://github.com/janelia-arduino/AD57X4R
- Author :: Peter Polidoro
- Email :: [email protected]

** Description

Provides an SPI based interface to the AD5724R, AD5734R, and the AD5754R Quad
12-/14-/16-Bit Unipolar/Bipolar Voltage Output DACs.

Expand All @@ -25,12 +27,12 @@

* Wiring

| PIN | CONNECTION |
|-----------+---------------------------------------------------------------------|
| SDIN | connect to processor MOSI pin or SDO of previous daisy-chained chip |
| SDO | connect to processor MISO pin or SDIN of next daisy-chained chip |
| SCLK | connect to processor SCK pin |
| SYNC | connect to processor chip select pin |
| BIN2SCOMP | GND |
| LDAC | GND or connect to processor pin and use setLoadDacPin method |
| CLR | DVCC or connect to processor pin and use setClearPin method |
| PIN | CONNECTION |
|-----------+-------------------------------------------------------------------------------|
| SDIN | connect to processor MOSI pin or SDO of previous daisy-chained chip |
| SDO | connect to processor MISO pin or SDIN of next daisy-chained chip |
| SCLK | connect to processor SCK pin |
| SYNC | connect to processor CS pin and set in constructor or setChipSelectPin method |
| BIN2SCOMP | GND |
| LDAC | GND or connect to processor pin and use setLoadDacPin method |
| CLR | DVCC or connect to processor pin and use setClearPin method |
2 changes: 1 addition & 1 deletion examples/Interactive/Interactive.ino
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ uint8_t parse(char *line, char **argv, uint8_t max_args)
line++; /* skip the argument until ... */
}
}
*argv = '\0'; /* mark the end of argument list */
**argv = '\0'; /* mark the end of argument list */
return arg_count;
}

Expand Down
42 changes: 42 additions & 0 deletions examples/MultiChip/MultiChip.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <AD57X4R.h>


const size_t CHIP_SELECT_PIN = 10;
const size_t LOAD_DAC_PIN = 3;
const size_t CLEAR_PIN = 4;

const size_t CHIP_COUNT = 2;

const size_t VOLTAGE_MULTIPLIER = 1;

const int DELAY = 500;

AD57X4R dac = AD57X4R(CHIP_SELECT_PIN);

void setup()
{
// Initialize DAC
dac.setLoadDacPin(LOAD_DAC_PIN);
dac.setClearPin(CLEAR_PIN);
dac.setup(AD57X4R::AD5724R, CHIP_COUNT);

dac.setAllOutputRanges(AD57X4R::UNIPOLAR_10V);
}

void loop()
{
dac.beginSimultaneousUpdate();
for (size_t channel=0; channel<dac.getChannelCount(); ++channel)
{
dac.setVoltage(channel, channel*VOLTAGE_MULTIPLIER);
}
dac.simultaneousUpdate();

delay(DELAY);

dac.beginSimultaneousUpdate();
dac.setAllVoltages(0);
dac.simultaneousUpdate();

delay(DELAY);
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=AD57X4R
version=4.0.1
version=5.0.0
author=Peter Polidoro <[email protected]>
maintainer=Peter Polidoro <[email protected]>
sentence=Provides an SPI based interface to the AD5724R, AD5734R, and the AD5754R Quad 12-/14-/16-Bit Unipolar/Bipolar Voltage Output DACs.
Expand Down
43 changes: 43 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[platformio]
; src_dir = examples/Interactive
; src_dir = examples/MultiChip
; src_dir = examples/Sawtooth
src_dir = examples/SimultaneousUpdate
lib_dir = src

[common_env_data]
build_flags =
-Isrc
lib_deps_builtin =
SPI
lib_deps_external =
https://github.com/janelia-arduino/Streaming.git#6.1.1
lib_deps_local =
src/AD57X4R

[env]
lib_ldf_mode = off
build_flags =
${common_env_data.build_flags}
; monitor_flags =
; --echo
; --eol
; CRLF
monitor_filters =
send_on_enter
colorize
monitor_speed = 115200
lib_deps =
${common_env_data.lib_deps_builtin}
${common_env_data.lib_deps_external}
${common_env_data.lib_deps_local}

[env:teensy41]
platform = teensy
framework = arduino
board = teensy41
upload_protocol = teensy-cli

; pio run
; pio run -e teensy41 --target upload --upload-port /dev/ttyACM0
; pio device monitor
23 changes: 13 additions & 10 deletions src/AD57X4R.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
class AD57X4R
{
public:
enum Resolution {AD5724R,
enum Resolution {
AD5724R,
AD5734R,
AD5754R};
enum Range {UNIPOLAR_5V,
enum Range {
UNIPOLAR_5V,
UNIPOLAR_10V,
UNIPOLAR_10V8,
BIPOLAR_5V,
Expand Down Expand Up @@ -85,7 +87,7 @@ class AD57X4R
const static int CHIP_ALL = -1;

const static size_t CHIP_COUNT_MIN = 1;
const static size_t CHIP_COUNT_MAX = 4;
const static size_t CHIP_COUNT_MAX = 8;
uint8_t chip_count_;

const static size_t CHANNEL_MIN = 0;
Expand All @@ -101,16 +103,16 @@ class AD57X4R
// Datagram
union Datagram
{
struct Fields
struct
{
uint32_t data : 16;
uint32_t channel_address : 3;
uint32_t reg : 3;
uint32_t space0 : 1;
uint32_t rw : 1;
uint32_t space1 : 8;
} fields;
uint32_t uint32;
};
uint32_t bytes;
};

// Read/Write Bit
Expand Down Expand Up @@ -161,18 +163,19 @@ class AD57X4R
void initialize();
uint8_t channelToChip(size_t channel);
uint8_t channelToChannelAddress(size_t channel);
void enableClockSelect();
void disableClockSelect();
void enableChipSelect();
void disableChipSelect();
void spiBeginTransaction();
void spiEndTransaction();
void initializeMosiDatagramArray(Datagram datagram_array[]);
void writeMosiDatagramToChip(int chip,
Datagram mosi_datagram);
Datagram readMisoDatagramFromChip(int chip);
void powerUpAllDacs();
void setOutputRangeToChip(int chip,
void setOutputRangeOnChip(int chip,
uint8_t channel_address,
Range range);
void setAnalogValueToChip(int chip,
void setAnalogValueOnChip(int chip,
uint8_t channel_address,
long data);
void load(int chip);
Expand Down
Loading

0 comments on commit a009794

Please sign in to comment.