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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham 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!news4.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!newsfeed.freenet.de!news.newsland.it!aioe.org!not-for-mail From: Cesar Rabak Newsgroups: comp.lang.ada Subject: Re: Translating an embedded C algorithm Date: Wed, 17 Jan 2007 08:48:43 -0200 Organization: Aioe.org NNTP Server Message-ID: References: <1168871816.263502.212100@11g2000cwr.googlegroups.com> NNTP-Posting-Host: zEJK12x7djBBvRARhduGQA.user.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org In-Reply-To: User-Agent: Thunderbird 1.5.0.8 (X11/20061109) Xref: g2news2.google.com comp.lang.ada:8219 Date: 2007-01-17T08:48:43-02:00 List-Id: Vo, Anh (US SSA) escreveu: > -----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 := Integer'Last; < > MAXIMUM_ADC_COUNT : constant := Integer'Last; < SPACING : constant > := 1; .. >> MINIMUM_ADC_COUNT : constant := 220; MAXIMUM_ADC_COUNT : constant >> := 468; SPACING : constant := 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. You're welcome. I also did read very diagonally, probably an implementation of mine would have errors as well ;-) > > 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. > Here a comment: it's the right assumption per OP description and C code. However, I think that in an embedded system (specially for a microcontroller) the cost of a function call just to get a value may be not worth of. As the value of the argument seems to be a constant (all uppercase names in C normally are macros), I think ReadEEPROM just reads a memory (in E�PROM probably). > ---------------------------------------------------------------------- > --| MeasureTemperature --| --| Calculates the temperature in �C > given the ADC count by lookup --| table and linear interpolation of > the diode circuit characteristic. --| --| Parameters: --| AdcCount > Raw ADC count. --| --| Returns: --| Temperature in �C x 10. > INVALID_TEMPERATURE if out of range. --| --| Note: GNAT-GPL-2006 > compiler on Windows was used > ----------------------------------------------------------------------- > Observe the 'specification' on this comment (not yours I know, but rather a direct translation of the OP C code) and the implementation: > function Measure_Temperature (Adc_Count : in Integer) return Integer > is [snipped] I would have written this part (to be accord the spec): > if (Adc_Count < MINIMUM_ADC_COUNT) then -- Underflow of ADC - > saturate at minimum value Index := 0; elsif (Adc_Count > > MAXIMUM_ADC_COUNT) then -- Overflow of ADC - saturate at maximum > value Index := TEMPERATURE_TABLE_NUM_ENTRIES - 1; this way: -- beware of line wrap in Usenet if Adc_Count < MINIMUM_ADC_COUNT or else Adc_Count > MAXIMUM_ADC_COUNT then return INVALID_TEMPERATURE; > else -- Find the index of the table entry just below the ADC value > Index := (Adc_Count - MINIMUM_ADC_COUNT) / SPACING; end if; and thus I would have put all the remaining of this code within the else block above.