Summary of RS-232 Freq. Meter/Pulse Generator Based on Atmel ATtiny2313 using microcontroller
This project describes a compact, firmware-only frequency meter and pulse generator using an AT90S2313 microcontroller. Designed for field experiments in Nondu, Thailand, it eliminates physical front-panel controls by communicating via an RS-232 terminal at 9600 baud. The device combines two functions: counting frequencies up to 4 MHz with selectable time bases and generating pulses with adjustable periods, widths, and amplitudes via a resistor ladder network. Timing loops were chosen over interrupts for measurement stability.
Parts used in the Frequency Meter/Pulse Generator:
- AT90S2313 microcontroller
- 7805 5 volt regulator
- Two LEDs
- Current limiting resistors
- Maxim MAX232 interface chip
- Resistor ladder network
- Bipolar transistor (for ESD protection)
- RS-232 terminal program
Simplicity in circuitry was the design direction. Zero mass (firmware only with no physical components) would the ultimate achievement. This instrument doesn’t have any front panel controls because the user interacts via an RS-232 terminal program at 9600 baud.
I needed a frequency meter for my experiments in Nondu, Thailand, where I really don’t have room for a lot of instruments. I wrote some straight forward code to read the 16 bit counter in the AT90S2313 after period of time, which was determined by running a timing loop. By the way, I tried various approaches using interrupts from the 8 bit timer to set the counting interval, but found timing uncertainty resulted in intolerable jitter in the measurements, to as inelegant as it is, timing loops turned out the be give the best results. The results of the counts are converted to ASCII and sent to the terminal. After finishing the frequency meter, I realized that only half the Flash ROM was used and that I could fit a handy pulse generator program I found on the web into the same chip, but having two instruments in one. The result is a combined counter and frequency meter. The chip flips between the two programs, The only things common between the two programs is some initialization and some of the serial port I/O code. The pulse generator firmware is pretty much as originally published, except that I modified it to drive a resistor network so as to allow the pulse output amplitude to be selectable.
The user controls teh device and reads data via an ASCII terminal set to 9600 baud, 1 stop bit, no parity. I use a terminal emulation program I found on the net, named “Term.exe”. The input and output are via the same terminal.
Salient features of the pulse generator
– 10 us to 65.5 ms pulse period
– 5 us to 65 ms pulse width
– 3 bits of selectable pulse amplitude (2^3 binary coded amplitudes). You design the ladder network for your needs.
Salient features of the frequency meter
– Counts to 65536 (all you can get from the 16 bit counter on the ‘2313)
– Selectable time base of 0.1, 1.0, 10, and 100 seconds.
– 4 Mhz max frequency (this can be increased if you change the crystal and rewrite the timing loops for both sections of the code)
Assembly code
Here is the assembly code for the micro controller. If you’re really lazy, here’s the AVR programmer hex file , and here’s the MacAVRpa hex file .
Note that this code can be modified for use on other AVR controllers. Rafael Alcocer in the Philippines has reported using this successfully on an AT90S8515 after adding an instruction to initialize the high register in the stack pointer. One must initialize both the high and low stack pointer registers on AVR devices that can address more than 255 bytes of RAM.
The circuit
Power input is to a 7805 5 volt regulator. A pair of LEDs is connected between the 5 volt supply and ground, with current limiting resistors in series and one pin on the AT90S2313 shunts the current through one LED or the other. When one LED is on, the device is “ready”, that is not generating pulses on the output and not measuring input frequency. When the other LED is on, the devise is actively generating pulses or measuring frequency. As a consequence, one of the LEDs is on at a time allowing quick visual confirmation that power is applied and the state of the device.
The serial interface is the AT90S2313’s internal UART connected to the outside world via RS-232 using a Maxim MAX232 interface chip, which derives RS-232 drive voltages from the 5 volt supply.
The output of the pulse generator is via a resistor ladder network. I chose the values I did so that I would have a few low-amplitudes to select from and still be able to drive 5 volt CMOS with the maximum level pulses. If I were to do it over, I would probably just use an R-2R ladder network. Pin 9 doubles as an input and output pin, thus it is connected as the MSB of the ladder network so that it can be exposed to the full amplitude input signal (without attenuation). To provide a measure of protection against electrostatic discharge and clumsy handling of test leads, a reverse biased emitter-base junction of a bipolar transistor is used. The junction will avalanche when the voltage exceeds at high positive voltages and enters forward conduction when the voltage swings negative. The collector of the transistor is left floating.
For more detail: RS-232 Freq. Meter/Pulse Generator Based on Atmel ATtiny2313 using microcontroller
- How does the user interact with the device?
The user interacts via an RS-232 terminal program set to 9600 baud since there are no front panel controls. - Why were timing loops used instead of interrupts?
Timing loops were used because interrupt approaches resulted in intolerable jitter in the measurements. - What is the maximum frequency this meter can count?
The meter counts up to a maximum frequency of 4 MHz using the 16 bit counter on the '2313. - Can the pulse amplitude be adjusted?
Yes, the pulse output amplitude is selectable with 3 bits of binary coded amplitudes via a resistor network. - What time bases are available for the frequency meter?
The device offers selectable time bases of 0.1, 1.0, 10, and 100 seconds. - How does the device indicate its current state visually?
One of two LEDs is always on; one indicates ready status while the other indicates active generation or measurement. - Is this code compatible with other AVR controllers?
Yes, the code can be modified for other AVR controllers like the AT90S8515 after initializing stack pointer registers. - What protects the circuit from electrostatic discharge?
A reverse biased emitter-base junction of a bipolar transistor is used to protect against high positive and negative voltage swings.

