Skip to contentSkip to conversation

New: MCP3428 scaling values are incorrect, three orders of magnitude low

Bug 220543 [email protected] 2 participants 3 messages Sep 6, 2025 – Sep 28, 2025 IIO

lore
Share & tools
lore
#0 lore raw

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: [email protected]
          Reporter: [email protected]
        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

Signature · 4 lines
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.
maintainer
#1 lore raw
Quoted 17 lines · On Sat, 06 Sep 2025 23:42:16 +0000 [email protected] 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: [email protected]
          Reporter: [email protected]
        Regression: No
Quoted 9 lines

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;

drivers/iio/adc/mcp3422.c +1 -1
index 50834fdcf738..2bdf14f337ec 100644
@@ -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

#2 lore raw

[Bug 220543] MCP3428 scaling values are incorrect, three orders of magnitude low

In reply to [email protected]

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

--- Comment #1 from Jonathan Cameron ([email protected]) ---

Quoted 21 lines · On Sat, 06 Sep 2025 23:42:16 +0000 [email protected] 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: [email protected]
          Reporter: [email protected]
        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.

Quoted 6 lines

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;

drivers/iio/adc/mcp3422.c +1 -1
index 50834fdcf738..2bdf14f337ec 100644
@@ -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

Signature · 4 lines
You may reply to this email to add a comment.

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