0.2.0 ADC081S

This commit is contained in:
Rob Tillaart 2024-01-19 14:59:42 +01:00
parent 6cde7de3f3
commit fb8db08712
9 changed files with 46 additions and 26 deletions

View File

@ -1,7 +1,7 @@
//
// FILE: ADC081S.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.2
// VERSION: 0.2.0
// DATE: 2024-01-10
// PURPOSE: Arduino library for ADC081S 8 bit ADC (SPI)
// URL: https://github.com/RobTillaart/ADC081S
@ -13,7 +13,7 @@
// HARDWARE SPI
ADC081S::ADC081S(__SPI_CLASS__ * mySPI)
{
_dataIn = 255;
_data = 255;
_clock = 255;
_select = 255;
_hwSPI = true;
@ -26,7 +26,7 @@ ADC081S::ADC081S(__SPI_CLASS__ * mySPI)
// SOFTWARE SPI
ADC081S::ADC081S(uint8_t dataIn, uint8_t clock)
{
_dataIn = dataIn;
_data = dataIn;
_clock = clock;
_select = 255;
_hwSPI = false;
@ -48,12 +48,12 @@ void ADC081S::begin(uint8_t select)
if (_hwSPI) // hardware SPI
{
_mySPI->end();
_mySPI->begin();
// _mySPI->end();
// _mySPI->begin();
}
else // software SPI
{
pinMode(_dataIn, INPUT);
pinMode(_data, INPUT);
pinMode(_clock, OUTPUT);
digitalWrite(_clock, HIGH);
}
@ -165,7 +165,7 @@ void ADC081S::shutDown()
uint16_t ADC081S::swSPI_transfer16(uint16_t m)
{
uint8_t clk = _clock;
uint8_t dai = _dataIn;
uint8_t dai = _data;
uint16_t rv = 0;
for (uint16_t mask = m; mask; mask >>= 1)
@ -187,7 +187,7 @@ ADC101S::ADC101S(__SPI_CLASS__ * mySPI) : ADC081S(mySPI)
_maxValue = 1023;
}
ADC101S::ADC101S(uint8_t dataIn, uint8_t clock) : ADC081S(dataIn, clock)
ADC101S::ADC101S(uint8_t data, uint8_t clock) : ADC081S(data, clock)
{
_maxValue = 1023;
}
@ -207,7 +207,7 @@ ADC121S::ADC121S(__SPI_CLASS__ * mySPI) : ADC081S(mySPI)
_maxValue = 4095;
}
ADC121S::ADC121S(uint8_t dataIn, uint8_t clock) : ADC081S(dataIn, clock)
ADC121S::ADC121S(uint8_t data, uint8_t clock) : ADC081S(data, clock)
{
_maxValue = 4095;
}

View File

@ -2,7 +2,7 @@
//
// FILE: ADC081S.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.2
// VERSION: 0.2.0
// DATE: 2024-01-10
// PURPOSE: Arduino library for ADC081S 8 bit ADC (SPI)
// URL: https://github.com/RobTillaart/ADC081S
@ -13,7 +13,7 @@
#include "SPI.h"
#define ADC081S_LIB_VERSION (F("0.1.2"))
#define ADC081S_LIB_VERSION (F("0.2.0"))
#ifndef __SPI_CLASS__
@ -35,8 +35,8 @@ public:
void begin(uint8_t select);
uint16_t maxValue();
uint16_t read();
uint16_t maxValue();
uint16_t read();
// speed in Hz
void setSPIspeed(uint32_t speed);
@ -51,7 +51,7 @@ public:
bool isLowPower();
protected:
uint8_t _dataIn;
uint8_t _data;
uint8_t _clock;
uint8_t _select;
bool _hwSPI;
@ -80,7 +80,7 @@ class ADC101S : public ADC081S
{
public:
ADC101S(__SPI_CLASS__ * mySPI = &SPI);
ADC101S(uint8_t dataIn, uint8_t clock);
ADC101S(uint8_t data, uint8_t clock);
uint16_t read();
};
@ -89,7 +89,7 @@ class ADC121S : public ADC081S
{
public:
ADC121S(__SPI_CLASS__ * mySPI = &SPI);
ADC121S(uint8_t dataIn, uint8_t clock);
ADC121S(uint8_t data, uint8_t clock);
uint16_t read();
};

View File

@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.2.0] - 2024-01-19
- Fix #5, improve handling SPI dependency.
- align pin names in constructor with datasheet
----
## [0.1.2] - 2024-01-12
- add support for **ADC101S** 10 bit series
- add support for **ADC121S** 12 bit series

View File

@ -35,6 +35,13 @@ The library is not tested with hardware yet.
Feedback is as always welcome.
#### 0.2.0 Breaking change
Version 0.2.0 introduced a breaking change to improve handling the SPI dependency.
The user has to call **SPI.begin()** or equivalent before calling **ADC.begin()**.
Optionally the user can provide parameters to the **SPI.begin(...)**
#### Performance
Although the ADC081S021 is rated at 200 KSPS, an Arduino UNO will not
@ -71,6 +78,7 @@ Type = ADC(bits)(channel)S(speed)1 e.g ADC081S021 = 8 bits 1 channel 200000
#### Related
- https://github.com/RobTillaart/ADC08XS 2 + 4 channel library
- 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)
@ -90,7 +98,7 @@ The ADC101S and ADC121S have an identical interface as the ADC081S.
- **ADC081S(SPIClassRP2040 \* mySPI = &SPI)** hardware constructor RP2040
- **ADC081S(SPIClass \* mySPI = &SPI)** hardware constructor other
- **ADC081S(uint8_t dataOut, uint8_t clock)**
- **ADC081S(uint8_t data, uint8_t clock)**
- **void begin(uint8_t select)** set select pin.
- **int16_t maxValue()** returns maxReading of ADC, => 255, 1023, 4095
depending on number of bits / class.
@ -119,20 +127,20 @@ of the ADC first to get optimal speed.
#### Must
- improve documentation
- get hardware to test
- get hardware to test / verify working
#### Should
- investigate continuous read
- set CS once (or hardwired)
- use a prepared address
- just transfer.
- how much faster?
#### Could
- unit tests possible?
- investigate multichannel series
- ADC122S101 2 channel series
- ADC124S101 4 channel series
- need own (6) classes
- needs channel selection => so need dataout
- need a control byte with channel select (bit 3,4,5)
#### Wont

View File

@ -18,6 +18,7 @@ void setup()
Serial.print("ADC081S_LIB_VERSION: ");
Serial.println(ADC081S_LIB_VERSION);
SPI.begin();
adc01.begin(10);
}

View File

@ -24,6 +24,8 @@ void setup()
Serial.println(ADC081S_LIB_VERSION);
Serial.println();
SPI.begin();
Serial.println("ADC\tMAXVALUE");
Serial.print("adc\t");
Serial.println(adc.maxValue());

View File

@ -7,11 +7,13 @@
#include "ADC081S.h"
ADC081S adc01; // use HWSPI
ADC081S adc02(6, 7); // use SWSPI
uint32_t start, stop;
void setup()
{
Serial.begin(115200);
@ -19,6 +21,7 @@ void setup()
Serial.print("ADC081S_LIB_VERSION: ");
Serial.println(ADC081S_LIB_VERSION);
SPI.begin();
adc01.begin(10);
adc02.begin(5);

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/ADC081S.git"
},
"version": "0.1.2",
"version": "0.2.0",
"license": "MIT",
"frameworks": "*",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=ADC081S
version=0.1.2
version=0.2.0
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for ADC081S 8 bit ADC (SPI).