public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
From: bugzilla-daemon@kernel.org
To: linux-iio@vger.kernel.org
Subject: [Bug 220543] MCP3428 scaling values are incorrect, three orders of magnitude low
Date: Sun, 28 Sep 2025 10:59:42 +0000	[thread overview]
Message-ID: <bug-220543-217253-oOEqOx899T@https.bugzilla.kernel.org/> (raw)
In-Reply-To: <bug-220543-217253@https.bugzilla.kernel.org/>

https://bugzilla.kernel.org/show_bug.cgi?id=220543

--- Comment #1 from Jonathan Cameron (jic23@kernel.org) ---
On Sat, 06 Sep 2025 23:42:16 +0000
bugzilla-daemon@kernel.org wrote:

> https://bugzilla.kernel.org/show_bug.cgi?id=220543
> 
>             Bug ID: 220543
>            Summary: MCP3428 scaling values are incorrect, three orders of
>                     magnitude low
>            Product: Drivers
>            Version: 2.5
>           Hardware: All
>                 OS: Linux
>             Status: NEW
>           Severity: normal
>           Priority: P3
>          Component: IIO
>           Assignee: drivers_iio@kernel-bugs.kernel.org
>           Reporter: phil@munts.net
>         Regression: No
> 
> The values for in_voltageY_scale that the 6.12 kernel generates for the
> MCP3428
> ADC are too low by a factor of 1000.
> 
> The ADS1115 and the MCP3204 get in_voltageY_scale values around 1.0 (implying
> millivolts per ADC step) while the MCP3428 gets values around 0.001 and lower
> (implying microvolts per ADC step).
> 
> See also: https://forums.raspberrypi.com/viewtopic.php?t=391674
> 
Optimistic +CC of Angelo (it's been a few years!)

As a sanity check, if you can rebuild your driver, could you try;
diff --git a/drivers/iio/adc/mcp3422.c b/drivers/iio/adc/mcp3422.c
index 50834fdcf738..2bdf14f337ec 100644
--- a/drivers/iio/adc/mcp3422.c
+++ b/drivers/iio/adc/mcp3422.c
@@ -178,7 +178,7 @@ static int mcp3422_read_raw(struct iio_dev *iio,

                *val1 = 0;
                *val2 = mcp3422_scales[sample_rate][pga];
-               return IIO_VAL_INT_PLUS_NANO;
+               return IIO_VAL_INT_PLUS_MICRO;

        case IIO_CHAN_INFO_SAMP_FREQ:
                *val1 = mcp3422_sample_rates[MCP3422_SAMPLE_RATE(adc->config)];

It's a bit of a hack for the largest scale as we should really represent that
as *val1 = 1, *val2 = 0 rather than *val2 = 1000000 but meh - I'll spin a nicer
fix if this works.

Working through the scaling. It's a mix of resolution, 12->18, vref = +-2.048V,
and PGA, 1->8x

The docs rather confusingly give LSB values for 12 bits of 1mV etc but those
are post PGA.   PGA increasing is equivalent of reducing the vref, so results
in lower values.

So agreed with your discovery - this seems to be out by a factor of 1000.

Thanks for the report.  Hopefully Angelo can take a look, but if not I'll try
and spin a fix. If you can test the above that would be a great start.

Thanks,

Jonathan

-- 
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.

      parent reply	other threads:[~2025-09-28 10:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-06 23:42 [Bug 220543] New: MCP3428 scaling values are incorrect, three orders of magnitude low bugzilla-daemon
2025-09-28 10:59 ` Jonathan Cameron
2025-09-28 10:59 ` bugzilla-daemon [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-220543-217253-oOEqOx899T@https.bugzilla.kernel.org/ \
    --to=bugzilla-daemon@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox