ARM7 LPC2138 digital frequency meter design source code and report

Publisher:世界因你而精彩Latest update time:2019-10-15 Source: eefocusKeywords:ARM7 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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);

[1] [2]
Keywords:ARM7 Reference address:ARM7 LPC2138 digital frequency meter design source code and report

Previous article:Linux-ARM Interrupt GIC Analysis
Next article:LPC2138+LCD1602 counter proteus simulation and source code adding comments and changing pins

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号