From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Thread: 103376,f822ae7b0f7433c1 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!tiscali!newsfeed1.ip.tiscali.net!news.tiscali.fr!proxad.net!cleanfeed2-b.proxad.net!nnrp4-1.free.fr!not-for-mail Return-Path: x-mimeole: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: RE: Translating an embedded C algorithm Date: Tue, 16 Jan 2007 19:00:51 -0800 In-Reply-To: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Translating an embedded C algorithm Thread-Index: Acc5h3aIXz6usUSZS3ejZBdF96rsQQAWqxyQ References: <1168871816.263502.212100@11g2000cwr.googlegroups.com> From: "Vo, Anh \(US SSA\)" To: "Cesar Rabak" , X-OriginalArrivalTime: 17 Jan 2007 03:00:52.0424 (UTC) FILETIME=[B2D87C80:01C739E3] X-Virus-Scanned: amavisd-new at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.9rc1 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.ada Message-ID: X-Leafnode-NNTP-Posting-Host: 88.191.17.134 Organization: Guest of ProXad - France NNTP-Posting-Date: 17 Jan 2007 06:55:06 MET NNTP-Posting-Host: 88.191.14.223 X-Trace: 1169013306 news-4.free.fr 289 88.191.14.223:51317 X-Complaints-To: abuse@proxad.net Xref: g2news2.google.com comp.lang.ada:8213 Date: 2007-01-17T06:55:06+01:00 -----Original Message----- From: comp.lang.ada-bounces@ada-france.org = [mailto:comp.lang.ada-bounces@ada-france.org] On Behalf Of Cesar Rabak Vo, Anh (US SSA) escreveu: > -----Original Message----- [snipped] A suggestion for the OP: < MINIMUM_ADC_COUNT : constant :=3D Integer'Last; < MAXIMUM_ADC_COUNT : constant :=3D Integer'Last; < SPACING : constant :=3D 1; .. > MINIMUM_ADC_COUNT : constant :=3D 220; > MAXIMUM_ADC_COUNT : constant :=3D 468; > SPACING : constant :=3D 8; The values 220 and 468 come from its Table 1 (PDF file). Also SPACING is = described as being 8. Thanks for pointing these values out. I did it in hurry. So, I did not = read the PDF file in details. Today I attempted to find out where = ReadEEPROM table or function is defined. I did not see it. In addition, = I did ask for its definition. However, it was left out. Again, here it = is. function ReadEEPROM (Temp : in Integer) return Integer is begin return Temp; -- for now end ReadEEPROM; I assume ReadEEPROM is a function. Whether it is a table or a function, = it needs to be defined. Assume that ReadEEPROM is defined, here is the = updated version of it. Thanks to Christoph Grein for his correction. ------------------------------------------------------------------------ --| MeasureTemperature --| --| Calculates the temperature in =BAC given the ADC count by lookup --| table and linear interpolation of the diode circuit characteristic. --| --| Parameters: --| AdcCount Raw ADC count. --| --| Returns: --| Temperature in =BAC x 10. INVALID_TEMPERATURE if out of range. --|=20 --| Note: GNAT-GPL-2006 compiler on Windows was used -------------------------------------------------------------------------= function Measure_Temperature (Adc_Count : in Integer) return Integer is Index : Integer :=3D 0; InterpolationDistance : Integer :=3D 0; TempDiff : Integer :=3D 0; TempCalOffset : Integer :=3D 0; Temperature : Integer :=3D 0; =20 TEMPERATURE_TABLE_NUM_ENTRIES : constant :=3D 32; Table : constant array (0 .. TEMPERATURE_TABLE_NUM_ENTRIES - 1) of = Integer :=3D (1171, 1116, 1061, 1006, 952, 899, = 846, 793, 741, 689, 638, 588, 537, 488, = 438, 389, 341, 293, 246, 199, 152, 106, = 61, 16, -29, -73, -116, -160, -202, -244, = -286, -327); MINIMUM_ADC_COUNT : constant :=3D 220; MAXIMUM_ADC_COUNT : constant :=3D 246; SPACING : constant :=3D 8;=20 TEMPERATURE_CAL_VALUE : constant :=3D 0; -- *** Important Note:=20 -- The algorithm of the following function needs to be defined. function ReadEEPROM (Temp : in Integer) return Integer is begin return Temp; -- for now end ReadEEPROM; ----------------------------------------------------------- =20 begin =20 -- Index is the index into the table. Each table entry is 8 ADC -- counts higher than the last one, so subtract the offset and -- divide by 8 to find the table index. InterpolationDistance -- is the linear distance between the the table entry ADC cou nt -- and the actual ADC count. -- Check range of Adc_Count and saturate index if out of range. if (Adc_Count < MINIMUM_ADC_COUNT) then -- Underflow of ADC - saturate at minimum value Index :=3D 0; elsif (Adc_Count > MAXIMUM_ADC_COUNT) then -- Overflow of ADC - saturate at maximum value Index :=3D TEMPERATURE_TABLE_NUM_ENTRIES - 1; else -- Find the index of the table entry just below the ADC value Index :=3D (Adc_Count - MINIMUM_ADC_COUNT) / SPACING; end if; =20 -- Calculate the interpolation between the table entries either side = of -- the ADC value. This is the remainder of the difference between the -- ADC count and the minimum temperature ADC count divided by the -- spacing between table entries. Since the spacing is a power of 2, -- this can be achieved by simply masking all but the bottom 3 bits. InterpolationDistance :=3D (Adc_Count - MINIMUM_ADC_COUNT) mod = (SPACING - 1); TempDiff :=3D (Table(Index) - Table (Index+1)); =20 -- The temperature is then the base temperature minus the amount -- calculated by linear interpolation. The compiler is clever enough -- to know that dividing by 8 is a right shift of three bits. Temperature :=3D Table(Index) - ((TempDiff * InterpolationDistance) / = SPACING); =20 -- To this is then added the calibration offset to the temperature = table. TempCalOffset :=3D ReadEeprom (TEMPERATURE_CAL_VALUE); Temperature :=3D Temperature + TempCalOffset; =20 return Temperature; =20 end Measure_Temperature; =20