From: Talulah on
Hi,

I am in the process of writing a book about real-time embedded
development (hardware and software). In it there is a section on
different programming languages that are available for embedded
development. I'm using a small C function that does temperature
measurement by linear interpolation of a lookup table as an example. I
have C code to do this, and would like to have the same algorithm
implemented in other languages.

Unfortunately I'm really a C programmer, with very little experience
of other languages, so I would like to ask if anyone on this newsgroup
is interested in translating the algorithm into Ada. Of course you
would be mentioned in thanks in the book once it is finished.

If you are interested, I have placed the section of the book here:

http://homepages.which.net/~paul.hills/Temporary/Temperature.pdf

so you can see the code and description. Please email me if you are
interested to paul (dot) hills (who is at) uk (dot) landisgyr (dot)
com.

Thanks very much
Paul Hills

From: Jeffrey Carter on
Talulah wrote:
>
> I am in the process of writing a book about real-time embedded
> development (hardware and software).
>
> Unfortunately I'm really a C programmer, with very little experience
> of other languages, ...

I would think that someone qualified to write such a book would be
familiar with at least one language that was designed for RT embedded SW
development. Such a language would have things like tasking, timing, and
fixed-point types built in.

Clearly C is not such a language, so I have to wonder about the
qualifications of someone who only knows C.
From: Marc A. Criley on
On Tue, 16 Jan 2007 00:06:59 +0000, Jeffrey Carter wrote:

> Talulah wrote:
>>
>> I am in the process of writing a book about real-time embedded
>> development (hardware and software).

> Clearly C is not such a language, so I have to wonder about the
> qualifications of someone who only knows C.

Thanks Jeff, go ad hominem on someone who's unfamiliar with Ada yet
willing to give it a fair hearing.

-- Marc A. Criley
-- McKae Technologies
-- www.mckae.com
-- Avatox - DTraq - XIA - XML EZ Out

From: Cesar Rabak on
Jeffrey Carter escreveu:
> Talulah wrote:
>>
>> I am in the process of writing a book about real-time embedded
>> development (hardware and software).
>> Unfortunately I'm really a C programmer, with very little experience
>> of other languages, ...
>
> I would think that someone qualified to write such a book would be
> familiar with at least one language that was designed for RT embedded SW
> development. Such a language would have things like tasking, timing, and
> fixed-point types built in.

Can you please enlight us why "Such a language *would have* things like"
and not "programming in a such language that has things like..."

>
> Clearly C is not such a language, so I have to wonder about the
> qualifications of someone who only knows C.

And why cannot C be augmented by RTOSs and other systems software to
achieve this?

Instead of taking profit of an opportunity you rather just spit a bit of
arrogance?

How does this helps Ada?
From: Vo, Anh (US SSA) on
-----Original Message-----
From: comp.lang.ada-bounces(a)ada-france.org [mailto:comp.lang.ada-bounces(a)ada-france.org] On Behalf Of Talulah
Sent: Monday, January 15, 2007 6:37 AM
To: comp.lang.ada(a)ada-france.org
Subject: Translating an embedded C algorithm

<< [..]

Unfortunately I'm really a C programmer, with very little experience
of other languages, so I would like to ask if anyone on this newsgroup
is interested in translating the algorithm into Ada. Of course you
would be mentioned in thanks in the book once it is finished.

If you are interested, I have placed the section of the book here:

http://homepages.which.net/~paul.hills/Temporary/Temperature.pdf

so you can see the code and description. Please email me if you are
interested to paul (dot) hills (who is at) uk (dot) landisgyr (dot)
com. >>>

Here I just translated directory to Ada from C code in the table. Please pay attention to the Important Note below the Table. Note also that I have slightly modified some variables for readability. Let me know if more information is desired.

AV
------------------------------------------------------------------------
--| 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
-------------------------------------------------------------------------
function Measure_Temperature (Adc_Count : in Integer) return Integer is

Index : Integer := 0;
InterpolationDistance : Integer := 0;
TempDiff : Integer := 0;
TempCalOffset : Integer := 0;
Temperature : Integer := 0;

TEMPERATURE_TABLE_NUM_ENTRIES : constant := 32;
Table : constant array
(0 .. TEMPERATURE_TABLE_NUM_ENTRIES - 1) of Integer := (
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);

-- *** Important Note:
-- The following constants and function need to be defined.
-- They are arbitrary set so compilation is successful.
MINIMUM_ADC_COUNT : constant := Integer'Last;
MAXIMUM_ADC_COUNT : constant := Integer'Last;
SPACING : constant := 1;
TEMPERATURE_CAL_VALUE : constant := 0;

function ReadEEPROM (Temp : in Integer) return Integer is
begin
return Temp; -- for now
end ReadEEPROM;
-----------------------------------------------------------

begin

-- 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 := 0;
elsif (Adc_Count > MAXIMUM_ADC_COUNT) then
-- Overflow of ADC - saturate at maximum value
Index := TEMPERATURE_TABLE_NUM_ENTRIES - 1;
else
-- Find the index of the table entry just below the ADC value
Index := (Adc_Count - MINIMUM_ADC_COUNT) / SPACING;
end if;

-- 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 := (Adc_Count - MINIMUM_ADC_COUNT) + (SPACING - 1);
TempDiff := (Table(Index) - Table (Index+1));

-- 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 :=
Table(Index) - ((TempDiff * InterpolationDistance) / SPACING);

-- To this is then added the calibration offset to the temperature table.
TempCalOffset := ReadEeprom (TEMPERATURE_CAL_VALUE);
Temperature := Temperature + TempCalOffset;

return Temperature;

end Measure_Temperature;