From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from hqemgate15.nvidia.com ([216.228.121.64]:1815 "EHLO hqemgate15.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754387AbcJUGeE (ORCPT ); Fri, 21 Oct 2016 02:34:04 -0400 Message-ID: <5809B34C.6040301@nvidia.com> Date: Fri, 21 Oct 2016 11:48:52 +0530 From: Laxman Dewangan MIME-Version: 1.0 To: =?UTF-8?B?UGF3ZcWCIEphcm9zeg==?= CC: , , Subject: Re: [PATCH] thermal: generic-adc: Fix linear temperature approximation References: <20161018193147.GA14745@vaio-ubuntu> <5808BB3D.2020201@nvidia.com> <8d2a5917-30b4-d9eb-304a-b96780de9f4c@gmail.com> <5808E78B.4060109@nvidia.com> <0412f751-fb88-7b9e-8a8c-501e019de774@gmail.com> <5808F86A.4080800@nvidia.com> In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Sender: linux-iio-owner@vger.kernel.org List-Id: linux-iio@vger.kernel.org On Thursday 20 October 2016 10:56 PM, Paweł Jarosz wrote: > >> It is Negative Coefficient Thermistor (NCT) and so adc reads are >> different. >> Lower temp gives higher value. >> >> So table should be >> >> <7000 10 >> 9000 8>; >> >> temp1 = gti->lookup_table[2 * i]; >> temp2 = gti->lookup_table[2 * i - 2]; >> >> and then use in following equation. >> >>> >>> adc_hi = gti->lookup_table[2 * i - 1]; >>> adc_lo = gti->lookup_table[2 * i + 1]; >>> temp = gti->lookup_table[2 * i]; >>> temp -= (val - adc_lo) * (temp1 - temp2) / (adc_hi - adc_lo); > > val = 9 > adc_hi = 10 > adc_lo = 8 > temp = 9000 - (9 - 8)*(7000 - 9000)/(10 - 8) > temp = 9000 - (1)*(-2000)/(2) > > temp = 9000 - (-1000) = 10000 > > still wrong ... temp for val = 9 should be 8000 Your temp1 and temp2 calculation is something wrong. temp1 = gti->lookup_table[2 * i]; temp2 = gti->lookup_table[2 * i - 2]; so temp1 = 9000, temp2 = 7000 temp -= (val - adc_lo) * (temp1 - temp2) / (adc_hi - adc_lo); temp = 9000 - (9 - 8)*(9000 - 7000)/(10 - 8) temp = 9000 - (1)*(2000)/(2) = 8000 which is expected. > > Maybe we could leave this patch as it is? > temp = gti->lookup_table[2 * i]; + tlow = gti->lookup_table[2 * i - 2]; (modify) temp -= (val - adc_lo) * (temp - tlow) / (adc_hi - adc_lo); This will gives you correct result. Let me know if you can send the updated patch. Else I will send. Thanks, Laxman ----------------------------------------------------------------------------------- This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. -----------------------------------------------------------------------------------