on Atmel AT902313
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)
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.
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.
You can build this without needing a printed circuit board, though it you really are anxious to, it sure would look neat. Layout isn't really critical, except that its a good idea to put the crystal and its load capacitors next to their associated pins on the AT90S2313, and its also a good idea to keep the I/O circuitry clear of the crystal circuitry. This should fall our naturally since, with the expectation of pin 9, the output pins are on the opposite side of the chip from the oscillator.
I mounted the LEDs and the I/O binding posts on the cover of a plastic box and stuck a piece of foam rubber in there to hold the circuit board steady so it won't rattle around.
I did a comparison of two chips running this program, one in the pulse generator mode and one in the frequency meter mode. The pulse generator seems to have some accuracy problems with very short periods. Note that the same results were obtained when using the pulse generator/frequency meter chip as when using the original pulse generator code for the pulse generator downloaded from the internet.
Programmed pulse interval 10, Measured frequency 111160
Programmed pulse interval 50 , Measured frequency 20416
Programmed pulse interval 100, Measured frequency 10105
Programmed pulse interval 1000, Measured frequency 1002
Programmed pulse interval 2000, Measured frequency 501
Programmed pulse interval 10000, Measured frequency 100.1
Programmed pulse interval 50000, Measured frequency 20.1
I trimmed the frequency meter timing loops by measuring the output of a frequency reference I made with a 74HCT4060 and a 4 MHz crystal and a 74HCT4040 12 stage divider. The fifth harmonic of the '4060 was zero beat with NIST station WWV by padding the capacitance from the crystal terminals to ground. The frequency meter was consistently within two counts of the output of frequency reference that was being measured.
Please see the liability disclaimer on the HOME page.
Contents ©2002 Richard Cappels All Rights Reserved