linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Bug 220543] New: MCP3428 scaling values are incorrect, three orders of magnitude low
@ 2025-09-06 23:42 bugzilla-daemon
  2025-09-28 10:59 ` Jonathan Cameron
  2025-09-28 10:59 ` [Bug 220543] " bugzilla-daemon
  0 siblings, 2 replies; 3+ messages in thread
From: bugzilla-daemon @ 2025-09-06 23:42 UTC (permalink / raw)
  To: linux-iio

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

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

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Bug 220543] New: MCP3428 scaling values are incorrect, three orders of magnitude low
  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 ` [Bug 220543] " bugzilla-daemon
  1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2025-09-28 10:59 UTC (permalink / raw)
  To: bugzilla-daemon; +Cc: linux-iio, Angelo Compagnucci

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



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [Bug 220543] MCP3428 scaling values are incorrect, three orders of magnitude low
  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
  1 sibling, 0 replies; 3+ messages in thread
From: bugzilla-daemon @ 2025-09-28 10:59 UTC (permalink / raw)
  To: linux-iio

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.

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-09-28 10:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [Bug 220543] " bugzilla-daemon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).