mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-19 16:46:11 -04:00
0.1.8 MCP_ADC
This commit is contained in:
parent
14b6317b3e
commit
8bb9dc6954
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019-2021 Rob Tillaart
|
||||
Copyright (c) 2019-2022 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
|
||||
|
@ -1,11 +1,10 @@
|
||||
//
|
||||
// FILE: MCP_ADC.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.7
|
||||
// VERSION: 0.1.8
|
||||
// DATE: 2019-10-24
|
||||
// PURPOSE: Arduino library for MCP3002, MCP3004, MCP3008, MCP3202, MCP3204, MCP3208
|
||||
// URL: https://github.com/RobTillaart/MCP_ADC
|
||||
//
|
||||
|
||||
|
||||
#include "MCP_ADC.h"
|
||||
@ -304,3 +303,4 @@ uint8_t MCP3208::buildRequest(uint8_t channel, bool single, uint8_t * data)
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: MCP_ADC.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.7
|
||||
// VERSION: 0.1.8
|
||||
// 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.7"))
|
||||
#define MCP_ADC_LIB_VERSION (F("0.1.8"))
|
||||
|
||||
|
||||
class MCP_ADC
|
||||
|
@ -120,30 +120,35 @@ The default SPI speed is reduced to 1 MHz.
|
||||
This is the value recommended in the datasheet for 2.7V.
|
||||
|
||||
In a test with an ESP32 (3.3V) the library showed stable results
|
||||
at 4 Mhz and at 6 Mhz it was almost good.
|
||||
at 4 MHz and at 6 MHz it was almost good.
|
||||
|
||||
The max value read at 6 MHz was 1020 instead of 1023 (MCP3008)
|
||||
which indicates that the last 2 bits got lost due to signal deformation.
|
||||
|
||||
| Board | Voltage | safe | max |
|
||||
|:-----:|:-------:|:------:|:-----:|
|
||||
| ESP32 | 2.7V | 1 MHz | 4 Mhz |
|
||||
| UNO | 5.0V | 2 MHz | 4 Mhz |
|
||||
| ESP32 | 2.7V | 1 MHz | 4 MHz |
|
||||
| UNO | 5.0V | 2 MHz | 4 MHz |
|
||||
|
||||
|
||||
For hardware SPI the ESP32 uses the VSPI pins. (see ESP examples).
|
||||
|
||||
|
||||
## Future / ideas / improvements
|
||||
## Future
|
||||
|
||||
- documentation
|
||||
- testing, a lot ...
|
||||
- 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
|
||||
- analogRead (mask, int array\[8\] ) read ports (set in mask) in an array in one call.
|
||||
would this save time?
|
||||
|
||||
|
||||
#### wont
|
||||
|
||||
- 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
|
||||
|
||||
|
||||
## Operations
|
||||
|
||||
See examples.
|
||||
|
@ -1,15 +1,16 @@
|
||||
//
|
||||
// FILE: MCP3002_analogRead.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// PURPOSE: demo
|
||||
// DATE: 2020-08-13
|
||||
|
||||
|
||||
#include "MCP_ADC.h"
|
||||
|
||||
MCP3002 mcp1; // use HWSPI
|
||||
MCP3002 mcp2(6, 7); // use SWSPI
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@ -30,6 +31,7 @@ void setup()
|
||||
Serial.println(mcp2.maxValue());
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.print("mcp1:\t");
|
||||
@ -52,4 +54,6 @@ void loop()
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,15 +1,16 @@
|
||||
//
|
||||
// FILE: MCP3002_deltaRead.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// PURPOSE: demo
|
||||
// DATE: 2020-08-13
|
||||
|
||||
|
||||
#include "MCP_ADC.h"
|
||||
|
||||
MCP3002 mcp1; // use HWSPI
|
||||
MCP3002 mcp2(6, 7); // use SWSPI
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@ -30,6 +31,7 @@ void setup()
|
||||
Serial.println(mcp2.maxValue());
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.print("mcp1:\t");
|
||||
@ -52,4 +54,6 @@ void loop()
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,15 +1,16 @@
|
||||
//
|
||||
// FILE: MCP3002_differentialRead.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// PURPOSE: demo
|
||||
// DATE: 2020-08-13
|
||||
|
||||
|
||||
#include "MCP_ADC.h"
|
||||
|
||||
MCP3002 mcp1; // use HWSPI
|
||||
MCP3002 mcp2(6, 7); // use SWSPI
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@ -30,6 +31,7 @@ void setup()
|
||||
Serial.println(mcp2.maxValue());
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.print("mcp1:\t");
|
||||
@ -52,4 +54,6 @@ void loop()
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,15 +1,16 @@
|
||||
//
|
||||
// FILE: MCP3008_analogRead.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// PURPOSE: demo
|
||||
// DATE: 2020-08-13
|
||||
|
||||
|
||||
#include "MCP_ADC.h"
|
||||
|
||||
MCP3008 mcp1; // use HWSPI
|
||||
MCP3004 mcp2(6, 7); // use SWSPI
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@ -30,6 +31,7 @@ void setup()
|
||||
Serial.println(mcp2.maxValue());
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.print("mcp1:\t");
|
||||
@ -52,4 +54,6 @@ void loop()
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,23 +1,23 @@
|
||||
//
|
||||
// FILE: MCP3008_analogRead_ESP32_HWSPI.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo
|
||||
// DATE: 2021-03-12
|
||||
|
||||
|
||||
#include "MCP_ADC.h"
|
||||
|
||||
|
||||
// ESP32 PINS
|
||||
// For HSPI
|
||||
// CLK: 14
|
||||
// MOSI: 13
|
||||
// MISO: 12
|
||||
// CLK: 14
|
||||
// MOSI: 13
|
||||
// MISO: 12
|
||||
//
|
||||
// For VSPI (id = 2):
|
||||
// CLK: 18,
|
||||
// MOSI: 23,
|
||||
// MISO: 19,
|
||||
// CLK: 18,
|
||||
// MOSI: 23,
|
||||
// MISO: 19,
|
||||
|
||||
|
||||
MCP3008 mcp1; // use HWSPI on ESP32 (apparently VSPI)
|
||||
@ -42,6 +42,7 @@ void setup()
|
||||
mcp1.setSPIspeed(4000000); // seems to be the max speed. use 1MHz (default) to be safe
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.print(millis());
|
||||
@ -58,4 +59,6 @@ void loop()
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,23 +1,23 @@
|
||||
//
|
||||
// FILE: MCP3008_analogRead_ESP32_SWSPI.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo
|
||||
// DATE: 2021-03-12
|
||||
|
||||
|
||||
#include "MCP_ADC.h"
|
||||
|
||||
|
||||
// ESP32 PINS
|
||||
// For HSPI
|
||||
// CLK: 14
|
||||
// MOSI: 13
|
||||
// MISO: 12
|
||||
// CLK: 14
|
||||
// MOSI: 13
|
||||
// MISO: 12
|
||||
//
|
||||
// For VSPI (id = 2):
|
||||
// CLK: 18,
|
||||
// MOSI: 23,
|
||||
// MISO: 19,
|
||||
// CLK: 18,
|
||||
// MOSI: 23,
|
||||
// MISO: 19,
|
||||
|
||||
|
||||
MCP3008 mcp1(23, 19, 21); // ESP32 use SWSPI dataIn, dataOut, Clock
|
||||
@ -40,6 +40,7 @@ void setup()
|
||||
Serial.println(mcp1.maxValue());
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.print(millis());
|
||||
@ -56,4 +57,6 @@ void loop()
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,15 +1,16 @@
|
||||
//
|
||||
// FILE: MCP3008_deltaRead.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// PURPOSE: demo
|
||||
// DATE: 2020-08-13
|
||||
|
||||
|
||||
#include "MCP_ADC.h"
|
||||
|
||||
MCP3008 mcp1; // use HWSPI
|
||||
MCP3004 mcp2(6, 7); // use SWSPI
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@ -30,6 +31,7 @@ void setup()
|
||||
Serial.println(mcp2.maxValue());
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.print("mcp1:\t");
|
||||
@ -52,4 +54,6 @@ void loop()
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,15 +1,16 @@
|
||||
//
|
||||
// FILE: MCP3008_differentialRead.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// PURPOSE: demo
|
||||
// DATE: 2020-08-13
|
||||
|
||||
|
||||
#include "MCP_ADC.h"
|
||||
|
||||
MCP3008 mcp1; // use HWSPI
|
||||
MCP3004 mcp2(6, 7); // use SWSPI
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@ -30,6 +31,7 @@ void setup()
|
||||
Serial.println(mcp2.maxValue());
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.print("mcp1:\t");
|
||||
@ -52,4 +54,6 @@ void loop()
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,13 +1,12 @@
|
||||
//
|
||||
// FILE: MCP_ADC_performance.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// PURPOSE: simple performance measurement.
|
||||
// DATE: 2020-08-14
|
||||
|
||||
// Note the deltaRead() does 1 or 2 differential reads depending
|
||||
// on positive of negative delta between 2 pins.
|
||||
// Therefor timing might differ substantially.
|
||||
//
|
||||
// Note the deltaRead() does 1 or 2 differential reads depending
|
||||
// on positive of negative delta between 2 pins.
|
||||
// Therefore timing might differ substantially.
|
||||
|
||||
|
||||
#include "MCP_ADC.h"
|
||||
@ -22,6 +21,7 @@ MCP3208 mcp28;
|
||||
|
||||
uint32_t start, stop;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@ -93,10 +93,12 @@ void setup()
|
||||
Serial.println("done...");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void test_1()
|
||||
{
|
||||
uint32_t val = 0;
|
||||
@ -133,6 +135,7 @@ void test_1()
|
||||
delay(10);
|
||||
}
|
||||
|
||||
|
||||
void test_2()
|
||||
{
|
||||
uint32_t val = 0;
|
||||
@ -169,6 +172,7 @@ void test_2()
|
||||
delay(10);
|
||||
}
|
||||
|
||||
|
||||
void test_3()
|
||||
{
|
||||
uint32_t val = 0;
|
||||
@ -205,6 +209,7 @@ void test_3()
|
||||
delay(10);
|
||||
}
|
||||
|
||||
|
||||
void test_6()
|
||||
{
|
||||
uint32_t val = 0;
|
||||
@ -243,3 +248,4 @@ void test_6()
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -15,8 +15,9 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/MCP_ADC.git"
|
||||
},
|
||||
"version": "0.1.7",
|
||||
"version": "0.1.8",
|
||||
"license": "MIT",
|
||||
"frameworks": "*",
|
||||
"platforms": "*"
|
||||
"platforms": "*",
|
||||
"headers": "MCP_ADC.h"
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=MCP_ADC
|
||||
version=0.1.7
|
||||
version=0.1.8
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for MCP3002, MCP3004, MCP3008, MCP3202, MCP3204, MCP3208
|
||||
|
@ -38,12 +38,15 @@
|
||||
|
||||
unittest_setup()
|
||||
{
|
||||
fprintf(stderr, "MCP_ADC_LIB_VERSION: %s\n", (char *) MCP_ADC_LIB_VERSION);
|
||||
}
|
||||
|
||||
|
||||
unittest_teardown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
unittest(test_new_operator)
|
||||
{
|
||||
@ -59,8 +62,6 @@ unittest(test_new_operator)
|
||||
|
||||
unittest(test_constructor)
|
||||
{
|
||||
fprintf(stderr, "VERSION: %s\n", "-");
|
||||
|
||||
MCP3002 ADC2;
|
||||
MCP3004 ADC4;
|
||||
MCP3008 ADC8;
|
||||
@ -90,6 +91,7 @@ unittest(test_constructor)
|
||||
assertEqual(4095, ADC28.maxValue());
|
||||
}
|
||||
|
||||
|
||||
unittest(test_MCP3002)
|
||||
{
|
||||
MCP3002 mcp_adc;
|
||||
@ -113,6 +115,8 @@ unittest(test_MCP3002)
|
||||
|
||||
}
|
||||
|
||||
|
||||
unittest_main()
|
||||
|
||||
|
||||
// --------
|
||||
|
Loading…
Reference in New Issue
Block a user