Audio frequencies mean the range of frequencies that a normal human can hear through his ears. It is from 20 Hz to 20 KHz. But in general, practically most of the sounds we hear around us are in the frequency range of 100 Hz to 2000 Hz.
Some time when we listen to some sound we become curious and want to find out what is the frequency of this sound. Some time it may become necessary to measure the frequency of output sound or any audible tone to do further analysis. So to measure such all kind of audible sound – audio frequency it is required to have audio frequency counter that displays frequency of audio signal or audio tone.
The project presented here counts the audio frequency and displays on LCD screen. It uses micro controller AT89C52 that counts frequency of applied input signal and displays it on 16×2 LCD screen. It has two modes of operation
- Single – counts frequency only once. To count again the operation has to be started again by pressing reset button
- Continuous – counts frequency in loop. Continuously counts incoming signal frequency and updates display after every second
(Check the circuit diagram tab for complete circuit for Audio Frequency Counter)
Circuit description:
· The frequency input is given to base input of NPN transistor Q1 through diode D1 and current limiting resistor R1
· The transistor is connected in switch configuration and its collector output is connected with timer 0 input and INT1 (external interrupt 1) input of micro controller AT89C52
· An LED is connected to pin P1.0 as shown
· One SPDT switch is connected to P3.7 such that it can give logic 1 or logic 0 input to pin
· A capacitor C1 is connected in between Vcc supply and reset input pin (9) to provide “power on reset”
· A push button is connected in parallel with C1 between Vcc supply and reset pin that is used for manual reset
· A 12 MHz crystal along with two 33 pF capacitors is connected to crystal input pins XTAL1 and XTAL2
· Port P2 drives data pins D0-D7 of LCD. Two LCD control pins RS and En are connected with P0.0 and P0.1 respectively. RW pin is connected to ground
· One 1 K potentiometer is connected to VEE pin of LCD as shown to vary LCD brightness
Circuit operation:
· Input signal is applied to diode D1. It rectifies AC signal – means clamps negative cycles. Thus it prevents negative input to micro controller
· The transistor further converts all kind of input signals (sinusoidal, triangle etc) into pulses
· As the transistor output is applied to both interrupt input as well as timer/counter input of micro controller, the first negative edge to micro controller will generate an interrupt and it will start counting pulses till 1 second
· The RED LED will be ON to indicate pulse counting process
· After exact 1 second micro controller will stop counting and displays count on LCD as frequency because frequency = number of pulses in 1 second
· If SW1 connects P3.7 to ground and gives low logic then the operation continuous and micro controller continuously counts frequency and displays it
· And if SW1 is on Vcc position then micro controller counts frequency only once and then stops
· To count again the operation has to be start by pressing reset push button
The complete circuit operation is due to the program loaded into the internal FLASH memory of micro controller. . All the functionalities are implemented using software logic and program.
Software program:
The program performs following tasks
· It handles LCD screen and displays frequency on it
· It generates exact 1 sec delay
· It counts pulses for 1 second period
· It indicated counting process on LED
· Checks status of SPDT switch and counts only once or count continuous
The program is written in C language. It is compiled using KEIL (IDE) cross compiler tool. It is compiled for generic 8051 micro controller platforms so it can be used for all different micro controllers of MCS51 family like 89C51 / 89C52 / 89S52 etc. After compiling the program the HEX file is generated. That HEX file is loaded into the internal FLASH (EEPROM) of micro controller using any suitable EEPROM programmer.
Fig. 1: Prototype of 8051 Microcontroller based Audio Frequency Counter
Project Source Code
###
#include<reg51.h>
#include<string.h>
sbit rs = P0^1; // rs pin of LCD
sbit en = P0^0; // en pin of LCD
sbit led= P1^0;
sbit sw = P3^7;
unsigned int flag=0; // flag
void delay() // 1 sec delay
{
int k;
TL1 = 0xBF; // load value 15535=3CAF
TH1 = 0x3C;
TR1 = 1;
for(k=0;k<100;k++)
{
while(TF1==0);
TF1 = 0;
TL1 = 0xBF;
TH1 = 0x3C;
}
TR1 = 0;
}
void busy() // check LCD busy
{
int x;
for(x=0;x<1500;x++);
}
void writecmd(unsigned char a) // send command byte to LCD
{
busy();
rs = 0;
P2 = a;
en = 1;
en = 0;
}
void writedata(unsigned char b) // send data byte to LCD
{
busy();
rs = 1;
P2 = b;
en = 1;
en = 0;
}
void writestr(unsigned char *s) // write string / message to LCD
{
unsigned char l,i;
l = strlen(s);
for(i=0;i<l;i++)
{
writedata(*s);
s++;
}
}
void int1(void) interrupt 2 // external interrupt 1 function
{
EA=0; // first disable interrupts
led=0;
TH0=0x00; // clear T0
TL0=0x00;
TR0=1; // start timer 0
delay(); // give 1 sec delay
TR0=0; // stop timer
flag=1; // if not then set the flag
led=1;
}
void display() // convert hex to desimal and
{ // decimal to ascii
unsigned int tmp1,tmp2,tmp3,t,t1,i,j;
unsigned char asci[4];
tmp1 = (TL0 & 0x0F);
tmp2 = TL0 >> 4;
tmp3 = (TH0 & 0x0F);
tmp2 = tmp2*16;
tmp3 = tmp3*256;
t = tmp1+tmp2+tmp3;
t=t*12;
i=3;
if(t>=1000)
{
while(t>=10)
{
t1=t%10;
asci[i]=t1+0x30;
t=t/10;
i--;
}
asci[0]=t+0x30;
}
else
{
while(t>=10)
{
t1=t%10;
asci[i]=t1+0x30;
t=t/10;
i--;
}
asci[1]=t+0x30;
asci[0]=0x20;
}
writecmd(0xC0);
for(j=0;j<3;j++)
writedata(asci[j]); // all four digits one by one
writestr(" ");
}
void main()
{
TMOD=0x15;
// timer 0 in 16 bit counter and timer 1 in 16 bit counter
P2 = 0x00; // P1 as output port
rs=0; // clear all LCD control pins
en=0;
sw=1;
led=0;
led=1;
writecmd(0x3C); // initialize LCD
writecmd(0x0E);
writecmd(0x01);
writestr("Audio Frequency"); initially display message
writecmd(0xC0);
writestr("Counter"); //
IT1=1;
IE=0x84; // enable external interrupt 1
next:while(flag==0); // remain within loop till flag is clear
display(); // when flag is set display freuqency
flag=0; // reset the flag to 0 again
EA=1; // again enable interrupts
if(sw==0) goto next; // if switch is 0 go for next measurement
while(1); // otherwise stop operation
}###
Circuit Diagrams
Project Video
Filed Under: Electronic Projects
Filed Under: Electronic Projects
Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.