Introduction to real-time systems 15
paid to the final executable code. There are circumstances where this opti-
mistic disregard may lead to difficulties. A commonly used environmental
monitoring arrangement involves a transducer being interfaced to a voltage-
to-frequency converter (thanks to Laurence O’Brien for sharing this lop-sided
bug with me). The cost advantage of not using an ADC interfaced to a serial
transmission link is the prime motivation. With a V2F unit, the transducer
analogue voltage is converted to a pulse frequency code: the larger the volt-
age, the higher the frequency; the lower the voltage, the lower the frequency.
The computer only has to dedicate a single bit input port to accept the infor-
mation in serial mode. However, there remains the problem of converting this
pulse frequency code into normal integer format. For an HLL programmer
the following code might appear attractive. It runs and offers the beguiling
appearance of success, but it entails an interesting bug related to the code
generated by the compiler. Unfortunately, the time spent in the two oppos-
ing arms of the
IF/ELSE structure is not matched. So with an actual 50/50
situation, the results would not come out as 50/50, because of the dwell time
bias. This can be checked by reversing the code and running both versions
back to back. Inspecting assembler code listings from the compiler will also
reveal the discrepancy.
loop for 100 msec { loop for 100 msec {
if (input
bit) ←−−− if (!input
bit)
hcount++; hcount++;
else else
lcount++; lcount++;
}}
temp1 = tempX*hcount/ temp2 = tempX*hcount/
(lcount+hcount) (lcount+hcount)
1.10 High speed timing
Perhaps an example would now be useful of the opposite situation, when pro-
cessors simply cannot run fast enough. Consider a laser range-finder, intended
for use in civil surveying, or more ominously for battlefield targeting. It works
by preparing a pulse laser for firing, emitting a pulse of light, waiting for the
reflected echo to return, and, by timing the duration of the flight, calculating
the distance travelled.
The speed of light is 3
×
10
8
m/sec.
For a target 20 km away, the pulse of light will travel 40 km (4
× 10
4
m).
So time taken
=
distance
speed
=
4 × 10
4
3 × 10
8
= 1. 3 × 10
4
s = 130 µs
If the item being surveyed is only 50 m distant, the time of flight will be
reduced to 325 ns.

Get Real-Time Systems Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.