Professional Documents
Culture Documents
Most frequency counters work by using a [counter] which accumulates the number of
events occurring within a specific period of time. After a preset period (1 second, for
example), the value in the counter is transferred to a display and the counter is reset to
zero. If the event being measured repeats itself with sufficient stability and the
frequency is considerably lower than that of the clock oscillator being used, the
resolution of the measurement can be greatly improved by measuring the time required
for an entire number of cycles, rather than counting the number of entire cycles
observed for a pre-set duration. Frequency counters are commonly used in laboratories,
factories, and field environments to provide direct frequency measurements of various
devices. The most common applications for frequency counters are measurement and
characterization of oscillator and transmitter frequencies.
CONTENTS
1. Introduction..3
1.1 Types of frequency meter.....3
1.2 Block Diagram... 4
2. The Basic Theory of Frequency Counter....5
2.1 Basic Counter Circuits....6
3. Hardware7
3.1 Microcontroller...7
3.1.1 Features..7
3.1.2 Pin diagram8
3.2 Counters....8
3.3 IN-1 Prescaler...9
3.4 IN-2 Pre-amplifier....9
3.5 By passing IN-2Amplifier....9
3.6 IN-2 Polarity Selector...9
3.7 Communication Port.9
4. Software....10
4.1 Measuring Modes...10
5. Power Supply12
5.1.1 Dual supplies...12
6. Liquid Crystal Display..14
6.1 Pin diagram.13
6.2 Pin Descriptions..15
7. Overview of Keil cross C compiler..18
7.1 Simulator/Debugger18
8. Proteus..19
9. Frequency counter applications19
2
10. Conclusion..19
References..20
Source code.21
FREQUENCY COUNTER/METER
1. INTRODUCTION
A frequency counter is an electronic instrument, or component of one, that is used
for measuring frequency. Frequency is defined as the number of events of a particular
sort occurring in a set period of time. Most frequency counters work by using a
counter which accumulates the number of events occurring within a specific period of
time. After a preset period (1 second, for example), the value in the counter is
transferred to a display and the counter is reset to zero. If the event being measured
repeats itself with sufficient stability and the frequency is considerably lower than that
of the clock oscillator being used, the resolution of the measurement can be greatly
improved by measuring the time required for an entire number of cycles, rather than
counting the number of entire cycles observed for a pre-set duration (often referred to
as the reciprocal technique). The internal oscillator which provides the time signals is
called the timebase, and must be calibrated very accurately. If the thing to be counted
is already in electronic form, simple interfacing to the instrument is all that is
required. More complex signals may need some conditioning to make them suitable
for counting. Most general purpose frequency counters will include some form of
amplifier, filtering and shaping circuitry at the input. DSP technology, sensitivity
control and hysteresis are other techniques to improve performance. The accuracy of a
frequency counter is strongly dependent on the stability of its timebase. Highly
accurate circuits are used to generate this for instrumentation purposes, usually using
a quartz crystal oscillator within a sealed temperature-controlled chamber known as a
crystal oven or OCXO (oven controlled crystal oscillator). In this project the circuit of
our designed frequency meter includes microcontroller, Liquid Crystal Display
(LCD), Cathode Ray Oscilloscope(CRO) and variable power supply unit.
attached pointer, can move. Frequencies in the middle of the meters range cause the
currents in the two coils to be approximately equal and the pointer to indicate the
midpoint of a scale. Changes in frequency cause an imbalance in the currents in the two
coils, causing them and, in turn, the pointer to move.
Another type of frequency meter, not of the deflection type, is the resonant-reed
type, ordinarily used in ranges from 10 to 1,000 Hz, although special designs can
operate at lower or higher frequencies. These work by means of specially tuned steel
reeds that vibrate under the effect of electric current; only those reeds that are in
resonance vibrate visibly, however.
Frequency counters designed for radio frequencies (RF) are also common and
operate on the same principles as lower frequency counters. Often, they have more
range before they overflow. For very high (microwave) frequencies, many designs use
a high-speed prescaler to bring the signal frequency down to a point where normal
digital circuitry can operate. The displays on such instruments take this into account
so they still display the correct value. Microwave frequency counters can currently
measure frequencies up to almost 100 GHz. Above these frequencies the signal to be
measured is combined in a mixer with the signal from a local oscillator, producing a
signal at the difference frequency, which is low enough to be measured directly.
When count number of cycles of the input signal for one second, the value of
frequency can be got in the counter. This can be realized by simple counter circuit so
that this was the conventional frequency measuring method. Many counter IC have
been released and many frequency counters that work in this method are being
shipped now. This is the simplest method but the measuring resolution is limited at
low frequency. To ensure more resolution, the gate time must be expanded: e.g. when
measure at resolution of 1 mHz, 1000 seconds is needed to measure one time.
Reciprocal Method
This is one of the frequency measuring methods that was thought out to make up the
defect of direct counting method, and it is prevailing now. This method measures the
period (T) of the input signal instead of number of cycles, and calculate its frequency
in the formula f = 1 / T with a microprocessor. Its frequency resolution depends on
only time resolution independent of the input frequency.
It can measure low frequency with high resolution quickly however any trigger gitter
due to noise decrease measuring resolution. To maintain sufficient time resolution, it
generally measures the period of several number of cycles. The reciprocal method
seems to also be implemented to cheap frequency counter because of price of
microcontrollers falls.
Every measuring method needs to control any clock signal. However using an AND
gate that shown in the diagram of principle will occur an extra count. The error rate
depends on the duty ratio of the clock signal: e.g. symmetrical clock signal occurs
+0.5 counts average. This cannot be ignored according to circumstance. At high
frequency of several MHz, this will not affect measuring accuracy, however input
signal of 99.7Hz results 100 or 101 Hz is not good.
This problem can be avoided by using a synchronous counter instead. In this circuit,
the rate of an extra count depends on only fractional number of less than 1, the clock
duty ratio doesn't affect to the extra count. However the synchronous counter can
occure any abnormal operation due to asynchronous input that is not
guaranteed ts and th. To avoid this problem, any care, such as separating counter
stages to insurate most synchronous block or synchronizing control signals with clock
to avoid that error, should be taken on this point.
3. HARDWARE
3.1 Microcontroller
There are different types of microcontrollers that can be used in frequency counter, in
this project the AT89C51 will be used .The AT89C51 is a low-power, highperformance CMOS 8-bit microcomputer with 4K bytes of Flash programmable and
erasable read only memory (PEROM). The device is manufactured using Atmels
high-density nonvolatile memory technology and is compatible with industry-standard
MCS-51 instruction set and pin out. The on-chip Flash allows the program memory to
be reprogrammed in-system or by a conventional nonvolatile memory programmer.
By combining a versatile 8-bit CPU with Flash on a monolithic chip, the AT89C51 is
a powerful microcomputer which provides a highly-flexible and cost-effective
solution to many embedded control applications.
3.1.1 Features
Compatible with MCS-51 Products
4K Bytes of In-System Reprogrammable Flash Memory Endurance: 1000
Write/Erase Cycles.
Fully Static Operation: 0Hz to 24MHz
Three-level Program Memory Lock
128 x 8- bit Internal RAM
32 Programmable I/O Lines
Two 16-bit Timer/Counters
Six Interrupt Sources
Programmable Serial Channel
7
3.2 Counters
The main counter that is the most important block in this universal counter is divided
into PLD (U1) and MCU (U2). The PLD part is a 12 bit counter. It can count up to
4096 and its most significant bit is connected to an external interrupt pin of the MCU,
the carry outs are counted by MCU. Therefore total counter length can be expanded
easy. In this system, a 36 bit counter of 12+24 bit is implemented. The frequency of
the carry out from PLD becomes approx 30 kHz at 120 MHz of input signal, this can
be counted with interrupt process easy. The operating frequency of the PLD is 84
MHz minimum, but it worked at over 140 MHz.
To read the counter value in the PLD, a reading mode is used. In this mode, the gate
signal from the MCU is routed as a counting clock and the counter gate is opened.
Then clock the gate signal until a carry out occurs, the counter value can be calculated
with: Counter value = 4096 - number of clocks. Any additional circuit to read the
counter is not required, however there is a problem that software loop of up to 4096
times (4.5 msec in AVR) is required. When a shift register to read the counter is
8
implemented, it can be read quickly. But there was not enough left logic cells for the
shift register.
communication interface must be isolated from its system ground. The interface is an
EIA-574 compatible serial port that is isolated with optical isolators.
4. SOFTWARE
4.1 Measuring Modes
This universal counter have two basic operating modes. One is frequency counting
mode that counts incoming signal, other is interval measuring mode that counts
reference clock gated by incoming signal.
In the Frequency Mode, selected input signal is routed as a counter clock. The gate
signal is generated with a timer unit in the MCU and applied to the PLD externally.
This can generate variable gate time easy. The operation is a sequential loop that reset
counter, open gate for a reference time and then display counter value as a frequency.
The gate lamp is lit during gate is opened, and wait for 30 msec before each
measuring operation to blink gate lamp to indicate refresh timing.
In the Time Interval Mode, the reference clock is routed as a counter clock. The gate
signal is generated by input signal. The operation is a sequential loop that reset
counter and gating block, wait for end of one gate time by monitoring PLD status
(CEN and EOC), read counter value and adjust it with scaling factor and then display
it. This mode is also used at reciprocal frequency measuring mode.
is for only time interval measurement, not designed for reciprocal method. This
mode is an additional measure ring mode with the time internal modes. It would
be able to implemented full functional logic if a higher density PLD is used
instead. Therefore this mode is suitable for only low input frequency, as for high
frequency,
direct
counting
method
will
do.
The top image of this page shows that measuring 400 Hz test signal and last digit
is not steady. It seems that is 6 digits resolution because of repeating the time
measuring operation for one second and calculating frequency from its average.
Mode
3
(Cycle
Time
[ms])
This mode measures cycle period of rising edges (falling edges at IN-2 inverting
mode). The display format is 0000.0000 ms, it can display up to 10 seconds in
resolution of 100 nsec. Since the reference clock is 12.8 MHz, actual time
resolution is approx. 78 nsec, the counter value is divided by 1.28 and scaled in to
100 nsec resolution.
Mode
4
(Pulse
Width
Time
[ms])
This mode measures pulse width of high levels (low levels at IN-2 inverting
mode). Any other funcitons are same as mode 3.
Selecting Coupling Mode and Trigger Polarity (([Cupl],[Pol] button)
These buttons change coupling mode and trigger polarity of IN-2.
Hold Display ([Hold] button)
This button stops and restarts measureing operateion. In hold mode, display will blink
to indicate that it is in the hold mode. When no result is displayed after mode change
or hold release, wait for a new result and then enter hold mode.
Expanding Gate Time ([Hold]+[Mode] button)
This function changes gate time at mode 0 and 1. The gate time is expanded 10 times
and frequency resolution is magnified 10 times. However the most decimal points of 7
segment LEDs are used for other status, so that the display format is not changed. Of
course output value to the communication port is scaled.
Serial Communication
The serial data format is N81, 2400bps. Measured values are sent as a line each at the
time of the display is updated. It can be saved as a CSV file. Especially the Microsoft
Excel can directly read results into the cells with VBA. When collect any time
intervals, it is a simple time interval analyzer.
The universal counter can also be controlled by serial commands form host. The
command character is not echo-backed, and each functions are as follows:
MODE<n><CR>
Select operation mode. <n> determines requested mode number which can be 0 to
4.
11
CPL<n><CR>
Select IN-2 coupling mode. 0 selects AC coupled, 1 selects TTL coupled.
POL<n><CR>
Select IN-2 trigger polarity 0 selects rising edge (high level), 1 selects falling
edge (low level).
GATE<n><CR>
Select gate time in mode 0 and 1. 0 selects normal, 1 selects expand to 10 times.
5. POWER SUPPLY
A power supply (sometimes called a power supply unit or PSU) is a device or
system that supplies electrical or other types of energy to an output load or group of
loads. The term is most commonly applied to electrical energy supplies, less often to
mechanical ones, and rarely to others.
Dual supplies have three outputs, for example a 9V supply has +9V, 0V and -9V
outputs.
Transformer only
The low voltage AC output is suitable for lamps, heaters and special AC motors. It is
not suitable for electronic circuits unless they include a rectifier and a smoothing
capacitor.
Transformer + Rectifier
The varying DC output is suitable for lamps, heaters and standard motors. It is not
suitable for electronic circuits unless they include a smoothing capacitor.
Transformer + Rectifier + Smoothing
The smooth DC output has a small ripple. It is suitable for most electronic circuits.
Transformer + Rectifier + Smoothing + Regulator
13
The regulated DC output is very smooth with no ripple. It is suitable for all electronic
circuits.
2.
Incorporation of a refreshing controller into the LCD, thereby relieving the CPU
to keep displaying the data.
3.
The connections are laid out in one of the two common configurations, either two
rows of seven pins, or a single row of 14 pins. One of the, pins are numbered on the
LCDs print circuit board (PCB), but if not, it is quite easy to locate pin1. Since this
pin is connected to ground, it often has a thicker PCB track, connected to it, and it is
generally connected to metalwork at same point.
The enable pin is used by the LCD to latch information presented to its data pins.
When data is supplied to data pins, a high-to-low pulse must be applied to this pin in
order for the LCD to latch in the data present at the data pins. This pulse must be a
minimum of 450ns wide.
D0-D7
The 8-bit data pins, D0-D7, are used to send information to the LCD or read the
contents of the LCDs internal registers. To display letters and numbers, we send
ASCII codes for the letters A-Z, a-z, and numbers 0-9 to these pins while making
RS=1.
We also use RS=0 to check the busy flag bit to see if the LCD is ready to receive
information. The busy flag is D7 and can be read when R/W=1 and RS=0, as follows:
if R/W=1, RS=0. When D7=1 (busy flag=1), the LCD is busy taking care of internal
operations and will not accept any information.
16
Manager or Linker (again specifying a list of controls) and finally running the ObjectHEX Converter to convert the Linker output file to an Intel Hex File. Once that has
been completed the Hex File can be downloaded to the target hardware and debugged.
Alternatively KEIL can be used to create source files; automatically compile, link and
covert using options set with an easy to use user interface and finally simulate or
perform debugging on the hardware with access to C variables and memory. Unless
you have to use the tolls on the command line, the choice is clear. KEIL Greatly
simplifies the process of creating and testing an embedded application.
7.1 Simulator/Debugger
The simulator/ debugger in KEIL can perform a very detailed simulation of a micro
controller along with external signals. It is possible to view the precise execution time
of a single assembly instruction, or a single line of C code, all the way up to the entire
application, simply by entering the crystal frequency. A window can be opened for
each peripheral on the device, showing the state of the peripheral. This enables quick
trouble shooting of mis-configured peripherals. Breakpoints may be set on either
assembly instructions or lines of C code, and execution may be stepped through one
instruction or C line at a time. The contents of all the memory areas may be viewed
along with ability to find specific variables. In addition the registers may be viewed
allowing a detailed view of what the microcontroller is doing at any point in time.
The Keil Software 8051 development tools listed below are the programs you use to
compile your C code, assemble your assembler source files, link your program
together, create HEX files, and debug your target program. Vision2 for Windows
Integrated Development Environment: combines Project Management, Source Code
Editing, and Program Debugging in one powerful environment.
C51 ANSI Optimizing C Cross Compiler: creates relocatable object modules
from your C source code,
A51 Macro Assembler: creates relocatable object modules from your 8051
assembler source code,
BL51 Linker/Locator: combines relocatable object modules created by the
compiler and assembler into the final absolute object module,
LIB51 Library Manager: combines object modules into a library, which may be
used by the linker,
OH51 Object-HEX Converter: creates Intel HEX files from absolute object
modules.
8. PROTEUS
In Greek mythology, Proteus () is an early sea-god, one of several deities
whom Homer calls the "Old Man of the Sea", whose name suggests the "first" (from
Greek "_" - protos, "first"), as protogonos () is the "primordial" or
the "firstborn". He became the son of Poseidon in the Olympian theology (Odyssey iv.
432), or of Nereus and Doris, or of Oceanus and a Naiad, and was made the herdsman
of Poseidon's seals, the great bull seal at the center of the harem. He can foretell the
future, but, in am theme familiar from several cultures, will change his shape to avoid
having to; he will answer only to someone who is capable of capturing him. From this
feature of Proteus comes the adjective protean, with the general meaning of
"versatile", "mutable", "capable of assuming many forms". "Protean" has positive
connotations of flexibility, versatility and adaptability. The earliest attested form of the
18
10. CONCLUSION
The frequency meter using 8051 displays the value of frequency of the waveforms
given to the CRO from the power supply on the LCD. Depending on the input value
given to the CRO the value of the frequency changes.
In total, the complete system (including all the hardware components and software
routines) is working as per the initial specifications and requirements of our project.
So certain aspects of the system can be modified as operational experience is gained
with it. As the users work with the system, they develop various new ideas for the
development and enhancement of the project.
References
1.
2.
3.
4.
5.
6.
http://grietinfo.in/projects/MINI/EEE/DOC-A.12-frequencymeter.pdf http://www.radio-electronics.com/info/t_and_m/
http://elm-chan.org/works/uctr/report.html
http://www.apogeekits.com/counter_article.htm
http://en.wikipedia.org/wiki/Frequency_counter
http://grietinfo.in/projects/MINI/EEE/DOC-A.12-frequencymeter.pdf
19
SOURCE CODE
#include<reg51.h>
sbit intr=P3^4;
sfr ldata=0x90;
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2;
void lcdcmd(char );
void delay(int);
void lcddata(int);
void lcddata1(char *value);
void main()
{
int i,l,H,k;
//char n;
while(1)
{
TMOD=0x15;
intr=1;
TL0=0x00;
TH0=0x00;
TR0=1;
for(i=0;i<28;i++)
{
TL1=0x00;
20
TH1=0x00;
TR1=1;
while(TF1==0);
TR1=0;
TF1=0;
}
P0=TL0;
l=TL0;
H=TH0;
k=l+H;
//H=H*0xf0;
lcdcmd(0x0E);
delay(250);
lcdcmd(0x01);
delay(250);
//lcdcmd(0x06);
//delay(250);
//lcdcmd(0x86);
//delay(250);
lcddata1("Frequecy=");
delay(100);
lcddata(k);
//lcddata(H);
delay(250);
}
}
void lcdcmd(char value)
{
ldata = value;
rs=0;
21
rw=0;
en=1;
delay(2);
en=0;
}
/*void lcddata(int value)
{
ldata=value;
rs=1;
rw=0;
en=1;
delay(2);
en=0;
}*/
void delay(int time)
{
int i,j;
for(i=0;i<time;i++)
for(j=0;j<125;j++);
}
void lcddata(int value)
{
int a[4],i,send=0,n=0;
for(i=0;value!=0;i++)
{
send=value%10;
value=value;
a[i]=send;
n++;
}
22
for(i=n-1;i>=0;i--)
{
ldata=a[i]+0x30;
rs=1;
en=1;
delay(1);
en=0;
}
return;
}
void lcddata1(char *name)
{
int i;
for(i=0;name[i]!='\0';i++)
{
P1=name[i];
rs=1;
rw=0;
en=1;
delay(1);
en=0;
}
return;
7.
23