RobTillaart / MCP3424

Arduino library for 18 bit ADC I2C MCP3424 and compatibles.
MIT License
2 stars 0 forks source link

65ms delay needed between setChannel and next readout. #4

Open FunDeckHermit opened 2 hours ago

FunDeckHermit commented 2 hours ago

This is not really a bug, more of a general tip for anyone struggling to change channels on the MCP3428 with this library. You need a delay of around 65ms between setting a channel and reading the value.

RobTillaart commented 2 hours ago

Thanks for reporting this issue.

Can you pinpoint the place in the datasheet where this is mentioned?

This should be in the documentation / comments .h file in my opinion. It would not be nice to block for 65 milliseconds.

Would you like a function like readyForRead() to check the last channel switch? Track timestamp of last channel switch (real change only so switching twice to channel 0 is no switch. and single channel> Think that is a bit overkill

RobTillaart commented 2 hours ago

Think the best place is to mention it near the Resolution and SPS (samples per second) as the 65 ms is about the time when getting 15 SPS => 66.6 ms

something like this

Bits LSB (gain=1) SPS Interval Raw range Notes
12 1 mV 240 4.2 ms -2048 .. 2047
14 250 µV 60 16.7 ms -8192 .. 8191
16 62.5 µV 15 66.7 ms -32768 .. 32767
18 15.625 µV 3.75 266.7 ms -131072 .. 131071 not for 3426/27/28.
RobTillaart commented 1 hour ago

@FunDeckHermit

Can you run MCP3424_performance.ino and post output + board used? (patched for your ADC of course).

FunDeckHermit commented 1 hour ago

Hi Rob,

The 65ms was empirically deduced by adding delays everywhere in my code and reducing/removing them gradually.

I'm running on 16bit resolution so the SPS of 15 seems like the culprit here.

Maybe add an example where you start a timer that waits 70ms for the read()? To show inexperienced programmers what would be best practice.

In my case I'm running on an ESP32 in a task, delays are actually just task switchers.

Next Tuesday I'm back at the office to test the performance.ino. Do you have the MCP3428 laying around? I can send you a breadboard friendly module if you happen to live in The Netherlands.

RobTillaart commented 38 minutes ago

Maybe add an example where you start a timer that waits 70ms for the read()? To show inexperienced programmers what would be best practice.

Good idea,

Do you have the MCP3428 laying around? I can send you a breadboard friendly module if you happen to live in The Netherlands.

No, Yes would be appreciated!

My email is rob.tillaart@gmail.com, please mail me for my address.