1.1 Design Principle
Frequency is the number of times a periodic signal changes within a unit time (1s). If the number of repeated changes of this periodic signal measured within a certain time interval T is N, then its frequency can be expressed as f=N/T. Among them, f is the frequency of the measured signal, N is the number of pulses accumulated by the counter, and T is the time generated by N pulses. The result recorded by the counter is the frequency of the measured signal. The counting method, also known as the frequency measurement method, is a method of adding the measured signal to the counter through a timing gate for counting. If the gate is opened for T, the count value obtained by the counter is N1, then the measured frequency is f=N1/T. Changing the time T can change the measurement frequency range. Assuming that during T, the precise count value of the counter should be N. According to the counting characteristics of the counter, the absolute error of N1 is N1=N+1, and the relative error of N1 is ΔN1=(N1-N)/N=1/N. From the relative error of N1, it can be seen that the larger the value of N, the smaller the relative error, which is inversely proportional. Therefore, under the condition that f is determined, in order to reduce the relative error of N, the measurement error can be reduced by increasing T. When T is a certain value (usually 1s), f1=N1, and f=N, so the relative error of f1 is: Δf1=(f1-f)/f=1/f From the above formula, it can be seen that the relative error of f1 is inversely proportional to f, that is, the higher the signal frequency, the smaller the error; and the lower the signal frequency, the greater the measurement error. Therefore, the frequency measurement method is suitable for measuring high-frequency signals. The higher the frequency, the higher the measurement accuracy.
1.2. Solution Selection
The timing method is also called the period measurement method. The period measurement method uses the measured signal to control the opening and closing of the gate, and the standard time base pulse is added to the counter through the gate. The gate is opened within one cycle of the external signal. In this way, the count value obtained by the counter is the period value of the external signal of the standard time base pulse. Then, the reciprocal of the period value is calculated to obtain the measured frequency value. However, since the signal period data obtained by the timing method still needs to be calculated in reverse to obtain the signal frequency, and the reciprocal calculation is difficult to achieve using small and medium-scale digital integrated circuits, the timing method is not suitable for the requirements of this experiment.
The counting method is suitable for measuring higher frequency signals. The measurement error of the frequency measurement method is inversely proportional to the signal frequency. The lower the signal frequency, the greater the measurement error, and the higher the signal frequency, the smaller the error. However, the measurement data obtained by the frequency measurement method does not require any conversion when the gate time is one second. The data counted by the counter is the signal frequency. According to the performance and technical indicators required by this design, it is first necessary to determine the frequency measurement method that can meet these indicators. Therefore, the frequency measurement method used in this experiment is the frequency measurement method.
Figure 1.1 Principle block diagram and waveform diagram
2.1 Schematic Design
Figure 2.1 Proteus circuit diagram
2.2 Programming
Figure 2.2 Program flow chart
3. Simulation results
Use proteus and Keil software to compile the program correctly and generate a HEX file, then use protest to simulate. Modify the transmission frequency and observe the results.
Figure 3.1 Simulation results
4. Physical debugging
4.1 Debugging Results
When the frequency of the signal transmitter input is a 2kHz square wave, the LCD display also shows 2k. When the transmission frequency is 3kHz, the display shows 3k. It can be concluded that the actual object has realized the function and achieved the corresponding accuracy.
4.1 Physical debugging
4.2 Problems encountered during debugging
Since we needed to burn the compiled program into our board, we were not very clear about how to use the program at that time, so the LCD did not display anything at first. We always thought it was a problem with the board and the display, so we wasted a lot of time. Later, after understanding the usage of the program, we successfully burned the program, connected the partial program circuit board we had soldered before, and debugged it, and finally achieved success.
5. Design summary
This design made me realize the bitterness and sweetness of designing programs, connecting schematics, and debugging. Design is a skill that we must have, and this internship gave us a good opportunity to practice. I found information from the library to design programs and connect schematics. In the process, I learned a lot of new knowledge, and became more proficient in the application of Keil and Proteus. I felt the powerful functions of these software. When the debugging was successful, it felt magical and incredible, and it deepened my impression of this knowledge.
During the design process, we set the timer to count mode. Therefore, the highest counting frequency is 1/4 (11.0592MHz) of the clock frequency (44.2368MHz), but we divide it by 100, so we can only measure 110kHz in the end. Due to the display problem, the fixed characters in the front have occupied many places, so we can only reach 9999Hz.
During the design process, you must not be impatient. Design and debugging must be done step by step. This time during the design process, because I was not familiar with the pin functions of LPC2138 at the beginning, I was always confused during the design process. After checking the information and studying carefully, I was able to distinguish them clearly. Especially when modifying the program, I must not be careless. If a letter is wrong, the compilation will fail. In the final debugging process, because the simulation results are already accurate, it is very frustrating not to debug the results, and it also delays time. It is recommended to have more good development boards. If it were not for the problems with the development board and the display, perhaps our progress could be faster.
LPC2138 source code:
#include"LPC213x.h"
#define uint unsigned int
#define uchar unsigned char
int g_sample_cnt;
#define RS 1<<5
#define RW 1<<6
#define EN 1<<7
#define KEY_MC (1<<31)
#define KEY_RST (1<<30)
#define KEY_NIGHT (1<<29)
fly num,i;
uchar table1[]={"frequency: hz "};
fly table2[]={" "};
uint HZ[]={ 0x08,0x0F,0x12,0x0F,0x0A,0x1F,0x02,0x00, 0x0F,0x09,0x0F,0x09,0x0F,0x09,0x11,0x00,
0x0F,0x09,0x09,0x0F,0x09,0x09,0x0F,0x00};
void DelayNs(uint NS)
{ uint i;
for(;NS>0;NS--)
for(i=0;i<500;i++);
}
void writecom(uint com)
{
IO0CLR=RS;
IO0PIN=(IO0PIN&0X00FF)+(com<<8);
DelayNs(1);
IO0SET=ONE;
IO0CLR=ONE;
}
void writedata( uint data)
{
IO0SET=RS;
IO0PIN=(IO0PIN&0X00FF)+(data<<8); //P0=data;
DelayNs(1);
IO0SET=ONE;
IO0CLR=ONE;
}
void init()
{
BRUSH0=0X00000000;
IO0DIR =0XFFFF;
IO0CLR=RW;
IO0CLR=ONE;
writecom(0x38);
writecom(0x0c);
writecom(0x06);
writecom(0x01);
}
int mile=0,premile=0;
int night=0;
int lowmode=0;
int price=0;
int lowmodefirsttime=0;
int price_low=0;
static int lowmodetime=0;
void __irq IRQ_Timr0(void)
{
table1[10]=g_sample_cnt/1000%10+'0'; table1[11]=g_sample_cnt/100%10+'0';
table1[12]=g_sample_cnt/10%10+'0';
table1[13]=g_sample_cnt%10+'0';
writecom(0x80);
for(num=0;num<21;num++)
{
writedata(table1[num]);
DelayNs(1);
}
writecom(0x80+0x40);
for(num=0;num<21;num++)
{
writedata(table2[num]);
}
g_sample_cnt=0;
T0IR = 0x01;
VICVectAddr = 0x00;
}
/**********************************************************
void Timer0Init(void)
{
//Fcclk = Fosc*4 = 11.0592MHz*4 = 44.2368MHz
//Fpclk = Fcclk/4 = 44.2368MHz/4 = 11.0592MHz
T0PR = 99; // Set the timer 0 division frequency to 100 division frequency, 110592Hz
T0MCR = 0x03; // Match channel 0 match interrupt and reset T0TC
T0MR0 = 150350; // comparison value (1S timing value)
T0TCR = 0x03; // Start and reset T0TC
T0TCR = 0x01;
VICIntSelect = 0x00;
VICVectCntl0 = 0x20|4;
VICVectAddr0 = (unsigned long)IRQ_Timr0;
VICIntEnable = 1<<4;
}
void main()
{
heat();
writecom(0x80);
DelayNs(100);
Timer0Init();
for(num=0;num<19;num++)
{
writedata(table1[num]);
DelayNs(1);
}
//writecom(0x40);
// for(num=0;num<24;num++)
// {
// writedata(HZ[num]);
// }
writecom(0x80+0x40);
for(num=0;num<19;num++)
{
writedata(table2[num]);
}
PINSEL1 &=0x00ffffff;
//IODIR =0xe83fffff;
IO1DIR |=0xff000000;
//writedata(0x00);
//writedata('4');
//writedata(0x01);
//writedata('2');
//writedata('6');
//writedata(0x02);
IO1DIR&=~KEY_MC;
IO1DIR&=~KEY_RST;
IO1DIR&=~KEY_NIGHT;
mile=325400;
lowmodetime=lowmodefirsttime=price=premile=mile=0;
while(1)
{
#if 1
if((IO1PIN&KEY_MC)==0)
{
g_sample_cnt+=1;
//DelayNs(1);
Previous article:Linux-ARM Interrupt GIC Analysis
Next article:LPC2138+LCD1602 counter proteus simulation and source code adding comments and changing pins
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Ranking of installed capacity of smart driving suppliers from January to September 2024: Rise of independent manufacturers and strong growth of LiDAR market
- Industry first! Xiaopeng announces P7 car chip crowdfunding is completed: upgraded to Snapdragon 8295, fluency doubled
- P22-009_Butterfly E3106 Cord Board Solution
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- CC3200 Documentation and Examples
- How to amplify a voltage signal of about 20mv from 0.3MHZ to 1MHZ
- GD32E231 DIY Competition (3) GD32E231C reads ADC sampling value
- Internal functions of MSP430
- When filling out college entrance examination applications, which majors must be chosen carefully?
- Differences between CPU and CLA and Error Handling Techniques
- EEWORLD University Hall ---- Pattern Recognition National University of Defense Technology Cai Xuanping
- ST32F103x Read the sensor value on X-NUCLEO-IKS01A3 via I2C
- Need help designing a CAN communication solution between two MCUs!
- 【NUCLEO-WL55JC2 Review 1】 Overview of STM32WL Chip