0.1.0 ADC08XS

This commit is contained in:
Rob Tillaart 2024-01-15 10:22:38 +01:00
parent 91b74ff384
commit cfabb5a73a
18 changed files with 1125 additions and 0 deletions

View File

@ -0,0 +1,27 @@
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:
- uno
# - due
# - zero
# - leonardo
- m4
- esp32
- esp8266
# - mega2560
- rpipico

4
libraries/ADC08XS/.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1,4 @@
# These are supported funding model platforms
github: RobTillaart

View File

@ -0,0 +1,13 @@
name: Arduino-lint
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update
compliance: strict

View File

@ -0,0 +1,17 @@
---
name: Arduino CI
on: [push, pull_request]
jobs:
runTest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- run: |
gem install arduino_ci
arduino_ci.rb

View File

@ -0,0 +1,18 @@
name: JSON check
on:
push:
paths:
- '**.json'
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:
pattern: "\\.json$"

View File

@ -0,0 +1,334 @@
//
// FILE: ADC08XS.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// DATE: 2024-01-13
// PURPOSE: Arduino library for ADC082S, ADC084S, ADC102S, ADC104S, ADC122S, ADC124S,
// 8, 10, 12 bits, 2 or 4 channel ADC (SPI).
// URL: https://github.com/RobTillaart/ADC08XS
#include "ADC08XS.h"
// HARDWARE SPI
ADC08XS::ADC08XS(__SPI_CLASS__ * mySPI)
{
_dataIn = 255;
_dataOut = 255;
_clock = 255;
_select = 255;
_hwSPI = true;
_mySPI = mySPI;
_maxValue = 255;
_isLowPower = false;
_maxChannel = 2;
}
// SOFTWARE SPI
ADC08XS::ADC08XS(uint8_t dataIn, uint8_t dataOut, uint8_t clock)
{
_dataIn = dataIn;
_dataOut = dataOut;
_clock = clock;
_select = 255;
_hwSPI = false;
_mySPI = NULL;
_maxValue = 255;
_isLowPower = false;
_maxChannel = 2;
}
void ADC08XS::begin(uint8_t select)
{
_select = select;
pinMode(_select, OUTPUT);
digitalWrite(_select, HIGH);
digitalWrite(_select, LOW);
digitalWrite(_select, HIGH);
_spi_settings = SPISettings(_SPIspeed, MSBFIRST, SPI_MODE0);
if (_hwSPI) // hardware SPI
{
_mySPI->end();
_mySPI->begin();
}
else // software SPI
{
pinMode(_dataIn, INPUT);
pinMode(_dataOut, OUTPUT);
pinMode(_clock, OUTPUT);
digitalWrite(_dataOut, LOW);
digitalWrite(_clock, HIGH);
}
}
uint16_t ADC08XS::maxValue()
{
return _maxValue;
}
uint8_t ADC08XS::maxChannel()
{
return _maxChannel;
}
uint32_t ADC08XS::count()
{
return _count;
}
uint16_t ADC08XS::read(uint8_t channel)
{
return readADC(channel) >> 4; // remove 4 trailing zero's
}
void ADC08XS::setSPIspeed(uint32_t speed)
{
_SPIspeed = speed;
_spi_settings = SPISettings(_SPIspeed, MSBFIRST, SPI_MODE0);
}
uint32_t ADC08XS::getSPIspeed()
{
return _SPIspeed;
}
bool ADC08XS::usesHWSPI()
{
return _hwSPI;
}
void ADC08XS::lowPower()
{
_isLowPower = true;
shutDown();
}
void ADC08XS::wakeUp()
{
readADC(0);
_isLowPower = false;
}
bool ADC08XS::isLowPower()
{
return _isLowPower;
}
/////////////////////////////////////////////////////////////////////////////
//
// PROTECTED
//
uint16_t ADC08XS::readADC(uint8_t channel)
{
if (channel >= _maxChannel) return 0;
_count++;
uint16_t address = channel << 11;
uint16_t data = 0;
digitalWrite(_select, LOW);
if (_hwSPI) // hardware SPI
{
_mySPI->beginTransaction(_spi_settings);
data = _mySPI->transfer16(address);
_mySPI->endTransaction();
}
else // Software SPI
{
data = swSPI_transfer16(address);
}
digitalWrite(_select, HIGH);
return data;
}
void ADC08XS::shutDown()
{
digitalWrite(_select, LOW);
if (_hwSPI) // hardware SPI
{
_mySPI->beginTransaction(_spi_settings);
_mySPI->transfer(0); // 8 pulses
_mySPI->endTransaction();
}
else // Software SPI
{
swSPI_transfer16(0, 0x0010); // 4 pulses is enough
}
digitalWrite(_select, HIGH);
}
// MSBFIRST
uint16_t ADC08XS::swSPI_transfer16(uint16_t address, uint16_t m)
{
uint8_t clk = _clock;
uint8_t dai = _dataIn;
uint8_t dao = _dataOut;
uint16_t addr = address;
uint16_t rv = 0;
for (uint16_t mask = m; mask; mask >>= 1)
{
digitalWrite(dao, (addr & mask));
digitalWrite(clk, LOW);
digitalWrite(clk, HIGH);
if (digitalRead(dai) == HIGH) rv |= mask;
}
return rv;
}
//////////////////////////////////////////////////////////////////////
//
// DERIVED CLASS ADC082S
//
ADC082S::ADC082S(__SPI_CLASS__ * mySPI) : ADC08XS(mySPI)
{
_maxValue = 255;
_maxChannel = 2;
}
ADC082S::ADC082S(uint8_t dataIn, uint8_t dataOut, uint8_t clock) : ADC08XS(dataIn, dataOut, clock)
{
_maxValue = 255;
_maxChannel = 2;
}
uint16_t ADC082S::read(uint8_t channel)
{
return readADC(channel) >> 4; // remove 4 trailing zero's
}
//////////////////////////////////////////////////////////////////////
//
// DERIVED CLASS ADC084S
//
ADC084S::ADC084S(__SPI_CLASS__ * mySPI) : ADC08XS(mySPI)
{
_maxValue = 255;
_maxChannel = 4;
}
ADC084S::ADC084S(uint8_t dataIn, uint8_t dataOut, uint8_t clock) : ADC08XS(dataIn, dataOut, clock)
{
_maxValue = 255;
_maxChannel = 4;
}
uint16_t ADC084S::read(uint8_t channel)
{
return readADC(channel) >> 4; // remove 4 trailing zero's
}
//////////////////////////////////////////////////////////////////////
//
// DERIVED CLASS ADC102S
//
ADC102S::ADC102S(__SPI_CLASS__ * mySPI) : ADC08XS(mySPI)
{
_maxValue = 1023;
_maxChannel = 2;
}
ADC102S::ADC102S(uint8_t dataIn, uint8_t dataOut, uint8_t clock) : ADC08XS(dataIn, dataOut, clock)
{
_maxValue = 1023;
_maxChannel = 2;
}
uint16_t ADC102S::read(uint8_t channel)
{
return readADC(channel) >> 2; // remove 2 trailing zero's
}
//////////////////////////////////////////////////////////////////////
//
// DERIVED CLASS ADC104S
//
ADC104S::ADC104S(__SPI_CLASS__ * mySPI) : ADC08XS(mySPI)
{
_maxValue = 1023;
_maxChannel = 4;
}
ADC104S::ADC104S(uint8_t dataIn, uint8_t dataOut, uint8_t clock) : ADC08XS(dataIn, dataOut, clock)
{
_maxValue = 1023;
_maxChannel = 4;
}
uint16_t ADC104S::read(uint8_t channel)
{
return readADC(channel) >> 2; // remove 2 trailing zero's
}
//////////////////////////////////////////////////////////////////////
//
// DERIVED CLASS ADC122S
//
ADC122S::ADC122S(__SPI_CLASS__ * mySPI) : ADC08XS(mySPI)
{
_maxValue = 4095;
_maxChannel = 2;
}
ADC122S::ADC122S(uint8_t dataIn, uint8_t dataOut, uint8_t clock) : ADC08XS(dataIn, dataOut, clock)
{
_maxValue = 4095;
_maxChannel = 2;
}
uint16_t ADC122S::read(uint8_t channel)
{
return readADC(channel);
}
//////////////////////////////////////////////////////////////////////
//
// DERIVED CLASS ADC124S
//
ADC124S::ADC124S(__SPI_CLASS__ * mySPI) : ADC08XS(mySPI)
{
_maxValue = 4095;
_maxChannel = 4;
}
ADC124S::ADC124S(uint8_t dataIn, uint8_t dataOut, uint8_t clock) : ADC08XS(dataIn, dataOut, clock)
{
_maxValue = 4095;
_maxChannel = 4;
}
uint16_t ADC124S::read(uint8_t channel)
{
return readADC(channel);
}
// -- END OF FILE --

142
libraries/ADC08XS/ADC08XS.h Normal file
View File

@ -0,0 +1,142 @@
#pragma once
//
// FILE: ADC08XS.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// DATE: 2024-01-13
// PURPOSE: Arduino library for ADC082S, ADC084S, ADC102S, ADC104S, ADC122S, ADC124S,
// 8, 10, 12 bits, 2 or 4 channel ADC (SPI).
// URL: https://github.com/RobTillaart/ADC08XS
//
#include "Arduino.h"
#include "SPI.h"
#define ADC08XS_LIB_VERSION (F("0.1.0"))
#ifndef __SPI_CLASS__
#if defined(ARDUINO_ARCH_RP2040)
#define __SPI_CLASS__ SPIClassRP2040
#else
#define __SPI_CLASS__ SPIClass
#endif
#endif
class ADC08XS
{
public:
// HARDWARE SPI
ADC08XS(__SPI_CLASS__ * mySPI = &SPI);
// SOFTWARE SPI
ADC08XS(uint8_t dataIn, uint8_t dataOut, uint8_t clock);
void begin(uint8_t select);
uint16_t maxValue();
uint8_t maxChannel();
uint16_t read(uint8_t channel);
// speed in Hz
void setSPIspeed(uint32_t speed);
uint32_t getSPIspeed();
// debugging
bool usesHWSPI();
uint32_t count(); // number of channels read.
void lowPower();
void wakeUp();
bool isLowPower();
protected:
uint8_t _dataIn;
uint8_t _dataOut;
uint8_t _clock;
uint8_t _select;
bool _hwSPI;
uint16_t _maxValue;
uint8_t _maxChannel;
uint16_t readADC(uint8_t channel);
void shutDown();
uint16_t swSPI_transfer16(uint16_t address, uint16_t m = 0x8000);
// 1 MHz is a safe value (datasheet); in a test 4 MHz worked.
uint32_t _SPIspeed = 1000000;
__SPI_CLASS__ * _mySPI;
SPISettings _spi_settings;
uint32_t _count;
bool _isLowPower;
};
//////////////////////////////////////////////////////////////////////
//
// DERIVED CLASSES 2 channel
//
class ADC082S : public ADC08XS
{
public:
ADC082S(__SPI_CLASS__ * mySPI = &SPI);
ADC082S(uint8_t dataIn, uint8_t dataOut, uint8_t clock);
uint16_t read(uint8_t channel);
};
class ADC102S : public ADC08XS
{
public:
ADC102S(__SPI_CLASS__ * mySPI = &SPI);
ADC102S(uint8_t dataIn, uint8_t dataOut, uint8_t clock);
uint16_t read(uint8_t channel);
};
class ADC122S : public ADC08XS
{
public:
ADC122S(__SPI_CLASS__ * mySPI = &SPI);
ADC122S(uint8_t dataIn, uint8_t dataOut, uint8_t clock);
uint16_t read(uint8_t channel);
};
//////////////////////////////////////////////////////////////////////
//
// DERIVED CLASSES 4 channel
//
class ADC084S : public ADC08XS
{
public:
ADC084S(__SPI_CLASS__ * mySPI = &SPI);
ADC084S(uint8_t dataIn, uint8_t dataOut, uint8_t clock);
uint16_t read(uint8_t channel);
};
class ADC104S : public ADC08XS
{
public:
ADC104S(__SPI_CLASS__ * mySPI = &SPI);
ADC104S(uint8_t dataIn, uint8_t dataOut, uint8_t clock);
uint16_t read(uint8_t channel);
};
class ADC124S : public ADC08XS
{
public:
ADC124S(__SPI_CLASS__ * mySPI = &SPI);
ADC124S(uint8_t dataIn, uint8_t dataOut, uint8_t clock);
uint16_t read(uint8_t channel);
};
// -- END OF FILE --

View File

@ -0,0 +1,11 @@
# Change Log ADC08XS
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.1.0] - 2024-01-13
- initial version.

21
libraries/ADC08XS/LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024-2024 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
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

180
libraries/ADC08XS/README.md Normal file
View File

@ -0,0 +1,180 @@
[![Arduino CI](https://github.com/RobTillaart/ADC08XS/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/ADC08XS/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/ADC08XS/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/ADC08XS/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/ADC08XS/actions/workflows/jsoncheck.yml)
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/ADC08XS.svg)](https://github.com/RobTillaart/ADC08XS/issues)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/ADC08XS/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/ADC08XS.svg?maxAge=3600)](https://github.com/RobTillaart/ADC08XS/releases)
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/ADC08XS.svg)](https://registry.platformio.org/libraries/robtillaart/ADC08XS)
# ADC08XS
Arduino library for ADC082S, ADC084S, ADC102S, ADC104S, ADC122S, ADC124S, 8, 10, 12 bits, 2 or 4 channel ADC (SPI).
## Description
Experimental.
This library provides six classes,
- dual channel: ADC082S, ADC102S and ADC122S.
- quad channel: ADC084S, ADC104S and ADC124S.
These are respectively an 8 bit, a 10 bit and a 12 bit ADC convertor.
The library supports both hardware and software SPI.
The interface is straightforward as one only need a **read()** call
to get the data.
This library does not support the single channel versions.
- See https://github.com/RobTillaart/ADC081S
The library does not support the I2C versions of these devices.
These can be recognized from the C as ADCxxxC
The library can put the device in **lowPower()** and needs a call to
**wakeUp()** to wake up. Alternative way to wake up the device is to
do a dummy **read()**.
The library is not tested with hardware yet.
Feedback is as always welcome.
#### Performance
Although the ADC08XS is rated at 200 KSPS and higher, an Arduino UNO will not
be able to fetch that much samples from the device.
The reason is that an UNO cannot fetch the bits fast enough from the device.
At maximum SPI speed of 8 MHz one will get at most 50 KSPS.
For the faster ones, see below, at 1 MSPS one need a clock of at least 16 MHz
+ time to process the incoming data.
A faster processor like an ESP32 or Teensy might do the job.
Investigations should be made for a sort of continuous mode.
This would have the CS line constantly LOW and be able to read from the same
address over and over.
To be tested, feedback welcome.
#### Compatibles
There are 18 (multi channel) device types in this series, which can be used
with the six classes of this library.
| device name | channels | bits | KSPS | Class | Notes |
|:--------------|:----------:|:------:|:------:|:---------:|:-------:|
| ADC082S021 | 2 | 8 | 200 | ADC082S |
| ADC082S051 | 2 | 8 | 500 | ADC082S |
| ADC082S101 | 2 | 8 | 1000 | ADC082S |
| ADC102S021 | 2 | 10 | 200 | ADC102S |
| ADC102S051 | 2 | 10 | 500 | ADC102S |
| ADC102S101 | 2 | 10 | 1000 | ADC102S |
| ADC122S021 | 2 | 12 | 200 | ADC122S |
| ADC122S051 | 2 | 12 | 500 | ADC122S |
| ADC122S101 | 2 | 12 | 1000 | ADC122S |
| ADC084S021 | 4 | 8 | 200 | ADC084S |
| ADC084S051 | 4 | 8 | 500 | ADC084S |
| ADC084S101 | 4 | 8 | 1000 | ADC084S |
| ADC104S021 | 4 | 10 | 200 | ADC104S |
| ADC104S051 | 4 | 10 | 500 | ADC104S |
| ADC104S101 | 4 | 10 | 1000 | ADC104S |
| ADC124S021 | 4 | 12 | 200 | ADC124S |
| ADC124S051 | 4 | 12 | 500 | ADC124S |
| ADC124S101 | 4 | 12 | 1000 | ADC124S |
Type = ADC(bits)(channel)(protocol)(speed)1
e.g ADC082S021 = 8 bits 2 channel SPI 200000
S == SPI.C == I2C.
#### Related
- https://github.com/RobTillaart/ADC081S single channel version of this series.
- https://gammon.com.au/adc tutorial about ADC's (UNO specific)
- https://github.com/RobTillaart/MCP_ADC
- https://github.com/RobTillaart/ADS1x15 (12 & 16 bit ADC, I2C, slow)
- https://github.com/RobTillaart/PCF8591 (8 bit ADC + 1 bit DAC)
- https://github.com/RobTillaart/MCP_DAC
## Interface
```cpp
#include "ADC08XS_MC.h"
```
#### Constructors
All six classes have identical interfaces as the ADC082S.
- **ADC082S_MC(SPIClassRP2040 \* mySPI = &SPI)** hardware constructor RP2040
- **ADC082S_MC(SPIClass \* mySPI = &SPI)** hardware constructor other
- **ADC082S_MC(uint8_t dataIn, uint8_t dataOut, uint8_t clock)**
- **void begin(uint8_t select)** set SELECT or CS pin.
- **int16_t maxValue()** returns maxReading of ADC, => 255, 1023, 4095
depending on number of bits / class.
- **uint8_t maxChannel()** returns 2 or 4 depending on the class.
#### Base
- **uint16_t read(uint8_t channel)** reads the value of the device.
The parameter channel must be 0,1,2,3, depending on device.
Invalid channels will always return zero 0.
- **void setSPIspeed(uint32_t speed)** sets SPI clock in **Hz**, please read datasheet
of the ADC first to get optimal speed.
- **uint32_t getSPIspeed()** returns current speed in **Hz**.
#### Low power
- **void lowPower()** put device in low power mode.
- **void wakeUp()** put device in normal power mode.
- **isLowPower()** returns true if in low power mode, so wakeUp needed().
Alternative way to wake up the device is to
do a dummy **read()**.
#### Debug
- **bool usesHWSPI()** returns true if hardware SPI is used.
- **uint32_t count()** returns number of reads since start.
## Future
#### Must
- improve documentation
- get hardware to test / verify working
- align with ADC081S where possible
#### Should
- investigate continuous read
- set CS once (or hardwired)
- use a prepared address
- just transfer.
- how much faster?
#### Could
- unit tests possible?
#### Wont
## Support
If you appreciate my libraries, you can support the development and maintenance.
Improve the quality of the libraries by providing issues and Pull Requests, or
donate through PayPal or GitHub sponsors.
Thank you,

View File

@ -0,0 +1,44 @@
//
// FILE: ADC08XS_low_power.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// URL: https://github.com/RobTillaart/ADC08XS
//
// to see it work measure current of the sensor.
#include "ADC08XS.h"
ADC084S adc01; // use HWSPI
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("ADC08XS_LIB_VERSION: ");
Serial.println(ADC08XS_LIB_VERSION);
adc01.begin(10);
}
void loop()
{
Serial.println("low power for 15 seconds.");
adc01.lowPower();
delay(15000);
Serial.println("wake up for 15 seconds.");
if (adc01.isLowPower())
{
adc01.wakeUp();
}
Serial.print("READ: ");
Serial.println(adc01.read(3));
delay(15000);
}
// -- END OF FILE --

View File

@ -0,0 +1,67 @@
//
// FILE: ADC08XS_performance.ino
// AUTHOR: Rob Tillaart
// PURPOSE: performance measurement for ADC082S SPI based ADC
// URL: https://github.com/RobTillaart/ADC08XS
#include "ADC08XS.h"
ADC082S adc; // HW SPI
// ADC082S adc(5, 6, 7); // SW SPI UNO - adjust pins if needed
// ADC082S adc(20, 21); // SW SPI ESP32 - adjust pins if needed
const uint8_t SELECT_PIN = 10;
uint32_t start, stop, read_time;
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("ADC08XS_LIB_VERSION: ");
Serial.println(ADC08XS_LIB_VERSION);
Serial.println();
Serial.println("ADC\tMAXVALUE");
Serial.print("adc\t");
Serial.println(adc.maxValue());
Serial.println("\nTiming in micros().\n");
delay(100);
Serial.println("***************************************\n");
for (int s = 1; s <= 64; s++)
{
uint32_t val = 0;
uint32_t speed = s * 1000000UL;
adc.setSPIspeed(speed);
adc.begin(SELECT_PIN);
delay(100);
start = micros();
for (int i = 0; i < 1000; i++)
{
val += adc.read(0);
}
stop = micros();
read_time = stop - start;
Serial.print(speed);
Serial.print("\tadc.read()\t");
Serial.print(read_time);
Serial.print("\t");
Serial.println(val);
delay(100);
}
Serial.println("done...");
}
void loop()
{
}
// -- END OF FILE --

View File

@ -0,0 +1,29 @@
## Performance test
Test sketch: ADC081S_performance.ino
### Library version: 0.1.0
There is only a transfer of 2 bytes. Times in microseconds.
| device | Test | HW 1 MHz | HW 2 MHz | HW 4 MHz | HW 8 MHz | HW 10 MHz | HW 12 MHz | HW 14 MHz | HW 16 MHz |
|:-----------|:-------------|:--------:|:--------:|:--------:|:---------:|:---------:|:---------:|:---------:|:---------:|
| UNO | adc.read() | 33.6 | 25.6 | 21.6 | 19.6 | - | - | - | - |
| ESP32 | adc.read() | 25.4 | 16.7 | 12.2 | 10.0 | 9.6 | 9.4 | 9.2 | 8.9 |
| device | Test | SW max speed | notes |
|:---------|:-------------|--------------:|:--------|
| UNO | adc.read() | 238.2 | UNO has relative slow digital IO
| ESP32 | adc.read() | 6.9 | faster than HW SPI as it has no transfer overhead.
### Notes

View File

@ -0,0 +1,77 @@
//
// FILE: ADC08XS_read.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// URL: https://github.com/RobTillaart/ADC08XS
#include "ADC08XS.h"
ADC082S adc01; // use HWSPI
ADC124S adc02(5, 6, 7); // use SWSPI
uint32_t start, stop;
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("ADC08XS_LIB_VERSION: ");
Serial.println(ADC08XS_LIB_VERSION);
adc01.begin(10);
adc02.begin(5);
Serial.println();
Serial.println("ADC\tMAXVALUE");
Serial.print("adc01\t");
Serial.println(adc01.maxValue());
delay(10);
start = micros();
uint16_t val = adc01.read(0);
stop = micros();
Serial.print("hwspi:\t");
Serial.print(stop - start);
Serial.print("\t");
Serial.println(val);
Serial.print("adc02\t");
Serial.println(adc02.maxValue());
delay(10);
start = micros();
val = adc02.read(0);
stop = micros();
Serial.print("swspi:\t");
Serial.print(stop - start);
Serial.print("\t");
Serial.println(val);
Serial.println();
}
void loop()
{
uint16_t val0 = adc01.read(0);
uint16_t val1 = adc01.read(1);
Serial.print("adc01:\t");
Serial.print(val0);
Serial.print("\t");
Serial.println(val1);
Serial.print("adc02:\t");
for (uint8_t ch = 0 ; ch < adc02.maxChannel(); ch++)
{
uint16_t val = adc02.read(ch);
Serial.print(val);
Serial.print("\t");
}
Serial.println();
delay(5000);
}
// -- END OF FILE --

View File

@ -0,0 +1,35 @@
# Syntax Colouring Map For ADC08XS
# Data types (KEYWORD1)
ADC08XS KEYWORD1
ADC082S KEYWORD1
ADC102S KEYWORD1
ADC122S KEYWORD1
ADC084S KEYWORD1
ADC104S KEYWORD1
ADC124S KEYWORD1
# Methods and Functions (KEYWORD2)
begin KEYWORD2
maxValue KEYWORD2
maxChannel KEYWORD2
read KEYWORD2
setSPIspeed KEYWORD2
getSPIspeed KEYWORD2
usesHWSPI KEYWORD2
count KEYWORD2
lowPower KEYWORD2
wakeUp KEYWORD2
isLowPower KEYWORD2
# Constants (LITERAL1)
ADC08XS_LIB_VERSION LITERAL1

View File

@ -0,0 +1,23 @@
{
"name": "ADC08XS",
"keywords": "ADC082S, ADC084S, ADC102S, ADC104S, ADC122S, ADC124S",
"description": "Arduino library for ADC08XS 8, 10, 12 bit ADC (SPI), 2 or 4 channel.",
"authors":
[
{
"name": "Rob Tillaart",
"email": "Rob.Tillaart@gmail.com",
"maintainer": true
}
],
"repository":
{
"type": "git",
"url": "https://github.com/RobTillaart/ADC08XS.git"
},
"version": "0.1.0",
"license": "MIT",
"frameworks": "*",
"platforms": "*",
"headers": "ADC08XS.h"
}

View File

@ -0,0 +1,11 @@
name=ADC08XS
version=0.1.0
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for ADC08XS 8, 10, 12 bit ADC (SPI), 2 or 4 channel.
paragraph=ADC082S, ADC084S, ADC102S, ADC104S, ADC122S, ADC124S
category=Sensors
url=https://github.com/RobTillaart/ADC08XS
architectures=*
includes=ADC08XS.h
depends=

View File

@ -0,0 +1,72 @@
//
// FILE: unit_test_001.cpp
// AUTHOR: Rob Tillaart
// DATE: 2024-01-10
// PURPOSE: unit tests for the ADC081S
// https://github.com/RobTillaart/ADC081S
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
//
// supported assertions
// ----------------------------
// assertEqual(expected, actual); // a == b
// assertNotEqual(unwanted, actual); // a != b
// assertComparativeEquivalent(expected, actual); // abs(a - b) == 0 or (!(a > b) && !(a < b))
// assertComparativeNotEquivalent(unwanted, actual); // abs(a - b) > 0 or ((a > b) || (a < b))
// assertLess(upperBound, actual); // a < b
// assertMore(lowerBound, actual); // a > b
// assertLessOrEqual(upperBound, actual); // a <= b
// assertMoreOrEqual(lowerBound, actual); // a >= b
// assertTrue(actual);
// assertFalse(actual);
// assertNull(actual);
// // special cases for floats
// assertEqualFloat(expected, actual, epsilon); // fabs(a - b) <= epsilon
// assertNotEqualFloat(unwanted, actual, epsilon); // fabs(a - b) >= epsilon
// assertInfinity(actual); // isinf(a)
// assertNotInfinity(actual); // !isinf(a)
// assertNAN(arg); // isnan(a)
// assertNotNAN(arg); // !isnan(a)
#include <ArduinoUnitTests.h>
#include "Arduino.h"
#include "ADC08XS.h"
unittest_setup()
{
fprintf(stderr, "ADC08XS_LIB_VERSION: %s\n", (char *) ADC08XS_LIB_VERSION);
}
unittest_teardown()
{
}
unittest(test_constructor)
{
ADC082S ADC_1;
ADC102S ADC_2;
ADC124S ADC_3;
ADC_1.begin(7);
ADC_2.begin(8);
ADC_3.begin(9);
assertEqual(255, ADC_1.maxValue());
assertEqual(2, ADC_1.maxChannel());
assertEqual(1023, ADC_2.maxValue());
assertEqual(2, ADC_2.maxChannel());
assertEqual(4095, ADC_3.maxValue());
assertEqual(4, ADC_3.maxChannel());
}
unittest_main()
// -- END OF FILE --