8 #define div_round(n,d) (((n) + ((d) >> 2)) / (d)) 50 uint32_t t1 = micros();
52 for (uint16_t i = 0; i < num; i++)
execute(cmd);
54 uint32_t t2 = micros();
68 uint32_t t1 = micros();
70 for (uint16_t i = 0; i < num; i++) {
72 delayMicroseconds(delay);
75 uint32_t t2 = micros();
84 return (static_cast<uint32_t>(raw) *
mVref) / (
kRes - 1);
90 return (static_cast<uint32_t>(val) * (
kRes - 1)) /
mVref;
102 return (static_cast<uint32_t>(
mVref) * 1000) / (
kRes - 1);
105 template <
typename T>
109 uint32_t splTime =
div_round(1000000000, splFreq);
115 int16_t delay = (splTime -
mSplSpeed) / 1000;
116 return (delay < 0) ? 0 :
static_cast<uint16_t
>(delay);
134 .value =
static_cast<uint16_t
>((0x0120 | (ch << 6)))
146 .value =
static_cast<uint16_t
>((0x0400 | (ch << 6)))
158 .value =
static_cast<uint16_t
>((0x0400 | (ch << 6)))
186 template <
typename T>
192 digitalWrite(
mCsPin, LOW);
200 digitalWrite(
mCsPin, HIGH);
204 return (adc.
value >> 1);
207 template <
typename T>
213 digitalWrite(
mCsPin, LOW);
223 digitalWrite(
mCsPin, HIGH);
uint16_t read(Channel ch) const
uint16_t getAnalogRes() const
uint16_t toDigital(uint16_t val) const
uint16_t execute(Command< Channel > cmd) const
MCP320x(uint16_t vref, uint8_t csPin, SPIClass *spi)
uint16_t toAnalog(uint16_t raw) const
MCP320xTypes::MCP3202::Channel MCP3202Ch
MCP320xTypes::MCP3204::Channel MCP3204Ch
static const uint16_t kRes
uint32_t testSplSpeed(Channel ch) const
MCP320xTypes::MCP3208::Channel MCP3208Ch
void calibrate(Channel ch)
MCP320xTypes::MCP3201::Channel MCP3201Ch
static Command< Channel > createCmd(Channel ch)
uint16_t getSplDelay(Channel ch, uint32_t splFreq)
uint16_t transfer() const