0.1.9 MCP_ADC

This commit is contained in:
rob tillaart 2022-11-17 13:00:17 +01:00
parent a3e2c91f94
commit 531c273094
9 changed files with 221 additions and 75 deletions

View File

@ -1,3 +1,18 @@
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:
@ -9,3 +24,4 @@ compile:
- esp32
# - esp8266
# - mega2560
- rpipico

View File

@ -0,0 +1,39 @@
# Change Log MCP_ADC
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.9] - 2022-11-16
- add RP2040 in build-CI
- add changelog.md
- minor edit readme.md
- clean up unit test
## [0.1.8] - 2021-12-21
- update library.json
- update license
- minor edits
----
## [0.1.7] - 2021-11-07
## [0.1.6] - 2021-08-01
## [0.1.5] - 2021-07-31
## [0.1.4] - 2021-03-31
## [0.1.3] - 2021-02-04
## [0.1.2] - 2021-01-01
## [0.1.1] - 2020-08-14
## [0.1.0] - 2019-10-24
- initial version.

View File

@ -1,7 +1,7 @@
//
// FILE: MCP_ADC.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.8
// VERSION: 0.1.9
// DATE: 2019-10-24
// PURPOSE: Arduino library for MCP3002, MCP3004, MCP3008, MCP3202, MCP3204, MCP3208
// URL: https://github.com/RobTillaart/MCP_ADC
@ -274,7 +274,7 @@ uint8_t MCP3204::buildRequest(uint8_t channel, bool single, uint8_t * data)
// P21 fig 6.1 MCP3204/3208
data[0] = 0x04; // start bit
if (single) data[0] |= 0x02; // single read | differential
if (channel > 3) data[0] |= 0x01; // msb channel (D2)
if (channel > 3) data[0] |= 0x01; // MSB channel (D2)
if (channel) data[1] |= (channel << 6); // other 2 bits (D1 D0)
return 3;
}
@ -296,7 +296,7 @@ uint8_t MCP3208::buildRequest(uint8_t channel, bool single, uint8_t * data)
// P21 fig 6.1 MCP3204/3208
data[0] = 0x04; // start bit
if (single) data[0] |= 0x02; // single read | differential
if (channel > 3) data[0] |= 0x01; // msb channel (D2)
if (channel > 3) data[0] |= 0x01; // MSB channel (D2)
if (channel) data[1] |= (channel << 6); // other 2 bits (D1 D0)
return 3;
}

View File

@ -2,7 +2,7 @@
//
// FILE: MCP_ADC.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.8
// VERSION: 0.1.9
// DATE: 2019-10-24
// PURPOSE: Arduino library for MCP_ADC
// URL: https://github.com/RobTillaart/MCP_ADC
@ -13,7 +13,7 @@
#include "SPI.h"
#define MCP_ADC_LIB_VERSION (F("0.1.8"))
#define MCP_ADC_LIB_VERSION (F("0.1.9"))
class MCP_ADC
@ -59,7 +59,7 @@ protected:
int16_t _maxValue;
uint32_t _SPIspeed = 1000000; // 1 MHz is a safe value (datasheet); in a test 4 MHz worked.
// derived classes must implement this one
// derived classes must implement buildRequest() function.
virtual uint8_t buildRequest(uint8_t channel, bool single, uint8_t * data) = 0;
int16_t readADC(uint8_t channel, bool single);
@ -75,9 +75,11 @@ protected:
uint32_t _count;
};
/////////////////////////////////////////////////////////////////////////////
//
// DERIVED CLASSES
//
class MCP3002 : public MCP_ADC
{
public:
@ -85,6 +87,7 @@ public:
uint8_t buildRequest(uint8_t channel, bool single, uint8_t * data);
};
class MCP3004 : public MCP_ADC
{
public:
@ -92,6 +95,7 @@ public:
uint8_t buildRequest(uint8_t channel, bool single, uint8_t * data);
};
class MCP3008 : public MCP_ADC
{
public:

View File

@ -134,10 +134,22 @@ which indicates that the last 2 bits got lost due to signal deformation.
For hardware SPI the ESP32 uses the VSPI pins. (see ESP examples).
## Operations
See examples.
## Future
#### must
- documentation
- testing, a lot ...
#### should
#### could
- analogRead (mask, int array\[8\] ) read ports (set in mask) in an array in one call.
would this save time?
@ -146,9 +158,5 @@ For hardware SPI the ESP32 uses the VSPI pins. (see ESP examples).
- get / setF(float A, float B) => float readF(channel) output = A\*value + B;
it actually does float mapping. As it implies the same mapping for all it might
not be that useful => multmap
not be that useful => multimap
## Operations
See examples.

View File

@ -81,6 +81,24 @@ void setup()
test_3();
}
// on UNO there is no difference above 8MHz (half CPU clock)
Serial.println("***************************************\n");
for (int s = 1; s <= 16; s *= 2)
{
Serial.println(s * 1000000UL);
mcp22.setSPIspeed(s * 1000000UL);
test_4();
}
// on UNO there is no difference above 8MHz (half CPU clock)
Serial.println("***************************************\n");
for (int s = 1; s <= 16; s *= 2)
{
Serial.println(s * 1000000UL);
mcp24.setSPIspeed(s * 1000000UL);
test_5();
}
// on UNO there is no difference above 8MHz (half CPU clock)
Serial.println("***************************************\n");
for (int s = 1; s <= 16; s *= 2)
@ -210,6 +228,80 @@ void test_3()
}
void test_4()
{
uint32_t val = 0;
start = micros();
for (int channel = 0; channel < mcp22.channels(); channel++)
{
val += mcp22.analogRead(channel);
}
stop = micros();
Serial.print("mcp22.analogRead()\t2x: \t");
Serial.println(stop - start);
delay(10);
start = micros();
for (int channel = 0; channel < mcp22.channels(); channel++)
{
val += mcp22.differentialRead(channel);
}
stop = micros();
Serial.print("mcp22.differentialRead() 2x: \t");
Serial.println(stop - start);
delay(10);
start = micros();
for (int channel = 0; channel < mcp22.channels(); channel++)
{
val += mcp22.deltaRead(channel);
}
stop = micros();
Serial.print("mcp22.deltaRead()\t2x: \t");
Serial.println(stop - start);
Serial.println();
delay(10);
}
void test_5()
{
uint32_t val = 0;
start = micros();
for (int channel = 0; channel < mcp24.channels(); channel++)
{
val += mcp24.analogRead(channel);
}
stop = micros();
Serial.print("mcp24.analogRead()\t4x: \t");
Serial.println(stop - start);
delay(10);
start = micros();
for (int channel = 0; channel < mcp24.channels(); channel++)
{
val += mcp24.differentialRead(channel);
}
stop = micros();
Serial.print("mcp24.differentialRead() 4x: \t");
Serial.println(stop - start);
delay(10);
start = micros();
for (int channel = 0; channel < mcp24.channels(); channel++)
{
val += mcp24.deltaRead(channel);
}
stop = micros();
Serial.print("mcp24.deltaRead()\t4x: \t");
Serial.println(stop - start);
Serial.println();
delay(10);
}
void test_6()
{
uint32_t val = 0;

View File

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

View File

@ -1,5 +1,5 @@
name=MCP_ADC
version=0.1.8
version=0.1.9
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for MCP3002, MCP3004, MCP3008, MCP3202, MCP3204, MCP3208

View File

@ -47,19 +47,6 @@ unittest_teardown()
}
/*
unittest(test_new_operator)
{
assertEqualINF(exp(800));
assertEqualINF(0.0/0.0);
assertEqualINF(42);
assertEqualNAN(INFINITY - INFINITY);
assertEqualNAN(0.0/0.0);
assertEqualNAN(42);
}
*/
unittest(test_constructor)
{
MCP3002 ADC2;