学士学位论文基于单片机的超声波测距电路的研究.docx
《学士学位论文基于单片机的超声波测距电路的研究.docx》由会员分享,可在线阅读,更多相关《学士学位论文基于单片机的超声波测距电路的研究.docx(70页珍藏版)》请在冰豆网上搜索。
学士学位论文基于单片机的超声波测距电路的研究
目录
设计总说明:
.3
ABSTRACT:
.5
第一章:
超声波测距原理论述7
1.1超声波介绍7
1.2超声波测距系统概述9
1.3超声波测距的基本原理11
1.4本课题的内容和任务12
第二章AVR单片机介绍13
2.1ATmega16结构框图16
2.2AVRCPU内核19
2.3AVRATmega16存储器。
19
2.4AVRATmega16系统时钟19
2.5系统控制和复位20
2.6看门狗定时器20
2.7ATmega16的中断向量(外部中断)20
2.8具有PWM功能的8位定时器/计时器21
2.9比较输出模式和波形产生22
2.10T/C0与T/C1的预分频器24
2.11串行外设接口-SPI24
2.12串行外设接口-USART25
2.13模数转换器25
2.14JTAG接口和片上调试系统26
第三章硬件电路的设计26
3.1电源电路设计26
3.2复位电路设计27
3.3时钟电路设计
27
3.4数码管显示电路28
3.5报警电路设计30
3.6温度补偿电路31
3.6.1温度计算33
3.6.2DSl820工作过程命令33
3.6.3时序33
3.6.4写时间隙34
3.6.5读时间隙34
3.6.6多路测量34
3.7在线通信电路设计35
第四章,超声波发射电路及接收电路的设计36
4.1超声波发射电路36
4.1.1压电陶瓷超声波传感器介绍36
4.1.2发射电路原理图分析38
4.2超声波接收电路39
4.2.1LC震荡选频电路设计:
39
4.2.2比较电路的设计40
4.2.3接收电路原理图分析40
第五章软件设计43
5.1主程序流程图43
5.2发射子程序设计44
5.3温度测量子程序44
5.4测量子程序46
5.5计算子程序46
5.6显示驱动子程序47
5.7报警子程序47
第六章设计心得49
致谢50
参考文献51
附录52
基于单片机的超声波测距电路的研究
设计总说明:
超声波因其指向性强,能量消耗缓慢,在介质中传播距离远等特点,而经常用于进行各种测量.如利用超声波在水中的发射,利用超声波在固体中的传播,可以用作金属探伤、医用A超、B超等.利用超声波测距,使用单片机系统,设计合理,计算处理也较方便,测量精度能达到各种场合使用的要求.
这篇应用性设计报告描述了一种基于AVRATMEGA16低功耗单片机的超声波测距系统,本系统发射器对着一个物体发射一定频率的超声波同时接收同频率的超声波,单片机通过计算从超声波发射时刻到接收返回的超声波时刻从而确定超声波通过的时间,根据房间的温度来确定超声波在空气中的速度大概是340m/s,AVR单片机计算二者的距离同时用3个LED驱动电路驱动的LED来显示,显示距离误差大概是±1cm,最小能测量时1cm同时局限于发射器的传感器的设定时间,最大能测量4m,超声波测距发射距离决定与发射物的材质和形状,例如超声波可能被地毯吸收,这样测量的距离就大大的降低,假如反射波接收的频率太低就可能不被系统处理,这样显示就会出现错误。
1设计理论:
本设计应用基于声波的反射。
声波在其传播的介质中被定义为纵波。
当声波受到尺寸大于其波长的目标物阻挡时就会发生反射;反射波称为回声。
如果声波在介质中传播的速度是已知的,而且测量到声波从声源到达目标然后返回声源的时间,从声源到目标的距离就可以精确地计算出来。
这就是本应用的测量原理。
这里声波传播的介质就是空气,采用不可见的超声波。
假设室内超声波的速度是340m/s则可以通过计算超声波通过时间来计算距离,但是实际温度对超声波影响很大,通过可以研究,速度和温度(T为绝对温度)存在一下关系:
由于超声波通过的距离是2倍的实际距离,则实际距离是d/2,所以
2电路描述:
本设计用来发射和接收超声波的设备是40hz压电陶瓷超声波传感器,AVRATMEGA16单片机驱动超声波发射器40hz的方波来源于晶振,波接收器接收回波由于AVRATMEGA16单片机的计时器计算40khz的分辨率是25us是完全胜任我们的设计,我们系统的稳定性来源于晶振的工作。
被超声波接收器超声波通过一个运算放大器放大对输入a放大,相对输入a输出超声波的同时触发单片机计时器timer1,捕获的回波被精确计算时间来计算距离。
计数器从超声波发射开始计时到收到回波停止,时间被精确记录,我们可以通过DS18B20芯片来确定室温,精确的确定超声波的速度,二者的距离通过AVRATMEGA16精确的计算同时在3个数码管上显示出来,一旦显示出来,单片机就进入休眠状态来节省电力能源。
这篇设计的主要电路分析。
传感器的输出驱动电路直接由9V电池供电并提供驱动超声波发射器由一个二进制非门CD4049电路实现的。
其中一个非门用来为驱动器的一侧提供180度的相移信号。
另一侧由相内信号驱动。
这种结构使输出端的电压提高了一倍,为发射传感器提供了足够的电压。
两个门并联连接以便每一侧能够为传感器提供足够的驱动电流。
电容耦合阻断了到传感器的直流通路。
因为CD4049工作于9V而AVRATMEGA16工作于Vcc=5V。
AVRATMEGA16和输出驱动器之间的逻辑电平是不匹配的,可以双极性晶体管就作为这两种逻辑电平之间的转换器。
由LC选频放大器对超声波接收器接收的回波在40KHz时提供充分的高增益。
选择并丢弃除了40KHz之外的频率。
运算放大器的输出端连接到比较器LM393的输入端。
比较器LM393的参考电平内部选择为0V。
当接收到回声时电压高于参考电平从而触发比较器的输出。
然后触发单片机的INT0.
本文在了解超声波测距原理的基础上,完成了基于时差测距原理的一种超声波测距系统的硬件设计,其中为了进一步提高系统测量精度和系统稳定性,在硬件上增加了温度传感器测温电路,采取声速预置和媒质温度测量相结合的办法对声速进行修正,降低了温度变化对测距精度的影响。
针对噪声环境中超声波测距的情况,本文讨论了一种基于时延的估计方法,可有效地降低噪声对测距的干扰,有利于提高超声波测距系统的测量精度。
关键词:
超声波测距AVRatmega16DS18B20
ABSTRACT:
Indifferentoccasions,thedemandsoftheprecisiononultrasonicdistancemeasuringsystemaredifferent.Usually,theerroroftheultrasonicdistancemeasuringsystemislarge,sotheycannotbesatisfiedwiththedemandsinsomeoccasions.ThisarticletakestemperATureaccountintotheultrasonicdistancemeasuringsystemandmakesithavehigherprecisionhanbeforeandincreasesthefunctionofbroadcastingtheresult.Itcanapplyinmoreoccasionsandbefeltmoreconvenient.
Thisdesignapplicationreportdescribesadistance-measuringsystembasedonultrasonicsoundutilizingtheAVRatmega16ultralow-powermicrocontroller.Thesystemtransmitsaburstofultrasonicsoundwavestowardsthesubjectandthenreceivesthecorrespondingecho.ThetimetakenfortheultrasonicbursttotravelthedistancefromthesystemtothesubjectandbacktothesystemisaccuratelymeasuredbytheAVRatmega16.Assumingthespeedofsoundinairatroomtemperaturetobe340m/s,theAVRatmega16computesthedistancebetweenthesystemandthesubjectanddisplaysitusingathree-digitstaticLEDdrivenbyitsintegratedLEDdriver.Thedistanceisdisplayedinincheswithanaccuracyof±1cm.Theminimumdistancethatthissystemcanmeasureis1cmandislimitedbythetransmitter’stransducersettling-time.Themaximumdistancethatcanbemeasuredis4m.Theamplitudeoftheechodependsonthereflectingmaterial,shape,andsize.Sound-absorbingtargetssuchascarpetsthemaximummeasurablerangeislowerforsuchsubjects.IftheamplitudeoftheechoreceivedbythesystemissolowthatitisnotdetectablebytheComparatorthesystemgoesoutofrange.Thisisindicatedbydisplayingtheerrormessage
1TheoryofOperation
Thisapplicationisbasedonthereflectionofsoundwaves.SubjectswhoseDimensionsarelargerthanthewavelengthoftheimpingingsoundwavesreflectthem;thereflectedwavesarecalledtheecho.Ifthespeedofsoundinthemediumisknownandthetimetakenforthesoundwavestotravelthedistancefromthesourcetothesubjectandbacktothesourceismeasured,thedistancefromthesourcetothesubjectcanbecomputedaccurately.Thisisthemeasurementprincipleofthisapplication.Sinceitisinaudibletohumans.Assumingthatthespeedofsoundinairisv=340m/satroomtemperatureandthatthemeasuredtimetakenforthesoundwavestotravelthedistancefromthesourcetothesubjectandbacktothesourceisseconds,asweknow:
Thedistancediscomputedbytheformula
Sincethesoundwavestraveltwicethedistancebetweenthesourceandthesubject,theactualdistancebetweenthesourceandthesubjectwillbed/2.
2CircuitDescription
Thedevicesusedtotransmitandreceivetheultrasonicsoundwavesinthisapplicationare40-kHzceramicultrasonictransducers.AVRATMEGA16drivesthetransmittertransducerwith40-kHzsquare-wavesignalderivedfromthecrystaloscillator,andthereceivertransducerreceivestheecho.TheTimer1intheAVRisconfiguredtocountthe40-kHzcrystalfrequencysuchthatthetimemeasurementresolutionis25μs,whichismorethanadequateforthisapplication.Themeasurementtimebaseisverystableasitisderivedfromaquartz-crystaloscillator.TheechoreceivedbythereceivertransducerisamplifiedbyanoperationalamplifierandtheamplifiedoutputisfedtotheComparator_Ainput.TheComparator_AsensesthepresenceoftheechosignalatitsinputandtriggersacaptureofTimer_Acountvaluetocapturecompareregistertimer1.Thecaptureisdoneexactlyattheinstanttheechoarrivesatthesystem.Thecapturedcountisthemeasureofthetimetakenfortheultrasonicbursttotravelthedistancefromthesystemtothesubjectandbacktothesystem.ThedistanceininchesfromthesystemtothesubjectiscomputedbytheAVRATMEGA16usingthismeasuredtimeanddisplayedonatwo-digitstaticLED.Immediatelyafterupdatingthedisplay,theAVRgoestosleepmodetosavepower.Thecircuitschematicdiagramofthisapplication.
Theoutputdrivecircuitforthetransducerispowereddirectlyfromthe9-Vbatteryandprovidesdrivetotheultrasonictransmitter.TheisachievedbyabridgeconfigurationwithhexinvertergatesCD4049.Oneinvertergateisusedtoprovidea180-degreesphase-shiftedsignaltoonearmofthedriver.Theotherarmisdrivenbythein-phasesignal.Thisconfigurationdoublesthevoltageswingattheoutputandprovidestherequiredtothetransmittertransducer.Twogatesareconnectedinparallelsothateacharmcanprovideadequatecurrentdrivetothetransducer.Capacitorsblockthedctothetransducer.SincetheCD4049operateson9-VandtheAVRATMEGA16operatesonaVCCof5V,thereisalogiclevelmismatchbetweentheAVRATMEGA16andtheoutputdrivercircuit.Bipolartransistoractsasalogic-levelshifterbetweenthesetwologiclevels.
OperationalamplifierNPNismadeofbyCircuit,Thisamplifierhasahigh-gainbandwidthandprovidessufficientlyhighgainat40kHz.Theamplifiedultrasonicsignalswingsaboveandbelowthisvirtualmidrail.providesselectivityandrejectionofunwantedfrequenciesotherthan40kHz.TheoutputoftheoperationalamplifierisconnectedtotheComparatorLM393inputoftheATMEGA16viaportpinINT0.TheComparatorLM393referenceisinternallyselectedtobe0.5VCC.Whennoultrasonicechoisreceived,thevoltagelevelatCA0isslightlylowerthanthereferenceatLM393.Whenanechoisreceived,thevoltagelevelincreasesabovethereferenceandtogglestheComparatorLM393canbefine-tunedfortherequiredsensitivityandthemeasurablerangecanbeoptimizedandgivethesingletotheATMEGA16.
Basedonthecomprehensionofmeasuringdistanceprinciplebyultrasonic,thepapercompletesanhardwaredesignwhichbasedontimedifferencemeasuringdistancetheory,Inordertoimprovethemeasurementaccuracyandsystemstabilityfurther,weaddatemperaturesensorinthehardwaredesignandadopttheimprovedmethodwhichcombinessoundvelocitypresettingwithmediumtemperaturemeasurementtomendthesoundvelocity.Bythismeans,theinfluenceoftemperaturevariationondistancemeasurementisdecreased.
Keywords:
distance-measuringsystembasedonultrasonicAVRatmega16DS18B20
第一章:
超声波测距原理论述
1.1超声波介绍
超声波是指振动频率大于20KHz以上的,人在自然环境下无法听到和感受到的声波。
超声波因其可在气体、液体、固体、固熔体等介质中有效传播,可传递很强的能量,产生反射、干涉、叠加和共振现象。
在液体介质中传播时,可在界面上产生强烈的冲击和空化现象。
由于超声波与介质的相互作用,使介质发生物理的和化学的变化,从而产生一系列力学的、热学的、电磁学的和化学的超声效应,包括以下4种效应:
①机械效应。
超声波的机械作用可促成液体的乳化、凝胶的液化和固体的分散。
当超声波流体介质中形成驻波时,悬浮在流体中的微小颗粒因受机械力的作用而凝聚在波节处,在空间形成周期性的堆积。
超声波在压电材料和磁致伸缩材料中传播时,由于超声波的机械作用而引起的感生电极化和感生磁化(见电介质物理学和磁致伸缩)。
②空化作用。
超声波作用于液体时可产生大量小气泡。
一个原因是液体内局部出现拉应力而形成负压,压强的降低使原来溶于液体的气体过饱和,而从液体逸出,成为小气泡。
另一原因是强大的拉应力把液体“撕开”成一空洞,称为空化。
空洞内为液体蒸气或溶于液体的另一种气体,甚至可能是真空。
因空化作用形成的小气泡会随周围介质的振动而不断运动、长大或突然破灭。
破灭时周围液体突然冲入气泡而产生高温、高压,同时产生激波。
与空化作用相伴随的内摩擦可形成电荷,并在气泡内因放电而产生发光现象。
在液体中进行超声处理的技术大多与空化作用有关。
③热效应。
由于超声波频率高,能量大,被介质吸收时能产生显著的热效应。
④化学效应。
超声波的作用可促使发生或加速某些化学反应。
例如纯的蒸馏水经超声处理后产生过氧化氢;溶有氮气的水经超声处理后产生亚硝酸;染料的水溶液经超声处理后会变色或退色。
这些现象的发生总与空化作用相伴随。
超声波还可加速许多化学物质的水解、分解和聚合过程。
超声波对光化学和电化学过程也