当前位置:网站首页>51 single chip microcomputer measures the period of square wave signal
51 single chip microcomputer measures the period of square wave signal
2022-07-25 03:48:00 【Rape and white spicy chicken】
utilize T0 As timer ,T1 As a counter ;
Main idea :
1、T1 Count , Working mode : The way 2;T0 timing , Working mode : The way 1
2、T1 Octet count , Assign initial value to 0xFF, Turn on interrupt , Start counting (P3.5 Input the measured square wave signal )
3、 Get into T1 interrupt : if TR0=0, Start timing TR0=1,TH/L1=0xF6( Measure ten cycles ); if TR0=1, Then stop timing TR0=0 And stop counting TR1=0; Record the current T0 Timing results , Get the period of the square wave .
Be careful :
- TH/L1=0xF6 For measuring ten cycles , The purpose is to increase the measured value , Reduce the proportion of measurement error . If it is deleted, the time of one cycle will be measured .
- T0 Work in the way 1 There are sixteen , At most one time 71ms( Crystal oscillator :11.0592MHz)
- T0 The result should be converted into time according to the crystal vibration frequency of the single chip microcomputer , If the crystal oscillator is 11.0592M, You need to ×12/11.0592(us)
C51 Timer settings
// Timer settings
void Init_T(){
TMOD=0x61; //T1 Counting works in 2 Pattern ;T0 Timing work in 1 Pattern
TL0=0x00;
TH0=0x00; //T0 Initial value 0, It can be timed 71ms
TL1=0xFF;
TH1=0xFF; //T1 Initial value 255, Count 1 Trigger interrupt ;
EA=1;
ET1=1;// Turn on T1 interrupt
ET0=1;// Turn on T0 interrupt
TR1=1;
TR0=0;
}// Timer interrupt setting
void timer1() interrupt 3 using 2{
if(!TR0){
TH0=0x00;
TL0=0x00;
TH1=0xF6;
TL1=0xF6;
TR0=1;
}
else{
TR0=0;
TR1=0;
time=0;
time=TH0;
time=time<<8;
time=time|TL0;
}
}If you feel this article is useful, just give it a compliment and encouragement @[email protected]
If there are other methods to accurately measure the period or think this article is wrong , Welcome to the comment area or private letter discussion and exchange ~
边栏推荐
- Use go language to import Doris data through stream load
- Implementation of online number or fan query of the scene
- Servlet个人实操笔记(一)
- C language introduction practice (9): completion judgment
- A 20 yuan facial cleanser sold tens of thousands in seven days. How did they do it?
- Many local and municipal supervision departments carried out cold drink sampling inspection, and Zhong Xue's high-quality products were all qualified
- MySQL select query part 2
- Force deduction problem 238. product of arrays other than itself
- ES (8.1) certification topic
- 基于ABP实现DDD--领域逻辑和应用逻辑
猜你喜欢

Solve "nothing added to commit but untracked files present"“

Analysis of DNS domain name resolution process

Acwing 870. approximate number

Original | ueditor1.4.3-asmx bypasses WAF

P100 MSSQL database penetration test of secondary vocational network security skills competition

Advantages and disadvantages of zero trust security

基于SSH婴幼儿产品销售系统

Machine learning notes - building a recommendation system (4) matrix decomposition for collaborative filtering

A code takes you to draw multi format sangjimei pictures such as interactive +pdf+png

292. Nim game
随机推荐
Experience sharing of system architecture designers in preparing for the exam: how to prepare for the exam effectively
Use of CCleaner
Pytorch deep learning practice lesson 8 importing data
01_ Education 4
Lombok detailed introduction
Chrome debugging skills
The relationship between private domain traffic and fission marketing. What is super app? Can our enterprise own it?
"Introduction to interface testing" punch in to learn day04: how to abstract the procedural test script into a test framework?
Wechat applet access wechat payment process
Secondary vocational network security skills competition P100 vulnerability detection
How does Jupiter notebook change themes and font sizes?
Image processing based on hog feature
基于SSH婴幼儿产品销售系统
[Flink] transform operator filter
Interview question 08.07. Permutation and combination of non repeated strings DFS method
Detailed explanation of kubernetes network plug-in - flannel chapter
Moveit2 - 8. Motion planning API
Force button brushing question 61. rotating linked list
CVPR 2020 | social stgcnn: pedestrian trajectory prediction based on graph convolution
Network construction and application in 2020 -- the answer of samba in Guosai