patch "iio: adc: mcp3911: use correct formula for AD conversion" added to char-misc-linus
Subsystems (3)
This is a note to let you know that I've just added the patch titled
iio: adc: mcp3911: use correct formula for AD conversion
to my char-misc git tree which can be found at
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git
in the char-misc-linus branch.
The patch will show up in the next release of the linux-next tree (usually sometime within the next 24 hours during the week.)
The patch will hopefully also be merged in Linus's tree for the next -rc kernel release.
If you have any questions about this process, please let me know.
From 9e2238e3ae40d371a1130226e0e740aa1601efa6 Mon Sep 17 00:00:00 2001
From: Marcus Folkesson <[email protected]>
Date: Fri, 22 Jul 2022 15:07:20 +0200
Subject: iio: adc: mcp3911: use correct formula for AD conversion
The ADC conversion is actually not rail-to-rail but with a factor 1.5. Make use of this factor when calculating actual voltage.
--- drivers/iio/adc/mcp3911.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/iio/adc/mcp3911.c +12 -5
@@ -40,8 +40,8 @@#define MCP3911_CHANNEL (x) (MCP3911_REG_CHANNEL0 + x * 3)#define MCP3911_OFFCAL (x) (MCP3911_REG_OFFCAL_CH0 + x * 6) -/* Internal voltage reference in uV */ -#define MCP3911_INT_VREF_UV 1200000 +/* Internal voltage reference in mV */ +#define MCP3911_INT_VREF_MV 1200#define MCP3911_REG_READ (reg, id) ((((reg) << 1) | ((id) << 5) | (1 << 0)) & 0xff)#define MCP3911_REG_WRITE (reg, id) ((((reg) << 1) | ((id) << 5) | (0 << 0)) & 0xff)
@@ -139,11 +139,18 @@ static int mcp3911_read_raw(struct iio_dev *indio_dev, *val = ret /1000 ; }else { - *val =MCP3911_INT_VREF_UV ; + *val =MCP3911_INT_VREF_MV ; } - *val2 =24 ; - ret =IIO_VAL_FRACTIONAL_LOG2 ; +/* +* For 24bit Conversion +* Raw = ((Voltage)/(Vref) * 2^23 * Gain * 1.5 +* Voltage = Raw * (Vref)/(2^23 * Gain * 1.5) +*/ + +/* val2 = (2^23 * 1.5) */ + *val2 =12582912 ; + ret =IIO_VAL_FRACTIONAL ;break ; }
Signature · 1 line
2.37.2