Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2405798imu; Wed, 21 Nov 2018 11:07:05 -0800 (PST) X-Google-Smtp-Source: AJdET5fQdfK5DagbUxEquSzhM2Z7ko/29hqsXZLXoMhZuUUBXc6TexlaHVmMBmpK/U4Uq4t2US2j X-Received: by 2002:a63:4566:: with SMTP id u38mr7093975pgk.4.1542827225666; Wed, 21 Nov 2018 11:07:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542827225; cv=none; d=google.com; s=arc-20160816; b=aSBDaWxE5JCgOtUbQUAbu44wgJg5aW+csyNsNdgoFkixbQE3aJ7GS0AcESilqeUozX bmhLTLES/bIZzNP5jkQ0AVb6kGz44ZisCuCXcqdxO6Z7N6cFKDjakROinPkYe0l9D8QY xedeG3yJJ6a7k2xfpvBpG/GcO6Ea7WGQ+yqmfap2XDuc+lKi/OUaWvg/e5TSIpz977yp dgPXGsLEGK26aKGh+IBLlMdm2ZbNX/ER9bGF/dRkgzYhZa5KPgclADnpLTtZ1udoJCrW PoKK77BgfRFlysOY0ul7VakvAusLVSiWqQ1A2uIiipaxXblwcJfYrhT3fJf5sahOU6hh ypDQ== 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=X//SdYqy4s1gXo5uIuqtdb/jm69Ol/bodzOqfdPf9vs=; b=Udx9XJptJpquAmdwF1SdtTj/FChPiSqOGtWBBv80KPvXrfe3NXMbNphy4HkM2ML94i vyGZOdlQrLBSftrDyXClYGDP4cQuiygMTYYBpmis5AvfGbcFiKIwIpU2Z2KCz0afJdXh YHM/TtTyQfh7ELoZYUnx8+RySVKNS1W3w+oxG0X6L/ar6r9Gt1ljPiEf35n6RQopCsqR sfzXFVoSPRVMo36r6WiWYmHB3Q9vuQI7Fsh3fbms9plTjb9rZ4PyRfXTbEqi0vAsf/Jo jdE5HwOz7Nx6Y1CRscABCcbea4Vk0Tustp2gTGHmzSFkqOgBKhsF2z7bvooId3AbUHem OKrg== 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 t12si10895242plr.311.2018.11.21.11.06.44; Wed, 21 Nov 2018 11:07:05 -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 S1731660AbeKVC56 convert rfc822-to-8bit (ORCPT + 99 others); Wed, 21 Nov 2018 21:57:58 -0500 Received: from mail-out-3.itc.rwth-aachen.de ([134.130.5.48]:61561 "EHLO mail-out-3.itc.rwth-aachen.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730072AbeKVC56 (ORCPT ); Wed, 21 Nov 2018 21:57:58 -0500 X-Greylist: delayed 591 seconds by postgrey-1.27 at vger.kernel.org; Wed, 21 Nov 2018 21:57:57 EST X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A2AFDQB5g/Vb/5oagoZiHgEGBwaBZQKBL?= =?us-ascii?q?1OBaDGYBoINmTIMASyBS4J1AoQKIjgSAQMBAQIBAQJtKEIBEAEEAYRjAQEBAQI?= =?us-ascii?q?BJ0UKAwULAgEIDgoJJQ8BIiUCBA6FIAgBA6xqM4oljAWBWD6EI4RiEQuFWwKLE?= =?us-ascii?q?IRJj09VBwKBEZAziVuHK4dTkDECAgICCQIUgV0hgVVNJIM8kFlBgVmEQ4RCgl4?= =?us-ascii?q?BgR4BAQ?= X-IPAS-Result: =?us-ascii?q?A2AFDQB5g/Vb/5oagoZiHgEGBwaBZQKBL1OBaDGYBoINmTI?= =?us-ascii?q?MASyBS4J1AoQKIjgSAQMBAQIBAQJtKEIBEAEEAYRjAQEBAQIBJ0UKAwULAgEID?= =?us-ascii?q?goJJQ8BIiUCBA6FIAgBA6xqM4oljAWBWD6EI4RiEQuFWwKLEIRJj09VBwKBEZA?= =?us-ascii?q?ziVuHK4dTkDECAgICCQIUgV0hgVVNJIM8kFlBgVmEQ4RCgl4BgR4BAQ?= X-IronPort-AV: E=Sophos;i="5.56,261,1539640800"; d="scan'208";a="24956557" Received: from rwthex-s2-a.rwth-ad.de ([134.130.26.154]) by mail-in-3.itc.rwth-aachen.de with ESMTP; 21 Nov 2018 17:13:01 +0100 Received: from rwthex-w2-a.rwth-ad.de (2a00:8a60:1:e500::26:158) by rwthex-s2-a.rwth-ad.de (2a00:8a60:1:e500::26:154) 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 17:13:01 +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 17:13:01 +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" , "m.purski@samsung.com" 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+ib8kVa6VaVu4A Date: Wed, 21 Nov 2018 16:13:01 +0000 Message-ID: <2863036.QIPGp1Eqjm@sbruens-linux.lcs.intern> References: <20181121012629.5432-1-nicoleotsuka@gmail.com> In-Reply-To: <20181121012629.5432-1-nicoleotsuka@gmail.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 02:26:29 CET Nicolin Chen wrote: > === Background === [...] > > === 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. 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). 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. On top of quantisation error, you have the ADC offset voltage (V_OS), which is given as (for PGA=1, best case): (+-) 10uV typical, (+-) 100uV max. So, if you want to have meaningful readouts adjust your shunt to a reasonable value. Even 100 times the current value will have no measurable effect on you system (power loss: 90uW, voltage drop: 3mV). Kind regards, Stefan