Special Timers for PC Serial Com Port and BASIC Stamp


We have completed the development of two timer circuits which may be used with a PC Com Port or with a Basic Stamp or similar. They may be also be used in standalone mode with the result being displayed on a serial LCD.

Typical applications include SONAR ranging or any similar application where a process is initiated and one desires to know the amount of time until a signal is returned. With a SONAR, a pulse is launched and one measures the amount of time to receive the echo. With a Pinewood Derby, one might cause a solenoid to release the racer and measure the amount of time until the racer breaks an optical path at the finish.

The inspiration for these timers was my frustration in attempting to interface a Poloroid 6500 Sonar Ranging device with a PC. A PC does not resolve time to sufficient accuracy and I soon discovered I needed a great deal of external timing circuitry and in fact, spent many weeks with various external oscillator, counter and latch arrangements. It worked, but by the time it was completed there was a great deal of circuitry. There just had to be a better way!

(Please note that these timers may be used as an interface between a PC or Stamp and a Polaroid 6500 SONAR. The SONAR package is available from Ben Wirz at http://www.wirz.com.


The new designs use the Microchip PIC12C508 in an 8-pin DIP package plus a three terminal ceramic resonator. They may be interfaced directly with such processors as the Basic Stamp or with a PC using a MAX232 level converter.

When input /GO is brought to a logic zero, output Q_RISE is brought to a logic one. This might be used to launch a pulse using the Polaroid 6500 SONAR. The processor then times until receipt of a positive logic level on input ECHO. The time is then serially transmitted to the PC (or Stamp) at 9600 Baud.

When interfacing with a PC, the process may be initiated by bringing the PC serial TX_D low (a start bit). This may be done by sending any character to the timer. When interfacing with a Stamp, this may be done by momentarily bringing a lead low.

Upon completion of the timing, the amount of elapsed time is then returned to the PC or Stamp at 9600 8N1 in decimal format.

Two Models.

Two different models are available.

TIMER_1 has a resolution of 10 usecs and would be suitable for SONAR applications. The data is returned as the number of msecs followed by a newline character.






The maximum time is 655.35 msecs. If an "echo" signal is not found within this time, a value of 655.35 is returned.

TIMER_2 has a resolution of 1 msec and would be more suitable for Pinewood Derby Applications. The data is returned as the number of seconds followed by a newline character.





The maximum time is 65.535 seconds. If the response from the system is not received within this time, a value of 65.535 is returned.

Clock Inaccuracy.

The PIC's internal 4.0 MHz oscillator proved to be inadequate. An initial six percent error plus additional error due to variations in temperature and voltage supply is not sufficiently accurate for serial communication, let alone the accuracy of the timing measurement.

Thus, both of these use an external 4.0 MHz ceramic resonator having an accuracy of 0.5 percent. A 4.0 MHz TTL clock oscillator may also be used for greater accuracy.

However, recognize that in a given application, you are using the same resonator at close to the same voltage supply and the same temperature. That is, the clock frequency is repeatable and thus the error may be "corrected" in your software using a scaling factor. For example, in using your SONAR you may find you are getting readings of 36.2 inches when in fact, the target is 36.0 inches. Knowing this, you can then correct your readings by multiplying by 36.2/36.0.

Local LCD Output.

The unit may also be interfaced with our PIC-n-LCD serial 20X4 LCD to provide a local display. Thus, with each reading the data is sent to the PC or Stamp via the MAX232. In addition, the value is also displayed on the PIC-n-LCD.

This permits the user to employ these timers in a standalone mode without a PC or Stamp. Thus the /GO signal might be applied by momentarily depressing a pushbutton. The PIC then brings PIC output Q_RISE high which initiates the process. The elapsed time may then be observed on the LCD display.


We have packaged this as a TIMER_KIT. This kit is intended for evaluation and includes one TIMER_1 and one TIMER_2 PIC. It also includes one 4.0 MHz ceramic resonator, one MAX232 plus the four associated capacitors, our logic probe, and a resistor and a capacitor for "simulating" a SONAR plus a small supply of 22 AWG wire suitable for breadboarding on a solderless breadboard. The package also includes documentation including assembly, sample applications and sample software. The TIMER_KIT is $16.00.

Additional TIMER_1 and TIMER_2 PICs may be purchased for $3.50 each. Note that this includes only the programmed PIC.

4.0 MHz ceramic resonators are available for $0.75, 4.0 MHz TTL clock oscillators for $2.00 and MAX232s with the four 1.0 uFd capacitors for $2.00.

Return Policy.

As with all of our manuals and kits, these items may be returned for full credit if they don't meet your needs or expectations.

Ordering Information.