Microcontroller makes effective frequency counter

Fazal Pathan, Physical Research Laboratory, Ahmedabad, India -- 11/23/2000

Figure 1 shows an efficient and cost-effective frequency counter using an Atmel 89C2051 µC (Reference 1). The design can use any µC of the 8051 family. The circuit counts frequency and sends the count to a PC via the serial port. The signal connects to pin 3.4 of the µC. The TTL-compatible output of the µC drives the 1488, which converts the output to RS-232 voltage levels. The output of the 1488 connects to the RxD pin on the serial port of the PC. In this design, only unidirectional communication exists between the µC and the PC. But you can use the TxD line to control another device. The assembly routine in Listing 1 shows initialization of the timer, counter, and interrupts. The main program sets up T0 to count external pulses and T1 to count time in the autoreload mode 2 (Reference 2). The main program monitors the main-program flag, frqflg, until the flag is set. Then, the main program sends the counted frequency to the PC's port using mode 1. First, it sends the special character "L" to recognize the following 3 bytes as valid data. Then it sends the value of register R2, which is the most significant byte of the counter value. This value increments every time the counter overflows. Then, the main program sends the values of registers TH0 and TL0 to the PC's port.

After sending the data, the program again jumps to the main routine, in which it clears the timer and counter and reinitializes them, and then starts counting again. The µC counts the value in hexadecimal format; the PC can then convert it to decimal format. In this example, we used a 12-MHz crystal and a baud rate of 2400 bps. However, you can use higher clock frequencies and baud rates, because the µC can operate to 24 MHz. We use the system in Figure 1 for photon counting in astronomical instrumentation. We give thanks to the Department of Space, Government of India, for material support and BG Anandarao, PhD, for encouragement.

Data Sheet for 89C2051, www.atmel.com.

Ayala, Kenneth J, The 8051 Microcontroller:Architecture, Programming and Applications (ISBN 0-314-77278-2), West Publishing Co, St Paul, MN.


ADVERTISEMENT

© 2009, Reed Business Information, a division of Reed Elsevier Inc. All Rights Reserved.