Design of a simple tachometer based on PIC16F877 microcontroller

Publisher:ZenMaster123Latest update time:2013-11-08 Source: dzscKeywords:PIC16F877 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

  0 Introduction

  With the rapid development of microelectronics technology, single-chip microcomputers have been widely used in automobiles, communications, office automation, industrial control, advanced toys, household appliances, etc. If Proteus is used as a single-chip microcomputer system simulation tool, there is no need to make circuit boards, but Proteus can be used for system virtualization. This can not only complete the required functional design verification, but also reduce the consumption of hardware costs, thereby shortening the entire design cycle and fundamentally improving the development efficiency of electronic products.

  Speed ​​measurement is a common problem in industrial and agricultural production. Based on the various advantages of single-chip microcomputers, it is of great significance to apply single-chip microcomputers to speed measurement systems. For speed measurement technology, the first thing to solve is the sampling problem. When using analog technology to make speed measurement equipment, the speed measuring generator method is often used, that is, the shaft of the speed measuring generator is connected to the shaft to be measured, and the voltage of the speed measuring generator reflects the speed; when using a single-chip microcomputer for speed measurement, a simple pulse counting method can be used.

  As long as the shaft generates one or more fixed pulses every time it rotates, and the pulses are sent to the microcontroller for counting, the number of pulses per unit time is finally calculated, and the relevant information of the speed can be obtained. This article will complete the pulse counting based on the capture function of the PIC16F877 microcontroller, use software programming to realize the conversion of relevant physical relationships, and finally obtain the gear linear speed and display it on the digital tube.

  1 Principle of tachometer

  1.1 CCP1 Capture Function

  There are two CCP modules in the PIC16F877 microcontroller, which have basically the same structure and are denoted as CCP1 and CCP2. Each CCP module can be configured as one of the three functional modes: Capture, Compare and Pulse Width Modulation (PWM).

  The capture mode of CCP1 has the following three functions: first, it can capture the jump of RC2/CPP1 pin and save the content of TMR1 count register at that time; second, it has a prescaler, which can realize capture once every 1 pulse, every 4 pulses or every 16 pulses; third, the capture time can generate an interrupt.

  1.2 CCP tachometer principle

  In capture mode, the microcontroller can capture the time value when the pin level changes, that is, the precise time value when the rising or falling edge of the pin input pulse occurs.

  When the CCP1 module of PIC16F877 works in capture mode, when a specific transition edge occurs, the count value of the TMR1 timer will be immediately copied to CCPR1H and CCPR1L and an interrupt signal will be generated. This 16-bit count value is read in the interrupt service program. When the capture function of the CCP1 module is used to measure the time interval between two adjacent rising edges, this time interval is the period g-Period of the input signal. Since the main frequency is 4 MHz, that is, each instruction cycle is 1 μs, the pre-scaling ratio is set to 1:1, and the unit of the measured period result is microseconds. Therefore, the final measured speed value speed is obtained by the following formula:

  speed=(1M*60s*0.01m*pi)/g_Period

  Among them, pi is the value of pi; 0.01m is the diameter of the gear being measured, which is measured by physical methods.

  speed=(1M*60s*0.01m*pi)/g_Period

  Among them, pi is the value of pi; 0.01m is the diameter of the gear being measured, which is measured by physical methods.

  2 Function Implementation

  2.1 System Design Block Diagram

  The tachometer function can be realized by several parts including the main control module based on PIC16F877, the display module, and the module under test consisting of gears and photoelectric sensors.

  The module under test and the measuring submodule are connected through the RC2/CCP1 pin of the microcontroller. During the Proteus software simulation, the signal generator SG1 and the frequency meter are connected as hardware devices. SG1 is used to simulate the signal generated by the module under test. F1 operates in the frequency meter mode to display the current signal frequency and is used as a reference value to compare with the display module data, that is, the speed measurement result value of the speed meter, to verify whether the speed measurement result of the speed meter is correct. The connection relationship between the modules is shown in Figure 1. [page]

  

  2.2 Solution Design and Implementation

  The design and implementation of this simple speedometer is mainly based on the CCP module function of PIC16F877. Here we first configure CCP1 of PIC16F877 to capture mode, set the prescaler ratio to 1:1, and trigger on every rising edge.

  When the jump is captured, the CPP1 interrupt flag is set and the interrupt method is used directly for processing, that is, the value or state change of the relevant register is processed in the interrupt service subroutine, and the relevant physical quantity is calculated and stored. The above settings are all completed by software programming.

  

  2.2 Design and Implementation

  The design and implementation of this simple speedometer is mainly based on the CCP module function of PIC16F877. Here we first configure CCP1 of PIC16F877 to capture mode, set the prescaler ratio to 1:1, and trigger on every rising edge.

  When the jump is captured, the CPP1 interrupt flag is set and the interrupt method is used directly for processing, that is, the value or state change of the relevant register is processed in the interrupt service subroutine, and the relevant physical quantity is calculated and stored. The above settings are all completed by software programming.

  

  3 Functional Simulation

  3.1 Construction of simulation circuit under Proteus

  To complete the simulation of the tachometer function in Proteus, you should first create a new design file in its interface and build a simulation circuit diagram. The circuit diagram of the tachometer function in this example is shown in Figure 4. [page]

  

  When simulating in Proteus software, each electronic module in the library has an integrated drive function, so each module and the microcontroller only need to be connected with a simple connection line without any external drive circuit. However, when actually making the circuit board, it is still necessary to add the drive circuit of each module and consider the spacing between each device to avoid electromagnetic interference.

  3.2 Functional Simulation

  The code for each module is written in MPLAB IDE 8.90, a dedicated development environment for PIC series microcontrollers. After compilation and running, the design file created in Proteus software is loaded and run using the debugging tool Proteus VSM. The result is shown in Figure 5.

  

  3.3 Simulation Results Analysis

  As shown in Figure 5 above, when the signal frequency is configured to 3 000 Hz, the simulation result, i.e. the speed of the tachometer, is displayed as 5 660 m/s, and fluctuates within a small range with the speed value as the center. The speed value calculated theoretically is about 5 655 m/s, which is basically the same as the simulation value. In fact, by taking the average value after continuous measurement of n cycles, the error between the theoretical value and the simulation value will be significantly reduced.

  4 Conclusion

  This paper proposes a simple tachometer design based on the capture function of the PIC16F877 microcontroller. After simulation verification under Proteus software, the design basically meets the expected results. The entire tachometer design in the scheme is simple and convenient, low cost, small speed measurement error, and easy to implement. After modularization, it can be directly used as an integrated speed measurement module in other designs.

Keywords:PIC16F877 Reference address:Design of a simple tachometer based on PIC16F877 microcontroller

Previous article:Portable electronic scale based on single chip microcomputer
Next article:Portable electronic scale based on PIC16F628 microcontroller

Recommended ReadingLatest update time:2024-11-16 15:58

Application of PIC16F877 microcontroller in DC motor closed-loop speed regulation system
0 Introduction        In modern industrial production, electric motors are the main driving equipment. Currently, thyristor (i.e. controlled silicon) devices are widely used in electric drag systems to supply power to motors. The KZ-D drag system has replaced the bulky generator. The FD system of the motor, along with
[Industrial Control]
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号