circuitcellar.com
Magazine Support   Digital Library   Products & Services   Suppliers Directory 
 
 





 

August 2004, Issue 169

Ham Radio Repeater Locator


by Glen Worstell

ACCURACY AND MATH

Precise distances to repeaters are not required, so to simplify calculations and make the code smaller, I decided to shoot for an accuracy of approximately plus or minus two miles for repeaters that are within approximately 100 miles.

Various factors affect accuracy: repeater locations are stored to an accuracy of about one mile; the exact locations of the repeaters are unknown; the algorithm for determining distances has a small error under certain situations; and the integer arithmetic used is subject to truncation and rounding errors. Tests on the finished algorithms show errors within the desired range.

Given two points on the surface of the earth, a straightforward trigonometry formula gives the distance between the points. Although the Zilog C compiler includes floating-point libraries, I used integer arithmetic throughout in order to avoid the size of floating-point arithmetic and transcendental routines. Speed is not really an issue for this project, but integer routines are faster of course.

The distance between two points on the same longitude (a north-south line) is about 69 miles per degree of latitude. For points on the same latitude (an east-west line), the distance is 69 miles per degree of longitude only at the equator, shrinking to zero at the poles. The formula for the distance along a line of constant latitude is 69 miles per degree of longitude multiplied by the cosine of the latitude.

The HRRL program calculates the legs of a right triangle using the formulas in Figure 1. The correction factor for the leg of constant latitude is taken to be the cosine of the average latitude of the two points, and the cosine is calculated with a look-up table. The error caused by this approximation is negligible for distances less than 100 miles.

(Click here to enlarge)

Figure 1—Given two points on the surface of the earth, a spherical trigonometry formula gives the distance between the points. In order to avoid lengthy code, the familiar formula for the length of the hypotenuse of a right triangle is used instead, with an accuracy that’s close enough (within a mile or so) for any repeaters within range.

Division is slow and takes noticeable code space, even for integers. The HRRL code does no division except by powers of two, which can be implemented by shifts. For example, to convert delta latitude—which is expressed in grees (a “gree” is defined as one-fiftieth of a degree)—to miles, it’s necessary to multiply by the ratio 69/50. The code uses the ratio 11/8 to avoid an integer divide, with a resulting error of only approximately one-third of a mile in 100 miles.  

DATABASE

There are about 8,000 repeaters in the U.S. and Canada, so it’s necessary to carefully design the data storage in order to fit all the repeater information and the program into the 64 KB of flash memory available in the Z8F6401. Experience with the first version of the program led me to add the call letters of each repeater station to the database. This made it impossible to fit all 8,000 repeaters in the available memory. But, a substantial fraction fit, enough to satisfy anyone who is driving through 49 states (Hawaii is not included) and Canada.

Table 1 shows the required database information and the number of bits of storage allocated. A change in latitude of 1 gree is equal to slightly greater than one mile, which is judged to be sufficient resolution for the HRRL.

The database is stored sorted by frequency in order to reduce the number of bits required for frequency information. Frequencies are in the range of 144 to 148 MHz, and all stations are on 5-kHz increments. 

REPEATER INFORMATION

I had hoped to find an Internet site with repeater locations and frequencies available for download, but no such service is offered. There are some localized databases for certain states, and users in those locations may be able to make use of them.

The printed ARRL repeater directory costs approximately $10, but manually entering the data is tedious. The translation to latitude-longitude is also tedious and inaccurate because the locations of the repeaters are given as the names of cities and geological features.

The ARRL sells a CD containing the locations, but it’s pricey and the CD database has the locations of the repeaters encrypted for some strange reason. It isn’t too difficult to extract the necessary latitude-longitude information, which I did for my project. Refer to the LCC program listings on the Circuit Cellar ftp site for the details. Because the information is copyrighted, I included only a small sample database as part of the project files.

If you only need repeaters for a small area, you can manually create a text file with one line per repeater. Tabs separate fields, and all fields must be present (enter zero for the tone field if no tone is required). The fields, in order, are: latitude in degrees, longitude, frequency in megahertz, plus or minus for offset, call, and tone in hertz. Figure 2 is an example line.

(Click here to enlarge)

Figure 2—The repeater database text file has one line per repeater. Tabs separate the fields. All fields must be present. (Enter zero for the tone field if no tone is required.) The fields, in order, are as follows: station latitude in degrees, station longitude in degrees, frequency in megahertz, plus or minus for offset, call, and tone in hertz. An auxiliary program converts the data to the format needed by the microcomputer.

Several programs have been written to aid in the creation of the repeater database. For example, the datagen program converts a text file in the aforementioned format to the C data array used by the microcomputer. The auxiliary programs were written with the free Windows lcc-win32 compiler.