RS-232 Freq. Meter/Pulse Generator Based on Atmel ATtiny2313 using microcontroller

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.
Generator
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


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top