Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp558162imu; Thu, 22 Nov 2018 01:46:35 -0800 (PST) X-Google-Smtp-Source: AFSGD/Xehd0iv8HWBaP2DKaS3QEmj1/BIJpcGrsu3eefqMORErBGz7bQ/DGmcexuwkfdsvPdioSa X-Received: by 2002:a17:902:b689:: with SMTP id c9-v6mr10787784pls.306.1542879995580; Thu, 22 Nov 2018 01:46:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542879995; cv=none; d=google.com; s=arc-20160816; b=PXTRBB/nXYVL0SEX3rtLMjI1DRQ0LFdLt5iJGZHxEPFw5bCmRFis1nxE4CTSEvQ9QZ 8XhZ3KPr2i0D874c/tz1FZJeLrxqcLqGTUQcHikI5Nj0kFnYYVdNS371WmHoMUUUlxtz NOyq4C92MLz4mSAXERVQM1XhSQPDJIOtB9HnEvlZ5HYeUCic9VIzMCjVYno0NtD14wsQ +wF4RkLAO7T0YnH83zmueuR/BckYme8BH6P3qU2/CBJ1IiJzKsuA+y9YGP03NPnfNzdp ZpakIVgXFP9RiIuR31j2Bo+zIJYA8kgxlpQFonBGh31BlQ14VdFNfqCiH+vKYMEnqxtX NxTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-id:content-language:accept-language:in-reply-to:references :message-id:date:thread-index:thread-topic:subject:cc:to:from; bh=taKLzzATc4iyqS6fSHyuVNFA12tJyCCrD6Ilyl2Dfuw=; b=J1gA4ONwg7inX5iT0Eb69FZDB2maijV3DW61v2UUJl1aJTY9xrylOOxqE9K/7Dpftz IJPlgakgeLQT6qiaLOvNKKgfSWpNBdl4dlLQsMdImZ1gMCNmehh9AH2lw4w+QRP0pCPr 3+MgLUrgTNk8QpTq8tQvbqNdBdtF/DfFArP10jN97qR1CoJ9PtMjxhQJh4oBIrzSUgMN uFIE4T2AAmNIebOYNxU3hnWcFL533OHKadNgDL+XIEM8c4VInbZwkFhPIrAfxYY/xm5k YEruZ+skyJC6AGSadh6mIjyiIfV4OXn2PIO8Dbgl1J1fXhwXfQnTSU757XkPIvtWYEBh S6bg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a35si11383965pla.226.2018.11.22.01.46.20; Thu, 22 Nov 2018 01:46:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387762AbeKVIw1 convert rfc822-to-8bit (ORCPT + 99 others); Thu, 22 Nov 2018 03:52:27 -0500 Received: from mail-out-1.itc.rwth-aachen.de ([134.130.5.46]:47433 "EHLO mail-out-1.itc.rwth-aachen.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731864AbeKVIw1 (ORCPT ); Thu, 22 Nov 2018 03:52:27 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A2AEDQAN2PVb/5wagoZiHgEGBwaBZQKBL?= =?us-ascii?q?1OBaCcKmhKXTIFmDAEsgUuCdQKECiI4EgEDAQECAQECbShCARABBAGEYwEBAQM?= =?us-ascii?q?BJ0UKAxACAQgOCgklDwEiJQIEDgWFGwgBA6xOM4omjAWBWD6DJX6EQiARC4VbA?= =?us-ascii?q?odVgzuESY9PVQcCgRGQM4FZiAIrhwCHU5AxAgICAgkCFIFdIYFVTSSDO5BaQTG?= =?us-ascii?q?BKIRahFiCXAGBHgEB?= X-IPAS-Result: =?us-ascii?q?A2AEDQAN2PVb/5wagoZiHgEGBwaBZQKBL1OBaCcKmhKXTIF?= =?us-ascii?q?mDAEsgUuCdQKECiI4EgEDAQECAQECbShCARABBAGEYwEBAQMBJ0UKAxACAQgOC?= =?us-ascii?q?gklDwEiJQIEDgWFGwgBA6xOM4omjAWBWD6DJX6EQiARC4VbAodVgzuESY9PVQc?= =?us-ascii?q?CgRGQM4FZiAIrhwCHU5AxAgICAgkCFIFdIYFVTSSDO5BaQTGBKIRahFiCXAGBH?= =?us-ascii?q?gEB?= X-IronPort-AV: E=Sophos;i="5.56,262,1539640800"; d="scan'208";a="61875155" Received: from rwthex-w1-a.rwth-ad.de ([134.130.26.156]) by mail-in-1.itc.rwth-aachen.de with ESMTP; 21 Nov 2018 23:16:10 +0100 Received: from rwthex-w2-a.rwth-ad.de (2a00:8a60:1:e500::26:158) by rwthex-w1-a.rwth-ad.de (2a00:8a60:1:e500::26:156) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1531.3; Wed, 21 Nov 2018 23:16:09 +0100 Received: from rwthex-w2-a.rwth-ad.de ([fe80::18f3:313d:3e:42ff]) by rwthex-w2-a.rwth-ad.de ([fe80::18f3:313d:3e:42ff%21]) with mapi id 15.01.1531.007; Wed, 21 Nov 2018 23:16:09 +0100 From: =?iso-8859-1?Q?Br=FCns=2C_Stefan?= To: Nicolin Chen CC: "jdelvare@suse.com" , "linux@roeck-us.net" , "linux-hwmon@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "corbet@lwn.net" , "linux-doc@vger.kernel.org" Subject: Re: [RFC][PATCH] hwmon: (ina2xx) Improve current and power reading precision Thread-Topic: [RFC][PATCH] hwmon: (ina2xx) Improve current and power reading precision Thread-Index: AQHUgTlMOgH+/TcWJ0m0L3+ib8kVa6VaVu4AgAA6FACAACtjgA== Date: Wed, 21 Nov 2018 22:16:09 +0000 Message-ID: <1717545.GXSegKtrMu@sbruens-linux.lcs.intern> References: <20181121012629.5432-1-nicoleotsuka@gmail.com> <2863036.QIPGp1Eqjm@sbruens-linux.lcs.intern> <20181121194051.GA8902@Asurada-Nvidia.nvidia.com> In-Reply-To: <20181121194051.GA8902@Asurada-Nvidia.nvidia.com> Accept-Language: en-US, de-DE Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [62.153.130.132] Content-Type: text/plain; charset="iso-8859-1" Content-ID: Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mittwoch, 21. November 2018 20:40:52 CET Nicolin Chen wrote: > (Removing "m.purski@samsung.com" since it's not reachable any more) > > Hi Stefan, > > Thank you for the comments. > > On Wed, Nov 21, 2018 at 04:13:01PM +0000, Br?ns, Stefan wrote: > > > === Problem === > > > Both methods simplify software routine by fixing one factor, which > > > sacrifices the precision of the hardware measurement results. > > > > > > Using ina226 for example, with method A, the current scale was 1mA > > > and the power scale was 25mA. > > > > > > With method B, calibration value is fixed at 2048 so the precision > > > is decided by shunt resistor value. It sounds reasonable since the > > > hardware engineers can use a larger shunt resistor when they need > > > higher resolution. However, they often concern power burning across > > > the resistor as well, so the resistor usually won't be so large: a > > > typical value 1000 micro-ohms, which results in a current scale at > > > 2.5 mA and a power sacle at 62.5 mW. > > > > Power loss surely is a concern, but figures should be kept reasonable. > > > > 1. You mention 1.8V bus voltage, and currents in the 30mA range. Using the > > 1mOhm current shunt: > > > > U_S = R_S * I_S 1e-3 Ohm * 30e-3 A = 30e-6 V (30uV) > > P_S = U_S * I_S = 30e-6V * 30e-3 A = 900e-9W = 0.9 uW > > > > INA219 Power Supply (Datasheet) > > Min operating Voltage: 3V > > Quiescent Current: 0.7mA > > -> Min power: 2.1mW > > > > So the INA219 alone uses 2.1mW, 1000 times more than the shunt. > > Chip can enter power-down or one-shot mode. Though this upstream > driver doesn't have these two mode supports yet, I am working on > it so they'll be added. The power-down current is 6uA, so even if you never leave power-down mode, you are down to 18uW. But on top of that, you need power for the conversion, and you need power for communication. > > Another concern may be voltage drop over the shunt, but for this case you > > have a nominal voltage of 1.8V, so 30uV are 0.001%. > > > > > When measuring a 1.8v voltage running a small current (e.g. 33 mA), > > > the power value (that's supposed to be 59.4 mW) becomes inaccurate > > > due to the larger scale (25mA for method A; 62.5 mA for method B). > > Just found out that I have typos here: 25mW and 62.5mW. > > > Another look into the datasheet reveals, even at full gain (PGA=1), the > > LSB is 40mV / 2^12 = 40mV / 4096 ~ 10uV. So when the current ADC reads > > out as 3*LSB, this anything between 25mA and 35mA. This is the best case > > figure. > Current read doesn't get affected a lot actually, since hwmon ABI > also reports current value in unit mA. However, the power read is > the matter here. With a 62.5mW power_lsb, power results are kinda > useless on my system. The reported current does not matter here, actually. Internally, the ADC value will have an uncertainty of 10mA (at PGA=1). At 1.8V, your uncertainty is 18mW. And thats *only* the quantization noise. It wont get better than that. Also note, you are apparently using the ina2xx hwmon driver - I strongly advise against it, you should either use the ina2xx driver from the IIO subsystem directly, or use the IIO driver via iio-hwmon. 1. INA219 is not properly supported by the hwmon driver, see the changes in the IIO driver. 2. The IIO driver has many more features: - setting the PGA (INA219) - setting the bus voltage range (INA219) - selecting the conversion time (INA219/226) There is also always the possibility to read the bus and shunt voltage registers and calculate the power manually. Regards, Stefan