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:
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.
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 initializationDate 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 displayPORTB &= ~LCD_CE ; // Turn off LCD
//LCD_clear();
}/*-----------------------------------------------------------------------
LCD_clear: LCD screen clearing functionDate 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 functionInput parameters: X: 0-83
Y: 0-5Date 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 charactersInput 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
}
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
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- EEWORLD University ---- Live playback: The most important component of the analog world - Signal chain and power supply: Amplifier special
- Help, how to calculate the voltage gain of an amplifier circuit?
- Electronic password lock based on single chip microcomputer
- Anlu SparkRoad FPGA development board interface definition
- Analysis and Design of TL431 Feedback Loop
- Understanding the past, present and future of the Matter Protocol in one article
- Schematic diagram of various application circuits of LM324
- [Voice and vision module based on ESP32S3]-The materials have not arrived yet, so use ESPcam to test QR code recognition first
- Circuit Schematic Analysis Method
- Hongmeng Development Board Neptune (Part 3) - Problems encountered in the development environment