当前位置:网站首页>Speed measurement based on 51 single chip microcomputer and Hall sensor
Speed measurement based on 51 single chip microcomputer and Hall sensor
2022-04-22 06:00:00 【*wj】
1. Introduction to small projects
Mainly adopts stc89c51/52 Single chip microcomputer as the main controller , The hall sensor is used as the basic module of speed measurement , Use the key to control the speed , The nixie tube displays the current speed .
The final finished product is shown as follows :

2. Power part
1. The power supplied by the power supply should be as large as possible , I'm powered by Rolex power bank (5V,2.1A outlet ). Because the power supply is too small , The motor will not be able to drive , Or digital tube flashing and other hardware bug.
2. If the voltage of the power supply is higher than 5V, A voltage stabilizing circuit needs to be used at the power input , Stabilize the input voltage to 5V To MCU , And other peripherals . Prevent device damage caused by high voltage .
3. hardware component
1. stc89c51/52 The smallest system of

Be careful : If you use the general USB Interface power supply , When the motor rotates , The pin power supply of MCU may be unstable , Therefore, it is necessary to use the single chip microcomputer IO External pull-up and drain resistance .P3 You don't need to .
9 Needle drainage resistance is as follows : The smaller end is the common end , Need and power 5V Connect , The other ports are welded with the pins of the single chip microcomputer one by one .

2. Hall sensor

Pay attention to the pins , On the narrow side, the pin sequence :

there VOUT The port can be directly connected to the external interrupt of the single chip microcomputer 1 mouth , It can pass through a voltage comparator lm393 Something like that is giving the MCU .

3. DC motor drive
51 Single chip microcomputer IO The output current of the port is too small , The effect of driving DC motor is not obvious , Can't reach the later speed change , Need to use a triode (9015\9013 This kind can ) The amplifier circuit drives the motor : The demonstration circuit is as follows :( The resistance shall be modified according to their own needs )

4. Common cathode nixie tube
// Digital tube position selection
sbit S1=P2^4;
sbit S2=P2^5;
sbit S3=P2^6;
sbit S4=P2^7;
// Digital tube segment selection :P1 Eight of IO mouth . When connecting, be sure to select according to the segment shown in the following figure ( Pay attention to pay attention to : Easy to connect wrong )

4. Software part
1. Overall drawing of software engineering :

2.main.c File code :
Create your own 51 Single chip microcomputer keil Engineering documents , Copy the following code to your project file main.c Just replace the file
/************************************************************************************** * be based on 51 Single chip microcomputer speed measurement * Realization phenomenon : Press the button K1 Slow down Press the button K2 Speed up External interrupt 1 Corresponding IO mouth P3^3 matters needing attention : The motor speed shall not be too fast , Otherwise, the nixie tube display will be unstable ***************************************************************************************/
#include "reg52.h" // This file defines some special function registers of MCU
typedef unsigned int u16; // Declare and define data types
typedef unsigned char u8;
// Test port ( Decide according to your own needs )
sbit led=P0^0; // The of single chip microcomputer P0.0 The port is defined as led
/************************************************************************************** **************************** The core part of the ************************************************* ***************************************************************************************/
// Duty cycle
u16 time = 0; // Variable that defines the duty cycle
u16 count=30; // Define the upper duty cycle limit
sbit PWM=P0^1;// P0.1 Output pwm
// Speed
u16 zhuansu=0; // The initial value of speed is 0
u16 jishu = 0; //jishu The initial value of the variable is 0
u8 flag = 0; // Timer 1 Count variables
// Key
sbit k1=P2^0;
sbit k2=P2^1;
sbit k3=P2^2;
sbit k4=P2^3;
// Digital tube position selection
sbit S1=P2^4;
sbit S2=P2^5;
sbit S3=P2^6;
sbit S4=P2^7;
// Digital tube position selection :P1 Eight of IO mouth
// Common cathode nixie tube segment selection
u8 code smgduan[]={
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};// Show 0~F Value
// The nixie tube stores intermediate variables
unsigned char Display_data[4];
/******************************************************************************* * Letter Count name : delay * The functionality : The time delay function ,i=1 when , About time delay 10us *******************************************************************************/
void delay(u16 i)
{
while(i--);
}
// Timer and external interrupt 1 Initialization function for
void InitSyetem()
{
// Configure external interrupts 1: Collect the falling edge triggered by Hall sensor
IT1 = 1; // Select the falling edge trigger
EX1 = 1; // Open external interrupt 1
// Timer 0,1 Operation mode 1
TMOD=0x11; // Timing or counting mode control register
// Timer 0 To configure : produce PWM wave
TH0=(65536-10)/256;// When the initial value is given 10us
TL0=(65536-10)%256;//s
ET0=1;// Turn on the timer 0 interrupt
TR0=1;// Start timer 0
// timing 1: velocity measurement
TH1=(65536-10000)/256;// When the initial value is given 10ms
TL1=(65536-10000)%256;
ET1=1;// Turn on the timer 0 interrupt
TR1=1;// Start timer 0
PX1=1;// set priority
PT1=1;// Set timer 1 Is the highest priority
EA=1;// General interruption
}
// external 1 Interrupt service function
void Service_Int1() interrupt 2
{
jishu++; // Hall's falling edge counts the number of times at a time
if(jishu == 100) // The cumulative count has 100 Time , The total time is 100 * 10ms = 1s
{
led^=led; //led flashing
}
}
// timing 0 The processing function generates PWM Speed regulation principle ——— stay PWM Drive the motor to rotate at high level stay PWM Stop the motor at low level
void Service_Timer0() interrupt 1
{
TR0=0;// When assigning initial value , off timer
TH0=(65536-10)/256;// When the initial value is given
TL0=(65536-10)%256;//0.01ms
TR0=1;
time++; // Count variables
if(time>=100) time= 0; // Clear flag variable
if(time<=count) // Less than the set value , Output high level
{
PWM = 1;
}
else
PWM = 0;
}
// Timer 1 Interrupt processing displays the speed
void Service_Timer1() interrupt 3
{
TR1=0;// When assigning initial value , off timer
TH1=(65536 - 10000) / 256;
TL1=(65536 - 10000) % 256;// timing 10ms
TR1=1;
flag++; // Count variable plus
if(flag==100) // Time to arrive 1s Measure the speed at this time
{
// led=~led; //led State inversion
zhuansu = jishu; // Monitor the total number of counts of the hall sensor
jishu=0; // Speed setting 0
flag=0; // Clear count variable
}
}
// Nixie tube processing function
void Deal_data()
{
Display_data[3]=smgduan[zhuansu/1000]; // High digital tube
Display_data[2]=smgduan[zhuansu/100%10];// Go to second
Display_data[1]=smgduan[zhuansu/10%10];
Display_data[0]=smgduan[zhuansu%10]; // Nixie tube low position
}
/******************************************************************************* * Letter Count name : DigDisplay * The functionality : Digital tube dynamic scanning function , Circular scanning 4 A digital tube display ****************************************************** *************************/
void DigDisplay()
{
u8 i;
for(i=0;i<4;i++)
{
switch(i) // Biting , Choose the LED that lights up ,
{
case 0 : S1 = 0; S2 = 1; S3 = 1; S4 = 1;break; // Light up the first digital tube
case 1 : S2 = 0; S1 = 1; S3 = 1; S4 = 1;break;
case 2 : S3 = 0; S1 = 1; S2 = 1; S4 = 1;break;
case 3 : S4 = 0; S1 = 1; S2 = 1; S3 = 1;break;
}
P1=Display_data[i];// Send segment code
delay(5); // Scan at intervals The less time , Light up together and the more stable the display ; The more time , It's running water that lights up
P1=0x00;// Blanking When time is too fast , Each nixie tube will have ghosting
}
}
/******************************************************************************* * Letter Count name : keypros * The functionality : Key handling functions , Judge button K1 Whether to press *******************************************************************************/
void keypros()
{
if(k1==0) // Test button K1 Whether to press
{
delay(100); // Eliminate jitter It's about 10ms Estimation of time 100*n=1(s)
if(k1==0) // Judge whether the key is pressed again
{
led=~led; //led State inversion
count+=10;
if(count >= 90) // Set an upper limit
count+=90;
}
while(!k1); // Check whether the key is released If it is false, it means that the key is not released
}
if(k2==0) // Test button K1 Whether to press
{
delay(100); // Eliminate jitter It's about 10ms
if(k2==0) // Judge whether the key is pressed again
{
led=~led; //led State inversion
count-=10;
if(count <= 10)
{
count = 10;
}
}
while(!k2); // Check whether the key is released
}
}
/******************************************************************************* * Letter Count name : main * The functionality : The main function * transport Enter into : nothing * transport Out : nothing *******************************************************************************/
void main()
{
led = 0; // Power on and turn off the small light
P1 = 0x00; // Power on initialization and turn off the nixie tube
InitSyetem();// Timer and external interrupt 1 Initialization function for
while(1)
{
keypros(); // Key handling functions
Deal_data(); // Data processing functions
DigDisplay(); // Nixie tube display function
}
}
版权声明
本文为[*wj]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220541420204.html
边栏推荐
- stm32学习笔记5——RGB屏相对位置计算
- [2022 Ali security] real scene tampering image detection challenge final rank17 scheme sharing
- C/S架构
- Integer splitting problem (dynamic programming + recursion & record array)
- LeetCode 2055. Plates between candles -- prefix and + interval mark
- 第72篇 LeetCode题目练习(五) 5.最长回文子串
- Summary of MySQL knowledge points
- 苹果 CMS 搭建视频网站,定时采集视频
- 12 - 容器-字符串
- AIX上安装gcc并使用
猜你喜欢

Torch uses stepping on the pit diary and matrix to speed up the operation

B/S架构

Cytoscape installation tutorial

Blue Bridge Cup 31 day sprint day16

14 - container - tuple
![Optimization theory: transportation problem (I) finding the minimum freight [northwest corner method, minimum element method, Vogel method]](/img/c3/922f8e94087f5ec279601a10f78818.png)
Optimization theory: transportation problem (I) finding the minimum freight [northwest corner method, minimum element method, Vogel method]

STM32学习笔记4——HC_SR04超声波测距模块的调试记录

Blue Bridge Cup 31 day sprint Day8

05-变量及标识符

Blue bridge sprint topic - BFS
随机推荐
14 - 容器-元组
STM32学习笔记4——HC_SR04超声波测距模块的调试记录
16 - 容器综合训练
Summary of MySQL knowledge points
STM32学习笔记3——GPIO的输入引脚
15 - 容器 - 字典
软件测试相关基础知识
Maximum continuous subsequence sum (enumeration + divide and conquer + online processing)
写一篇关于ddt数据驱动的自动化测试
第86篇 LeetCode剑指Offer动态规划(三)股票的最大利润
Blue Bridge Cup 31 day sprint day23
The unit of the total length slice offset of the header in an IP datagram
Why is softmax commonly used instead of sigmoid in binary classification tasks
第74篇 LeetCode题目练习(七) 7.整数反转
Apple CMS builds a video website and collects videos regularly
c语言开发postgres自定义函数
第90篇 LeetCode剑指Offer动态规划(七)最长不包含重复字符的子字符串
VB操作excel 格式设置及打印页面设置(精简)
The postgraduate entrance examination is over
Torch uses stepping on the pit diary and matrix to speed up the operation