Linux-IIO Archive mirror
 help / color / mirror / Atom feed
From: Peter Rosin <peda@axentia.se>
To: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
Cc: "João Paulo Gonçalves" <jpaulo.silvagoncalves@gmail.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	joao.goncalves@toradex.com
Subject: Re: Supporting a Device with Switchable Current/Voltage Measurement
Date: Thu, 2 May 2024 18:43:01 +0200	[thread overview]
Message-ID: <00a0aa99-b33e-b3a4-594d-36685d138a05@axentia.se> (raw)
In-Reply-To: <20240502160938.00007691@Huawei.com>



2024-05-02 at 17:09, Jonathan Cameron wrote:
> On Thu, 2 May 2024 16:05:45 +0200
> Peter Rosin <peda@axentia.se> wrote:
> 
>> 2024-05-02 at 15:49, Peter Rosin wrote:
>>> Since you appear to need to change both the gpio pin and the io-channel, the
>>> mux isn't a perfect fit. The closest you can get with the current code is to
>>> create a gpio mux, I think. You would then use that mux twice to fan out both
>>> io-channels, but only expose the "left leg" on the first fan-out and only the
>>> "right leg" on the other. Something like this (untested, probably riddled with
>>> errors, use salt etc etc):
>>>
>>> rcs: raw-current-sense {
>>> 	compatible = "current-sense-shunt";
>>> 	io-channels = <&adc 0>;
>>> 	io-channel-name = "raw-current";
>>> 	#io-channel-cells = <1>;
>>>
>>> 	shunt-resistor-micro-ohms = <3300000>;
>>> };
>>>
>>> rvs: raw-voltage-sense {
>>> 	compatible = "voltage-divider";
>>> 	io-channels = <&adc 1>;
>>> 	io-channel-name = "raw-voltage";
>>> 	#io-channel-cells = <1>;
>>>
>>> 	output-ohms = <22>;
>>> 	full-ohms = <222>;
>>> };
>>>
>>> mux: gpio-mux {
>>> 	compatible = "gpio-mux";
>>> 	#mux-control-cells = <0>;
>>>
>>> 	gpios-mux = <&main_gpio0 29 GPIO_ACTIVE_HIGH>;
>>> };
>>>
>>> current-sense {
>>> 	compatible = "io-channel-mux";
>>> 	io-channels = <&rcs 0>;
>>> 	io-channel-names = "parent";
>>>
>>> 	mux-controls = <&mux>;
>>>
>>> 	channels = "current", "";
>>> };
>>>
>>> voltage-sense {
>>> 	compatible = "io-channel-mux";
>>> 	io-channels = <&rvs 0>;
>>> 	io-channel-names = "parent";
>>>
>>> 	mux-controls = <&mux>;
>>>
>>> 	channels = "", "voltage";
>>> };
>>>
>>> What the mux solves is exclusion, so that the gpio pin is locked while
>>> measurement is made on either current-sense or voltage-sense.
>>>
>>> However, the channels from the raw-{current,voltage}-sense nodes are exposed
>>> to user space, and it will be possible to make "raw" measurements without
>>> regard to how the gpio pin is set. That will of course not yield the desired
>>> results, but is also a user error and might not be a big problem?  
>>
>> I just realized that it's also possible to do this "the other way around". Maybe
>> that makes more sense?
> Ah, I'd failed to realize that this is about routing a single wire
> through two different analog circuits that end on 'different' ADC inputs.
> 
> Pictures would help me out btw!  Everyone loves ascii art.

Certainly! :-)

> Anyhow, I 'think' what you have here should work.

Also, on ordinary multimeters it is quite easy to blow the fuse for the current
loop. Assuming that measuring current is more sensitive, the following addition
might be in order?

@mux {
	idle-state = 1;
};

Cheers,
Peter

      reply	other threads:[~2024-05-02 16:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-01 23:38 Supporting a Device with Switchable Current/Voltage Measurement João Paulo Gonçalves
2024-05-02  0:31 ` Bagas Sanjaya
2024-05-02  0:42   ` João Paulo Silva Gonçalves
2024-05-02  0:50     ` Bagas Sanjaya
2024-05-02 12:36 ` Jonathan Cameron
2024-05-02 13:49   ` Peter Rosin
2024-05-02 14:05     ` Peter Rosin
2024-05-02 14:53       ` jpaulo.silvagoncalves
2024-05-02 15:09       ` Jonathan Cameron
2024-05-02 16:43         ` Peter Rosin [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=00a0aa99-b33e-b3a4-594d-36685d138a05@axentia.se \
    --to=peda@axentia.se \
    --cc=Jonathan.Cameron@Huawei.com \
    --cc=joao.goncalves@toradex.com \
    --cc=jpaulo.silvagoncalves@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).