1、基于霍尔元件的自行车速度感应器设计摘 要随着居民生活水平的不断提高,自行车不再仅仅是普通的运输、代步的工具,而是成为人们娱乐、休闲、锻炼的首选。自行车的速度里程表能够满足人们最基本的需求,让人们能清楚地知道当前的速度、里程等物理量。本论文主要阐述一种基于霍尔元件的自行车的速度里程表的设计。以 AT89C52 单片机为核心,A44E 霍尔传感器测转数,实现对自行车里程/速度的测量统计,采用 24C02 实现在系统掉电的时候保存里程信息,并能将自行车的里程数及速度用LED实时显示。文章详细介绍了自行车的速度里程表的硬件电路和软件设计。硬件部分利用霍尔元件将自行车每转一圈的脉冲数传入单片机系统,然后
2、单片机系统将信号经过处理送显示。软件部分用汇编语言进行编程,采用模块化设计思想。该系统硬件电路简单,子程序具有通用性,完全符合设计要求。关键词:里程/速度;霍尔元件;单片机;LED显示IIABSTRACTWith the developing of peoples life, the bicycle is not only the universal tool of transportation and substitute for walking, but becomes the first choice of entertainment and exercising. The bicycl
3、e mileage/speed can fulfill the basic need of peoples life, so that they can learn the speed and the mileage of the bicycle. In this paper, the bicycle mileage/speed design based on the Hall element is elaborated. By AT89C52 as kernel, using A44E Hall element to measure revolution, the measure and s
4、tatistic are achieved. The range information is saved by 24C02 when the power is off, the bicycle speed can be displayed on LED. In this article, the hardware circuit and software design of bicycle mileage/speed instrument are introduced in detail. About the hardware, the pulse number is transmitted
5、 of one cycle of the bicycle into Single Chip Microcomputer system. Then the signal processed by Single Chip Microcomputer system is sent to display scream. About the software, in assemble language; the program is designed in the mode of modules. The system has simple hardware, common sub-program, a
6、nd meets the demand of design.KEY WORDS: Mileage / speed; Hall element; Single chip microcomputer; LED 目 录目 录1 绪 言11.1 课题背景11.2 课题的主要任务及内容12 自行车的速度里程表总体方案设计22.1 任务分析与实现22.2 自行车的速度里程表硬件方案设计22.3 自行车的速度里程表软件方案设计43 自行车的速度里程表硬件电路设计53.1 概述53.2 传感器及其测量系统53.2.1 霍尔传感器的测量原理53.2.2 集成开关型霍尔传感器63.3 单片机的原理及应用73.3.
7、1 单片机原理简介73.3.2 单片机的引脚功能介绍83.3.3 单片机中断系统介绍103.3.4 单片机定时/计数功能介绍113.4 其他器件的介绍123.4.1 存储器的介绍123.4.2 74LS74芯片的介绍133.4.3 74LS244芯片的介绍143.5 单片机外围电路的设计143.5.1 时钟电路的设计143.5.2 复位电路的设计153.5.3 显示电路的设计163.5.4 报警电路的设计174 自行车的速度里程表软件程序设计184.1 概述184.2 自行车的速度里程表总体程序设计184.3 中断子程序的设计204.4 数据处理子程序的设计204.5 显示子程序的设计225
8、系统调试与分析245.1 系统仿真调试245.2 调试故障及原因分析246 结论与展望266.1结论266.2 展望26致 谢27参考文献28附 录29 IV1 绪 言1 绪 言1.1 课题背景自行车被发明及使用到现在已有两百多年的历史,这两百年间人类在不断的尝试与研发过程中,将玩具式的木马车转换到今日各式新颖休闲运动自行车,自行车发展的目的也从最早的交通代步的工具转换成休闲娱乐运动的用途。随着居民生活水平的不断提高,自行车不再仅仅是普通的运输、代步的工具,而是成为人们娱乐、休闲、锻炼的首选。因此,人们希望自行车的功用更强大,能给人们带来更多的方便。自行车里程速度表作为自行车的一大辅助工具也正
9、是随着这个要求而迅速发展的,其功能也逐渐从单一的里程显示发展到速度、时间显示,甚至有的还具有测量骑车人的心跳、显示骑车人热量消耗等功能。本设计采用了MCS-51系列单片机设计一种体积小、操作简单的便携式自行车的速度里程表,它能自动地显示当前自行车行走的距离及运行的速度。 1.2 课题的主要任务及内容本课题主要任务是利用霍尔元件、单片机等部件设计一个可用LED数码管实时显示里程和速度的自行车的速度里程表。本文主要介绍了自行车的速度里程表的设计思想、电路原理、方案论证以及元件的选择等内容,整体上分为硬件部分设计和软件部分设计。本文首先扼要对该课题的任务进行方案论证,包括硬件方案和软件方案的设计;继
10、而具体介绍了自行车的速度里程表的硬件设计,包括传感器的选择、单片机的选择、显示电路的设计;然后阐述了该自行车的速度里程表的软件设计,包括数据处理子程序的设计、显示子程序的设计;最后针对仿真过程遇到的问题进行了具体说明与分析,对本次设计进行了系统的总结。 具体的硬件电路包括AT89C52单片机的外围电路以及LED显示电路等。软件设计包括:芯片的初始化程序、定时中断采样子程序、显示子程序等,软件采用汇编语言编写,软件设计的思想主要是自顶向下,模块化设计,各个子模块逐一设计。 102 自行车的速度里程表总体方案设计2 自行车的速度里程表总体方案设计2.1 任务分析与实现本设计的任务是:以通用MCS-
11、51单片机为处理核心,用传感器将车轮的转数转换为电脉冲,进行处理后送入单片机。里程及速度的测量,是经过MCS-51的定时/计数器测出总的脉冲数和每转一圈的时间,再经过单片机的计算得出,其结果通过LED显示器显示出来。本系统总体思路如下:假定轮圈的周长为L,在轮圈上安装m个永久磁铁,则测得的里程值最大误差为L/m。经综合分析,本设计中取m=1。当轮子每转一圈,通过开关型霍尔元件传感器采集到一个脉冲信号,并从引脚P3.2中断0端输入,传感器每获取一个脉冲信号即对系统提供一次计数中断。每次中断代表车轮转动一圈,中断数n轮圈的周长为L的乘积为里程值。计数器T1计算每转一圈所用的时间t,就可以计算出即时
12、速度v。当里程键按下时,里程指示灯亮,LED切换显示当前里程,与当速度键按下时,速度指示灯亮,LED切换显示当前速度,若自行车超速,系统发出报警信号,指示灯闪烁。要求达到的各项指标及实现方法如下:1. 利用霍尔传感器产生里程数的脉冲信号。2. 对脉冲信号进行计数。实现:利用单片机自带的计数器T1对霍尔传感器脉冲信号进行计数。3. 对数据进行处理,要求用LED显示里程总数和即时速度。实现:利用软件编程,对数据进行处理得到需要的数值。最终实现目标:自行车的速度里程表具有里程、速度测试与显示功能,采用单片机作控制,显示电路可显示里程及速度。2.2 自行车的速度里程表硬件方案设计测速,首先要解决是采样
13、的问题。使用单片机进行测速,可以使用简单的脉冲计数法。只要转轴每旋转一周,产生一个或固定的多个脉冲,将脉冲送入单片机中进行计算,即可获得转速的信息。常用的测速元件有霍尔传感器、光电传感器和光电编码器。里程测量传感器的选择也有以下几种方案:使用光敏电阻对里程进行测量、利用编码器对车轮的圈数进行测量、利用霍尔传感器对里程进行测量、利用干簧管型传感器测量里程。光敏电阻对光特别敏感,当白天行驶时,外界光源将导致光敏电阻发出错误信号;光敏电阻对环境的要求相当高,如果光敏或发光二极管被泥沙或灰尘所覆盖,光敏电阻就不能再进行准确测量;而编码器必须安装在车轴上,安装较为复杂;霍尔元件或干簧管不但不受天气的影响
14、,即使被泥沙或灰尘覆盖也不会有影响,而且安装方便。所以本设计采用霍尔元件对里程与速度进行测量,既简单易行,又经济适用。使用霍尔传感器获得脉冲信号,其机械结构也可以做得较为简单,只要在转轴的齿轮盘上粘上一粒磁钢,霍尔元件固定在前叉上,当车子转动时霍尔元件靠近磁钢,就有信号输出,转轴旋转时,就会不断地产生脉冲信号输出。如果在齿轮盘上粘上多粒磁钢,可以实现旋转一周,获得多个脉冲输出。在粘磁钢时要注意,霍尔传感器对磁场方向敏感,粘之前可以先手动接近一下传感器,如果没有信号输出,可以换一个方向再试。这种传感器不怕灰尘、油污,在工业现场应用广泛。霍尔传感器是对磁敏感的传感元件,常用于信号采集的有A44E,
15、该传感器是一个3端器件,外形与三极管相似,只要接上电源、地,即可工作,工作电压范围宽,使用非常方便。A44E的外形如图2.1所示。1-Vcc 2-GND 3-OUT图2.1 A44E外形图单片机由于将CPU、内存和一些必要的接口集成到一个芯片上,并且面向控制功能将结构作了一定的优化,所以它有一般芯片不具有的特点:1. 体积小、重量轻;2. 电源单一、功耗低;3. 功能强、价格低;4. 全部集成在一块芯片上,布线短、合理;5. 数据大部分在单片机内传送,运行速度快、抗干扰能力强、可靠性高。目前,单片机被广泛的应用于测控系统、工业自动化、智能仪表、集成智能传感器、机电一体化产品、家用电器领域、办公
16、自动化领域、汽车电子与航空航天器电子系统以及单片机的多机系统等领域。在设计中选用的是AT89C52单片机。外部信号霍尔传感器外部存储器AT89C52单片机里程显示速度显示报警部分图2.2 系统的原理框图2.3 自行车的速度里程表软件方案设计通过软件控制单片机的功能是单片机的主要特点和优点,程序的设计要考虑合理性和可读性,遵循模块化设计的原则,采用自顶向下的设计方法。模块化设计使程序的可读性好、修改及完善方便。软件设计包括主程序、行车过程中里程和速度计算子程序、延时子程序、中断服务子程序、显示子程序等等。中断子程序是将传感器产生的信号接入外部中断0,将经过74LS74分频后的信号接入外部中断1,
17、利用中断和定时器对分别对里程进行累加、每转一周的时间进行测量。数据处理子程序是将进入单片机的脉冲信号与实际要显示值之间有一定的对应关系,经过软件编程显示所需要的值。显示子程序是将数据处理的结果送显示器显示。系统软件总体流程图如图2.3所示。 初始化P3.0=1?计算里程显示里程计算速度显示速度N开始图 2.3 软件总体流程图3 自行车的速度里程表硬件电路设计3.1 概述自行车的速度里程表的硬件电路设计是基础部分,它包括信号的捕获、放大、整形,单片机的计算处理,数码管的实时显示和单片机外围基本电路的设计,两大主要器件就是传感器和单片机。传感器是获取自然或生产领域中信息的关键器件,是现代信息系统和
18、各种设备不可缺少的信息采集工具。磁传感器是一种将磁学量信号转变为电信号的器件或装置。随着信息产业、工业自动化、医疗仪器等的飞速发展和计算机应用的普及,需要大量的传感器将被测或被控的非电信号转换成可与计算机兼容的电信号。作为输入信号,这就给磁传感器的快速发展提供了机遇,形成了磁传感器的产业。其中最具代表的磁传感器就是霍尔传感器,在自动检测系统中,利用霍尔传感器测转数是一种最基本的测量工作。单片机是本次设计的核心部件,它是信号从采集到输出的桥梁,而且包括计算、定时、信息处理等功能。3.2 传感器及其测量系统本次设计信号的捕获采用的是霍尔传感器。霍尔器件具有许多优点,它们的结构牢固、体积小、重量轻、
19、寿命长、安装方便、功耗小、频率高(可达1MHz)、耐震动、不怕灰尘、油污、水汽及烟雾等的污染或腐蚀。霍尔线性器件的精度高、线性度好;霍尔开关器件无触点、无磨损、输出波形清晰、无抖动、无回跳、位置重复精度高。取用各种补偿和保护措施的霍尔器件工作温度范围宽,可达55150。按照霍尔器件的功能可将它们分为:霍尔线性器件和霍尔开关器件,前者输出模拟量,后者输出数字量。 按被检测对象的性质可将它们的应用分为:直接应用和间接应用。前者是直接检测出受检测对象本身的磁场或磁特性,后者是检测受检对象上人为设置的磁场,用这个磁场来作被检测的信息的载体。通过它,将许多非电、非磁的物理量例如力、力矩、位置、位移、速度
20、、加速度、角度、角速度、转数、转速以及工作状态发生变化的时间等,转变成电量来进行检测和控制。 3.2.1 霍尔传感器的测量原理霍尔传感器是利用霍尔效应制成的一种磁敏传感器。在置于磁场中的导体或半导体通入电流I,若电流垂直磁场B,则在与磁场和电流都垂直的方向上会出现一个电势差Uh,这种现象称为霍尔效应。利用霍尔效应制成的元件称为霍尔元件。因为它具有结构简单、频率响应宽、灵敏度高、测量线性范围大、抗干扰能力强以及体积小、使用寿命长等一系列特点,因此被广泛应用于测量、自动控制及信息处理等领域。霍尔效应原理图如图3.1所示。图3.1 霍尔效应原理图3.2.2 集成开关型霍尔传感器A44E集成霍尔开关由
21、稳压器A、霍尔电势发生器(即硅霍尔片)B、差分放大器 C、施密特触发器D和OC门输出E五个基本部分组成,如图3.2(a)所示。(1)、(2)、(3)代表集成霍尔开关的三个引出端点。在电源端加电压Vcc,经稳压器稳压后加在霍尔电势发生器的两端,根据霍尔效应原理,当霍尔片处在磁场中时,在垂直于磁场的方向通以电流,则与这二者相垂直的方向上将会产生霍尔电势差VH输出,该VH信号经放大器放大后送至施密特触发器整形,使其成为方波输送到OC门输出。当施加的磁场达到工作点时,触发器输出高电压(相对于地电位),使三极管导通,此时OC门输出端输出低电压,通常称这种状态为开 。当施加的磁场达到释放点时,触发器输出低
22、电压,三极管截止,使OC门输出高电压,这种状态为关 。这样两次电压变换,使霍尔开关完成了一次开关动作。工作点与释放点的差值一定,此差值称为磁滞,在此差值内,V0保持不变,因而使开关输出稳定可靠,这也就是集电成霍尔开关传感器优良特性之一。传感器主要特性是它的输出特性,即输入磁感应强度B与输出电压V0之间的关系。A44E集成霍尔开关是单稳态型,由测量数据作出的输出特性曲线如图 3.2(b)所示。测量时,在1、2两端加5V直流电压,在输出端3与1之间接一个2kW的负载电阻,如图3.3所示。图3.2 集成开关型霍尔传感器图3.3 集成霍尔开关接线图3.3 单片机的原理及应用3.3.1 单片机原理简介单
23、片机是指集成在一个芯片上的微型计算机,也就是把组成微型计算机的各种功能部件,包括CPU(Central Processing Unit)、随机存储器RAM(Random Access Memory)、只读存储器ROM(Read-only Memory)、基本输入/输出(Input/Output)接口电路。定时器/计数器等部件都制作在一块集成芯片上,构成一个完整的微型计算机从而实现微型计算机的基本功能。单片机内部结构示意图如图3.4所示。 定时/计数器中断系统CPU存储器并行I/O口串口I/O口TXDTXDRXDTINTP0-P3图3.4 单片机内部结构示意图1.中央处理器(CPU)中央处理器是
24、单片机最核心的部分,主要完成运算和控制功能。2.内部存储器内部存储器包括内部数据存储器(内部RAM)和内部程序存储器。存储器是由大量的寄存器所组成,其中每一个寄存器就称为一个存储单元。3.定时/计数器单片机的定时器和计数器是同一结构,只是计数器记录的是单片机外部发生的事件,由单片机的外部电路提供计数信号;而定时器是由单片机内部提供一个非常稳定的计数信号。4.中断系统请删除以下内容,O(_)O谢谢!conduction, transfer of heat or electricity through a substance, resulting from a difference in temp
25、erature between different parts of the substance, in the case of heat, or from a difference in electric potential, in the case of electricity. Since heat is energy associated with the motions of the particles making up the substance, it is transferred by such motions, shifting from regions of higher
26、 temperature, where the particles are more energetic, to regions of lower temperature. The rate of heat flow between two regions is proportional to the temperature difference between them and the heat conductivity of the substance. In solids, the molecules themselves are bound and contribute to cond
27、uction of heat mainly by vibrating against neighboring molecules; a more important mechanism, however, is the migration of energetic free electrons through the solid. Metals, which have a high free-electron density, are good conductors of heat, while nonmetals, such as wood or glass, have few free e
28、lectrons and do not conduct as well. Especially poor conductors, such as asbestos, have been used as insulators to impede heat flow (see insulation). Liquids and gases have their molecules farther apart and are generally poor conductors of heat. Conduction of electricity consists of the flow of char
29、ges as a result of an electromotive force, or potential difference. The rate of flow, i.e., the electric current, is proportional to the potential difference and to the electrical conductivity of the substance, which in turn depends on the nature of the substance, its cross-sectional area, and its t
30、emperature. In solids, electric current consists of a flow of electrons; as in the case of heat conduction, metals are better conductors of electricity because of their greater free-electron density, while nonmetals, such as rubber, are poor conductors and may be used as electrical insulators, or di
31、electrics. Increasing the cross-sectional area of a given conductor will increase the current because more electrons will be available for conduction. Increasing the temperature will inhibit conduction in a metal because the increased thermal motions of the electrons will tend to interfere with thei
32、r regular flow in an electric current; in a nonmetal, however, an increase in temperature improves conduction because it frees more electrons. In liquids and gases, current consists not only in the flow of electrons but also in that of ions. A highly ionized liquid solution, e.g., saltwater, is a go
33、od conductor. Gases at high temperatures tend to become ionized and thus become good conductors (see plasma), although at ordinary temperatures they tend to be poor conductors. See electrochemistry; electrolysis; superconductivity. Almost everyone has experienced the Doppler effect, though perhaps w
34、ithout knowing what causes it. For example, if one is standing on a street corner and an ambulance approaches with its siren blaring, the sound of the siren steadily gains in pitch as it comes closer. Then, as it passes, the pitch suddenly lowers perceptibly. This is an example of the Doppler effect
35、: the change in the observed frequency of a wave when the source of the wave is moving with respect to the observer. The Doppler effect, which occurs both in sound and electromagnetic wavesincluding light waveshas a number of applications. Astronomers use it, for instance, to gauge the movement of s
36、tars relative to Earth. Closer to home, principles relating to the Doppler effect find application in radar technology. Doppler radar provides information concerning weather patterns, but some people experience it in a less pleasant way: when a police officer uses it to measure their driving speed b
37、efore writing a ticket. Sound and light are both examples of energy, and both are carried on waves. Wave motion is a type of harmonic motion that carries energy from one place to another without actually moving any matter. It is related to oscillation, a type of harmonic motion in one or more dimens
38、ions. Oscillation involves no net movement, only movement in place; yet individual points in the wave medium are oscillating even as the overall wave pattern moves. The term periodic motion, or movement repeated at regular intervals called periods, describes the behavior of periodic waveswaves in wh
39、ich a uniform series of crests and troughs follow each other in regular succession. A period (represented by the symbol T ) is the amount of time required to complete one full cycle of the wave, from trough to crest and back to trough. Period is mathematically related to several other aspects of wav
40、e motion, including wave speed, frequency, and wavelength. Frequency (abbreviated f ) is the number of waves passing through a given point during the interval of one second. It is measured in Hertz (Hz), named after nineteenth-century German physicist Heinrich Rudolf Hertz (1857-1894), and a Hertz i
41、s equal to one cycle of oscillation per second. Higher frequencies are expressed in terms of kilohertz (kHz; 103 or 1,000 cycles per second); megahertz (MHz; 106 or 1 million cycles per second); and gigahertz (GHz; 109 or 1 billion cycles per second.) Wavelength (represented by the symbol , the Gree
42、k letter lambda) is the distance between a crest and the adjacent crest, or a trough and an adjacent trough, of a wave. The higher the frequency, the shorter the wavelength. Amplitude, though mathematically independent from the parameters discussed, is critical to the understanding of sound. Defined
43、 as the maximum displacement of a vibrating material, amplitude is the size of a wave. The greater the amplitude, the greater the energy the wave contains: amplitude indicates intensity, which, in the case of sound waves, is manifested as what people commonly call volume. Similarly, the amplitude of
44、 a light wave determines the intensity of the light. electromagnetic radiation,energy radiated in the form of a wave as a result of the motion of electric charges. A moving charge gives rise to a magnetic field, and if the motion is changing (accelerated), then the magnetic field varies and in turn
45、produces an electric field. These interacting electric and magnetic fields are at right angles to one another and also to the direction of propagation of the energy. Thus, an electromagnetic wave is a transverse wave. If the direction of the electric field is constant, the wave is said to be polariz
46、ed (see polarization of light). Electromagnetic radiation does not require a material medium and can travel through a vacuum. The theory of electromagnetic radiation was developed by James Clerk Maxwell and published in 1865. He showed that the speed of propagation of electromagnetic radiation shoul
47、d be identical with that of light, about 186,000 mi (300,000 km) per sec. Subsequent experiments by Heinrich Hertz verified Maxwells prediction through the discovery of radio waves, also known as hertzian waves. Light is a type of electromagnetic radiation, occupying only a small portion of the poss
48、ible spectrum of this energy. The various types of electromagnetic radiation differ only in wavelength and frequency; they are alike in all other respects. The possible sources of electromagnetic radiation are directly related to wavelength: long radio waves are produced by large antennas such as those used by broadcasting stations; much shorter visible light waves are produced by the motio