Skip to content

Commit 36289cc

Browse files
committed
0.1.0 AD7367
1 parent 06866da commit 36289cc

File tree

19 files changed

+756
-0
lines changed

19 files changed

+756
-0
lines changed

libraries/AD7367/.arduino-ci.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
platforms:
2+
rpipico:
3+
board: rp2040:rp2040:rpipico
4+
package: rp2040:rp2040
5+
gcc:
6+
features:
7+
defines:
8+
- ARDUINO_ARCH_RP2040
9+
warnings:
10+
flags:
11+
12+
packages:
13+
rp2040:rp2040:
14+
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
15+
16+
compile:
17+
# Choosing to run compilation tests on 2 different Arduino platforms
18+
platforms:
19+
- uno
20+
# - due
21+
# - zero
22+
# - leonardo
23+
- m4
24+
- esp32
25+
- esp8266
26+
# - mega2560
27+
- rpipico
28+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# These are supported funding model platforms
2+
3+
github: RobTillaart
4+
custom: "https://www.paypal.me/robtillaart"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Arduino-lint
2+
3+
on: [push, pull_request]
4+
jobs:
5+
lint:
6+
runs-on: ubuntu-latest
7+
timeout-minutes: 5
8+
steps:
9+
- uses: actions/checkout@v4
10+
- uses: arduino/arduino-lint-action@v1
11+
with:
12+
library-manager: update
13+
compliance: strict
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Arduino CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
runTest:
7+
runs-on: ubuntu-latest
8+
timeout-minutes: 20
9+
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: ruby/setup-ruby@v1
13+
with:
14+
ruby-version: 2.6
15+
- run: |
16+
gem install arduino_ci
17+
arduino_ci.rb
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: JSON check
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.json'
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
timeout-minutes: 5
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: json-syntax-check
16+
uses: limitusus/json-syntax-check@v2
17+
with:
18+
pattern: "\\.json$"

libraries/AD7367/AD7367.cpp

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
//
2+
// FILE: AD7367.cpp
3+
// AUTHOR: Rob Tillaart
4+
// VERSION: 0.1.0
5+
// DATE: 2025-01-10
6+
// PURPOSE: Arduino library for the AD7367, 2 channel simultaneous sampling 14 bit ADC.
7+
8+
9+
#include "AD7367.h"
10+
11+
12+
AD7367::AD7367(uint8_t select, uint8_t clock, uint8_t convert, uint8_t busy, uint8_t data0, uint8_t data1)
13+
{
14+
_type = 67;
15+
_bits = 14;
16+
_select = select;
17+
_clock = clock;
18+
_convert = convert;
19+
_busy = busy;
20+
_data0 = data0;
21+
_data1 = data1;
22+
}
23+
24+
// sets internal state
25+
void AD7367::begin()
26+
{
27+
pinMode(_select, OUTPUT);
28+
pinMode(_clock, OUTPUT);
29+
pinMode(_convert, OUTPUT);
30+
pinMode(_busy, INPUT);
31+
pinMode(_data0, INPUT);
32+
pinMode(_data1, INPUT);
33+
34+
digitalWrite(_select, HIGH);
35+
digitalWrite(_clock, HIGH);
36+
digitalWrite(_convert, HIGH);
37+
}
38+
39+
40+
uint8_t AD7367::getType()
41+
{
42+
return _type;
43+
}
44+
45+
46+
int AD7367::read()
47+
{
48+
// simulation
49+
// _value[0] = random(16384); // 14 bits = 16383, 12 bits = 4095
50+
// _value[1] = random(16384);
51+
52+
// datasheet page 07 + 20
53+
// trigger conversion
54+
triggerConversion();
55+
// wait for conversion to be done
56+
while (conversionBusy());
57+
return readAsync();
58+
}
59+
60+
61+
void AD7367::triggerConversion()
62+
{
63+
// Trigger conversion by 10 ns pulse.
64+
// might need a delayMicroseconds(1); on very fast processors.
65+
// needs a configuration flag, although checking the flag is already 10 ns.
66+
// Are NOP's portable?
67+
digitalWrite(_convert, LOW);
68+
// delayMicroseconds(1);
69+
digitalWrite(_convert, HIGH);
70+
}
71+
72+
73+
bool AD7367::conversionBusy()
74+
{
75+
return digitalRead(_busy) == HIGH;
76+
}
77+
78+
79+
bool AD7367::conversionReady()
80+
{
81+
return digitalRead(_busy) == LOW;
82+
}
83+
84+
85+
int AD7367::readAsync()
86+
{
87+
digitalWrite(_select, LOW);
88+
// use local variables for clocking
89+
int d0 = 0;
90+
int d1 = 0;
91+
// clock in the bits
92+
for (int i = 0; i < _bits; i++)
93+
{
94+
digitalWrite(_clock, LOW);
95+
digitalWrite(_clock, HIGH);
96+
d0 <<= 1;
97+
d0 |= digitalRead(_data0);
98+
d1 <<= 1;
99+
d1 |= digitalRead(_data1);
100+
}
101+
_value[0] = d0;
102+
_value[1] = d1;
103+
return 0;
104+
}
105+
106+
107+
int AD7367::getValue(uint8_t channel)
108+
{
109+
return _value[channel];
110+
}
111+
112+
113+
int AD7367::getBits()
114+
{
115+
return _bits;
116+
}
117+
118+
119+
//////////////////////////////////////////////////////////////////
120+
//
121+
// PROTECTED
122+
//
123+
124+
125+
126+
/////////////////////////////////////////////////////////////////////////////
127+
//
128+
// DERIVED CLASS AD7366
129+
//
130+
AD7366::AD7366(uint8_t select, uint8_t clock, uint8_t convert, uint8_t busy, uint8_t data0, uint8_t data1)
131+
:AD7367(select, clock, convert, busy, data0, data1)
132+
{
133+
_type = 66;
134+
_bits = 12;
135+
}
136+
137+
138+
// -- END OF FILE --
139+

libraries/AD7367/AD7367.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#pragma once
2+
//
3+
// FILE: AD7367.h
4+
// AUTHOR: Rob Tillaart
5+
// VERSION: 0.1.0
6+
// DATE: 2025-01-10
7+
// PURPOSE: Arduino library for the AD7367, 2 channel simultaneous sampling 14 bit ADC.
8+
// Also AD7366 == 12 bits.
9+
10+
11+
#include "Arduino.h"
12+
13+
#define AD7367_LIB_VERSION (F("0.1.0"))
14+
15+
16+
class AD7367
17+
{
18+
public:
19+
// CONSTRUCTOR
20+
// pins to set.
21+
AD7367(uint8_t select, uint8_t clock, uint8_t convert, uint8_t busy, uint8_t data0, uint8_t data1);
22+
23+
void begin();
24+
uint8_t getType(); // returns 66 or 67
25+
int getBits(); // returns 12 or 14
26+
27+
// READ
28+
int read();
29+
// READ ASYNC
30+
void triggerConversion();
31+
bool conversionBusy();
32+
bool conversionReady();
33+
int readAsync();
34+
// GET VALUE
35+
int getValue(uint8_t channel); // channel = 0 or 1
36+
37+
38+
protected:
39+
uint8_t _type;
40+
uint8_t _bits;
41+
uint8_t _select;
42+
uint8_t _clock;
43+
uint8_t _convert;
44+
uint8_t _busy;
45+
uint8_t _data0;
46+
uint8_t _data1;
47+
int16_t _value[2] = {0, 0};
48+
};
49+
50+
51+
52+
/////////////////////////////////////////////////////////////////////////////
53+
//
54+
// DERIVED CLASS AD7366
55+
//
56+
class AD7366 : public AD7367
57+
{
58+
public:
59+
AD7366(uint8_t select, uint8_t clock, uint8_t convert, uint8_t busy, uint8_t data0, uint8_t data1);
60+
};
61+
62+
63+
// -- END OF FILE --
64+

libraries/AD7367/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Change Log AD7367
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
6+
and this project adheres to [Semantic Versioning](http://semver.org/).
7+
8+
9+
## [0.1.0] - 2025-01-10
10+
- initial version
11+

libraries/AD7367/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025-2025 Rob Tillaart
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)