Design of digital frequency meter based on single chip microcomputer

Publisher:柳絮轻风Latest update time:2012-09-12 Source: 21ic Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The frequency meter is one of the experimental instruments we often use. In this experiment, we will use a single-chip microcomputer, a counting circuit and a liquid crystal device to design a wide-band frequency meter.

It is expected to achieve accurate frequency measurement in the range of 10Hz-1.1G.

Experimental circuit diagram (preliminary scheme)

1) Counting and display circuit:

Click to browse the next page

2) Preamplifier and frequency division circuit:

Design ideas

Frequency measurement is actually counting the signal within 1S, and the count value is the signal frequency. There are usually two ways to design a frequency meter using a single-chip microcomputer: 1) Use the built-in counter of the single-chip microcomputer to count the input pulses or measure the period of the signal; 2) Use a counter outside the single-chip microcomputer to count the pulse signal, and then read the count value by the single-chip microcomputer.

Since the frequency of the input clock of the microcontroller's built-in counter is usually only a few or even several tenths of the system clock frequency, using the microcontroller's counter to directly measure the signal frequency is greatly limited.

This experimental circuit adopts method 2, using a 74LS393 four-bit dual binary counter and the T1 counter of Atmega8 to form a 24-bit counter, and the maximum count value is 16777215. If the input signal is divided by 64 by the MB501 divider before measurement, the maximum measurement frequency under the fixed 1S time base is 1073.741760Mhz.

In order to obtain an accurate 1-second measurement gate signal, we used the asynchronous real-time clock function of Atmega8 and adopted a 32.768Khz crystal oscillator to generate a 1-second timing signal from TC2.

Measuring principle:

The single-chip microcomputer opens the measurement gate, that is, PB1 outputs a high level, and the TC2 timer starts. The 74LS393 starts to count the input pulses. Every time the 74LS393 counts to 256, the T1 counter of Atmega8 also counts up once. When the 1S timing is reached, the single-chip microcomputer generates an interrupt, PB1 outputs a low level to close the measurement gate, and then Atmega8 reads the count values ​​of 74LS393 and T1, and then sends them to the LCD for display.

Experimental progress

2004-09-27

According to the design ideas, we wrote a program and obtained some preliminary experimental results, as shown in the figure below. The figure below is the output result of measuring the 8M active crystal oscillator.

Click to browse the next page

Since the 1S measurement gate time is difficult to test under amateur conditions, the real-time clock is displayed on the LCD at the same time in the experimental program to determine the accuracy of the 1S gate time. In the experiment, I used the precise GPS satellite time displayed on a CDMA mobile phone for comparison. The smallest unit of mobile phone time display is minutes. When measuring, once the minute value of the mobile phone jumps, the second value displayed on the LCD is immediately recorded. In this way, after the frequency meter runs for a period of time, the seconds displayed on the LCD are recorded many times, and the asynchronous clock of the frequency meter can be accurately determined. During the experiment, I let the frequency meter run for about 10 decimal places, and the measured 1S clock was still very accurate. [page]

#include
#include
#include lcd.h
#include 6x8.h
#include chinese.h

/*-----------------------------------------------------------------------
LCD_init: 3310LCD initialization

Date of writing: 2004-8-10
Date of last modification: 2004-8-10
--------------------------------------------------------------------------------------*/
void LCD_init(void)
{
PORTB &= ~LCD_RST; // Generate a low level pulse to reset LCD
delay_1us();
PORTB |= LCD_RST;

PORTB &= ~LCD_CE ; // Disable LCD
delay_1us();
PORTB |= LCD_CE; // Enable LCD
delay_1us();

LCD_write_byte(0x21, 0); // Use extended commands to set LCD mode
LCD_write_byte(0xc8, 0); // Set bias voltage
LCD_write_byte(0x06, 0); // Temperature correction
LCD_write_byte(0x13, 0); // 1:48
LCD_write_byte(0x20, 0); // Use basic commands
LCD_clear(); // Clear the screen
LCD_write_byte(0x0c, 0); // Set display mode, normal display

PORTB &= ~LCD_CE ; // Turn off LCD
//LCD_clear();
}

/*-----------------------------------------------------------------------
LCD_clear: LCD screen clearing function

Date of creation: 2004-8-10
Date of last modification: 2004-8-10
-----------------------------------------------------------------------*/
void LCD_clear(void)
{
unsigned int i;

LCD_write_byte(0x0c, 0);
LCD_write_byte(0x80, 0);

for (i=0; i<504; i++)
LCD_write_byte(0, 1);
}

/*-----------------------------------------------------------------------
LCD_set_XY : Set LCD coordinate function

Input parameters: X: 0-83
Y: 0-5

Date of creation: 2004-8-10
Date of last modification: 2004-8-10
-----------------------------------------------------------------------*/
void LCD_set_XY(unsigned char X, unsigned char Y)
{
LCD_write_byte(0x40 | Y, 0); // column
LCD_write_byte(0x80 | X, 0); // row
}

/*-----------------------------------------------------------------------
LCD_write_char: display English characters

Input parameters: c: the character to be displayed;

Date of creation: 2004-8-10
Date of last modification: 2004-8-10
-----------------------------------------------------------------------*/
void LCD_write_char(unsigned char c)
{
unsigned char line;

//c -= 32;

//for (line=0; line<6; line++)
//LCD_write_byte(font6x8[c][line], 1);
for (line=0; line<7; line++)
LCD_write_byte(font7x13[c][line] , 1);
for (line=7; line<14; line++)
LCD_write_byte(font7x13[c][line], 1);

}

[page]

/*-----------------------------------------------------------------------
LCD_write_char: English string display function

Input parameters: *s: English string pointer;
X, Y: display string position

-------------------------------------------------- ---------------------*/
void LCD_write_String(unsigned char X,unsigned char Y,char *s)
{
unsigned char line;
unsigned char i=0;
while (*s)
{
LCD_set_XY(X+i*7,Y);
for (line=0; line<7; line++)
LCD_write_byte(font7x13[*s-0X30][line], 1);

LCD_set_XY(X+i*7,Y+1);
for (line=7; line<14; line++)
LCD_write_byte(font7x13[*s-0X30][line], 1);
s++;
i++;
}
}
/*-----------------------------------------------------------------------
LCD_write_chi: Display Chinese characters on LCD

Input parameters: X, Y: the starting X, Y coordinates of the displayed Chinese characters;
ch_with: the width of the Chinese character dot matrix
num: the number of displayed Chinese characters;
line: the starting row number in the Chinese character dot matrix array
row: the row spacing of the Chinese character display
-----------------------------------------------------------------------*/
void LCD_write_chi(unsigned char X, unsigned char Y,
unsigned char ch_with,unsigned char num,
unsigned char line,unsigned char row)
{
unsigned char i,n;

LCD_set_XY(X,Y); //Set the initial position

for (i=0;i {
for (n=0; n {
if (n==ch_with) //write the lower half of the Chinese character
{
if (i==0) LCD_set_XY(X,Y+1);
else
LCD_set_XY((X+(ch_with+row)*i),Y+1);
}
LCD_write_byte(china_char[line+i][n],1);
}
i++;
LCD_set_XY((X+(ch_with+row)*i),Y);
}
}

/*-----------------------------------------------------------------------
LCD_write_chi: Chinese character movement

[page]

Input parameters: X, Y: starting X, Y coordinates of displayed Chinese characters;
T: moving speed;

-------------------------------------------------- ---------------------*/
void LCD_move_chi (unsigned char X, unsigned char Y, unsigned char T)
{
unsigned char i,n,j=0;
unsigned char buffer_h[84]={0};
unsigned char buffer_l[84]={0};

for (i=0; i<156; i++)
{
buffer_h[83] = china_char[i/12][j];
buffer_l[83] = china_char[i/12][j+12];
j++;
if (j ==12) j=0;

for (n=0; n<83; n++)
{
buffer_h[n]=buffer_h[n+1];
buffer_l[n]=buffer_l[n+1];
}

LCD_set_XY(X,Y);
for (n=0; n<83; n++)
{
LCD_write_byte(buffer_h[n],1);
}

LCD_set_XY(X,Y+1);
for (n=0; n<83; n++)
{
LCD_write_byte(buffer_l[n],1);
}

delay_nms(T);
}
}

/*-----------------------------------------------------------------------
LCD_draw_map: bitmap drawing function

Input parameters: X, Y: starting X, Y coordinates of bitmap drawing;
*map: bitmap dot matrix data;
Pix_x: bitmap pixel (length)
Pix_y: bitmap pixel (width)

-------------------------------------------------- ---------------------*/
void LCD_draw_map(unsigned char X, unsigned char Y, unsigned char *map,
unsigned char Pix_x, unsigned char Pix_y)
{
unsigned int i,n;
unsigned char row;

if (Pix_y%8==0) row=Pix_y/8; //Calculate the number of rows occupied by the bitmap
else
row=Pix_y/8+1;

for (n=0;n {
LCD_set_XY(X,Y);
for(i=0; i {
LCD_write_byte(map[i+n*Pix_x], 1);
}
Y++; //Line break
}
}

/*-----------------------------------------------------------------------
LCD_write_byte : Use SPI interface to write data to LCD

Input parameters: data: data to be written;
command: write data/command selection;

-------------------------------------------------- ---------------------*/
void LCD_write_byte(unsigned char data, unsigned char command)
{
PORTB &= ~LCD_CE; // Enable LCD

if (command == 0)
PORTB &= ~LCD_DC ; // send command
else
PORTB |= LCD_DC ; // send data

SPDR = data; //Transmit data to SPI register

while ((SPSR & 0x80) == 0); // Wait for data transmission to complete

PORTB |= LCD_CE ; // Turn off LCD
}

Reference address:Design of digital frequency meter based on single chip microcomputer

Previous article:Fatigue driving detector based on head position characteristics of single chip microcomputer
Next article:AVR MCU LED Experiment

Recommended ReadingLatest update time:2024-11-16 17:52

ATmega88 External RC Oscillator
The chip can be driven by an external clock source, as shown in Figure 15. At this time, the CKSEL fuse bits must be programmed according to Table 15.
[Microcontroller]
ATmega88 External RC Oscillator
ATmega8 drives 74HC595 program
method one: //PC0 connects to data port SI 74HC595 14th pin  //PC1 connects to SCK 74HC595 11th pin  //PC2 connects to RCK 74HC595 12th pin  //74HC595 13th pin (/G) enables and connects to low level  //74HC595 10th pin (/SCLR) clears and connects to high level  #include iom8v.h   #include macros.h   #define uc
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号