It is expected to achieve accurate frequency measurement in the range of10hz-1.1g.
Experimental circuit diagram (preliminary scheme)
1) Counting and display circuit:
2) Pre-amplification and frequency division circuit:
Design concept
The measurement of frequency is actually counting the signals within 1, and the calculated value is the signal frequency. There are usually two ways to design a frequency meter with a single chip microcomputer: 1) using the counter of the single chip microcomputer to count the input pulses or measure the period of the signal; 2) A counter is used outside the single chip microcomputer to count the pulse signals, and the count value is read by the single chip microcomputer.
Because the frequency of the input clock of the single chip microcomputer counter is usually only a fraction or even a few tenths of the system clock frequency, it is very limited to measure the signal frequency directly with the single chip microcomputer counter.
In this experiment, a 74LS393 four-bit binary counter from Atmega8 and T 1 counter are used to form a 24-bit counter, and the maximum count value is 167772 15. If the input signal is divided by MB50 1 frequency divider and measured, the highest measurement frequency is 1073.45438+0760 MHz under the fixed time base of1s.
In order to get the accurate 1 sec measurement gate signal, we use the asynchronous real-time clock function of Atmega8 to generate the 1 sec timing signal from TC2 with a 32.768Khz crystal oscillator.
Measuring principle:
Single chip microcomputer opens the measuring gate, that is, PB 1 outputs high level, and TC2 timer starts at the same time. 74LS393 starts counting input pulses. When the 74LS393 counts to 256, the T 1 counter of Atmega8 also counts up 1 time. When 1 reaches a fixed time, the single chip microcomputer generates an interrupt, PB 1 outputs a low level to close the measuring gate, and then Atmega8 reads the count values of 74LS393 and T 1, and then sends them to the LCD for display.
Experimental progress
2004-09-27
According to the design idea, some experimental results are obtained, as shown in the following figure. The following figure shows the output result of measuring 8M active crystal oscillator.
Because the door measuring time of 1S is not easy to test under amateur conditions, the real-time clock is displayed on the LCD at the same time in the experimental program to judge the accuracy of the door measuring time of1s. In the experiment, I compared the precise time of GPS satellite displayed on CDMA mobile phone. The minimum unit of time display on mobile phone is minutes. When measuring, once the minute value of the mobile phone jumps, the second value displayed by the LCD will be recorded immediately. In this case, after the frequency meter runs for a period of time, the seconds displayed by the LCD will be recorded several times, so that whether the asynchronous clock of the frequency meter is accurate can be accurately judged. In the experiment, I let the frequency meter go about 10 decimal place, and the measured 1S clock is still very accurate.
# Including
# Including
# including lcd.h
# including 6x8.h
# including Chinese. h
/* -
LCD_init: 33 10LCD initialization
Date of writing: August 2004-10
Last revision date: August 2004-10
- */
void LCD_init(void)
{
Port & amp= ~ LCD _ RST;; //Generate a low-level pulse to reset the LCD.
delay _ 1us();
PORTB | = LCD _ RST;
Port & amp= ~ LCD _ CE///Turn off the LCD.
delay _ 1us();
PORTB | = LCD _ CE// Enable LCD.
delay _ 1us();
LCD_write_byte(0x2 1,0); //Use the extended command to set the LCD mode.
LCD_write_byte(0xc8,0); //Set the bias voltage
LCD_write_byte(0x06,0); //Temperature correction
LCD_write_byte(0x 13,0); // 1:48
LCD_write_byte(0x20,0); //Use basic commands
LCD _ clear(); //Clear the screen
LCD_write_byte(0x0c,0); //Set the display mode to normal display.
Port & amp= ~ LCD _ CE///Turn off the LCD.
//LCD _ clear();
}
/* -
LCD_clear: LCD screen clearing function.
Date of writing: August 2004-10
Last revision date: August 2004-10
- */
void LCD_clear(void)
{
Unsigned int I;;
LCD_write_byte(0x0c,0);
LCD_write_byte(0x80,0);
for(I = 0; I & lt504; i++)
LCD_write_byte(0, 1);
}
/* -
LCD_set_XY: Set the LCD coordinate function.
Input parameters: x: 0-83
Y :0-5
Date of writing: August 2004-10
Last revision date: August 2004-10
- */
Void LCD_set_XY (unsigned character x, unsigned character y)
{
LCD_write_byte(0x40 | Y,0); //column
LCD_write_byte(0x80 | X,0); //line
}
/* -
LCD_write_char: displays English characters.
Input parameters: c: displayed characters;
Date of writing: August 2004-10
Last revision date: August 2004-10
- */
Void LCD_write_char (unsigned character c)
{
Unsigned character line;
//c-= 32;
//for(line = 0; line & lt6; line++)
//LCD _ write _ byte(font 6x 8[c][line], 1);
for(line = 0; line & lt7; line++)
LCD _ write _ byte(font 7x 13[c][line], 1);
for(line = 7; line & lt 14; line++)
LCD _ write _ byte(font 7x 13[c][line], 1);
}
/* -
LCD_write_char: English character string display function
Input parameter: *s: English string pointer;
X, y: displays the position of the string.
Date of writing: August 2004-10
Last revision date: August 2004-10
- */
Void LCD_write_String (unsigned character x, unsigned character y, character *s)
{
Unsigned character line;
Unsigned character I = 0;;
while (*s)
{
LCD_set_XY(X+i*7,Y);
for(line = 0; line & lt7; line++)
LCD _ write _ byte(font 7x 13[* s-0x 30][line], 1);
LCD_set_XY(X+i*7,Y+ 1);
for(line = 7; line & lt 14; line++)
LCD _ write _ byte(font 7x 13[* s-0x 30][line], 1);
s++;
i++;
}
}
/* -
LCD_write_chi: displays Chinese characters on the LCD.
Input parameters: x, y: display the initial x, y coordinates of Chinese characters;
Ch_with: width of Chinese character lattice
Num: displays the number of Chinese characters;
Line: the starting line number in the Chinese character dot matrix array.
Line: Displays the space between lines of Chinese characters.
Date of writing: August 2004-1 1
Last revision date: August 2004-12.
- */
Void LCD_write_chi (unsigned character x, unsigned character y,
Unsigned character ch_with, number of unsigned characters,
Unsigned character lines, unsigned character lines)
{
Unsigned characters 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 part of Chinese characters.
{
if (i==0) LCD_set_XY(X,Y+ 1);
other
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
Input parameters: x, y: display the initial x, y coordinates of Chinese characters;
T: moving speed;
Date of writing: August 2004-13
Last revision date: August 2004-13.
- */
Void LCD_move_chi (unsigned character x, unsigned character y, unsigned character t)
{
Unsigned characters I, n, j = 0;;
Unsigned charbuffer _ h [84] = {0};
Unsigned charbuffer _ 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 & lt83; n++)
{
buffer _ h[n]= buffer _ h[n+ 1]。
Buffer _ l[n]= buffer _ l [n+1];
}
LCD_set_XY(X,Y);
for(n = 0; n & lt83; n++)
{
LCD_write_byte(buffer_h[n], 1);
}
LCD_set_XY(X,Y+ 1);
for(n = 0; n & lt83; n++)
{
LCD_write_byte(buffer_l[n], 1);
}
delay _ NMS(T);
}
}
/* -
LCD_draw_map: bitmap drawing function
Input parameters: x, y: initial x and y coordinates of bitmap drawing;
*map: bitmap dot matrix data;
Pix_x: Bitmap pixel (length)
Pix_y: Bitmap pixel (width)
Date of writing: August 2004-13
Last revision date: August 2004-13.
- */
void LCD_draw_map(unsigned char X,unsigned char Y,unsigned char *map
Unsigned character Pix_x, unsigned character Pix_y)
{
Unsigned int i, n;
Unsigned character line;
if(Pix _ y % 8 = = 0)row = Pix _ y/8; //Calculate the number of rows occupied by the bitmap.
other
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++; //newline
}
}
/* -
LCD_write_byte: Use SPI interface to write data into LCD.
Input parameters: data: written data;
Command: write data/command selection;
Date of writing: August 2004-10
Last revision date: August 2004-13.
- */
Void LCD_write_byte (unsigned character data, unsigned character command)
{
Port & amp= ~ LCD _ CE///Enable LCD.
If (command == 0)
Port & amp= ~ LCD _ DC;; //Send command
other
PORTB | = LCD _ DC; //transmit data
SPDR = data; //Transfer data to SPI register
And ((spsr &; 0x 80)= = 0); //Wait for the data transmission to be completed
PORTB | = LCD _ CE// Turn off the LCD.
}