* [PATCH V2] staging:iio:ad7606: fix voltage scales
@ 2018-09-13 8:44 Alexandru Ardelean
2018-09-16 11:12 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: Alexandru Ardelean @ 2018-09-13 8:44 UTC (permalink / raw)
To: linux-iio, Michael.Hennerich, lars, jic23
Cc: knaack.h, pmeerw, Alexandru Ardelean
Fixes commit 17be2a2905a6ec9aa27cd59521495e2f490d2af0 ("staging: iio:
ad7606: replace range/range_available with corresponding scale").
The AD7606 devices don't have a 2.5V voltage range, they have 5V & 10V
voltage range, which is selectable via the `gpio_range` descriptor.
The scales also seem to have been miscomputed, because when they were
applied to the raw values, the results differ from the expected values.
After checking the ADC transfer function in the datasheet, these were
re-computed.
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
Changelog V1 -> V2:
* changed 2.5/2**16 and 5/2**16 -> 5000/32768 and 10000/32768, because
my computation of 32768 in power of 2 is also wrong; it's 2**15, not 2**16
and the datasheet mentions 32768, so use that value
drivers/staging/iio/adc/ad7606.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
index c5fe3003075b..87d5fb073c95 100644
--- a/drivers/staging/iio/adc/ad7606.c
+++ b/drivers/staging/iio/adc/ad7606.c
@@ -26,9 +26,11 @@
#include "ad7606.h"
-/* Scales are computed as 2.5/2**16 and 5/2**16 respectively */
+/* Scales are computed as 5000/32768 and 10000/32768 respectively,
+ * so that when applied to the raw values they provide mV values
+ */
static const unsigned int scale_avail[2][2] = {
- {0, 38147}, {0, 76294}
+ {0, 152588}, {0, 305176}
};
static int ad7606_reset(struct ad7606_state *st)
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH V2] staging:iio:ad7606: fix voltage scales
2018-09-13 8:44 [PATCH V2] staging:iio:ad7606: fix voltage scales Alexandru Ardelean
@ 2018-09-16 11:12 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2018-09-16 11:12 UTC (permalink / raw)
To: Alexandru Ardelean; +Cc: linux-iio, Michael.Hennerich, lars, knaack.h, pmeerw
On Thu, 13 Sep 2018 11:44:09 +0300
Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:
> Fixes commit 17be2a2905a6ec9aa27cd59521495e2f490d2af0 ("staging: iio:
> ad7606: replace range/range_available with corresponding scale").
>
> The AD7606 devices don't have a 2.5V voltage range, they have 5V & 10V
> voltage range, which is selectable via the `gpio_range` descriptor.
>
> The scales also seem to have been miscomputed, because when they were
> applied to the raw values, the results differ from the expected values.
> After checking the ADC transfer function in the datasheet, these were
> re-computed.
>
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
On thing inline.
Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.
Thanks,
Jonathan
> ---
>
> Changelog V1 -> V2:
> * changed 2.5/2**16 and 5/2**16 -> 5000/32768 and 10000/32768, because
> my computation of 32768 in power of 2 is also wrong; it's 2**15, not 2**16
> and the datasheet mentions 32768, so use that value
>
> drivers/staging/iio/adc/ad7606.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
> index c5fe3003075b..87d5fb073c95 100644
> --- a/drivers/staging/iio/adc/ad7606.c
> +++ b/drivers/staging/iio/adc/ad7606.c
> @@ -26,9 +26,11 @@
>
> #include "ad7606.h"
>
> -/* Scales are computed as 2.5/2**16 and 5/2**16 respectively */
This isn't a kernel comment style. I'll fix up.
> +/* Scales are computed as 5000/32768 and 10000/32768 respectively,
> + * so that when applied to the raw values they provide mV values
> + */
> static const unsigned int scale_avail[2][2] = {
> - {0, 38147}, {0, 76294}
> + {0, 152588}, {0, 305176}
> };
>
> static int ad7606_reset(struct ad7606_state *st)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-09-16 16:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-09-13 8:44 [PATCH V2] staging:iio:ad7606: fix voltage scales Alexandru Ardelean
2018-09-16 11:12 ` Jonathan Cameron
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).