基于单片机的步进电机小车驱动系统设计摘要本设计以STC89C52单片机最小系统为核心,设计了一种两相四线步进电机的驱动器电路。整个系统通过单片机控制步进电机驱动器的输出信号,对步进电机的动作进行控制,进而实现小车的行走动作。文章包括了步进电机正转、反转、加速、减速这些基本旋转,以及在此基础之上同时控制两个步进电机,实现小车的前进、后退、左转与右转。并在小车上增加一些传感器模块,使单片机正常驱动步进电机,带动小车执行相应任务的同时,根据传感器模块的反馈,不断修正,直到任务实现小车循迹与避障功能。至此来证明所设计的驱动电路的可行性。文章中不仅包括了在步进电机驱动电路基础上的单片机扩展电路,也包括了专门为单片机供电的5V稳压电路的分析与设计,以及使单片机串口与计算机USB接口直接进行通信的上位机电路的设计。关键词:STC89C52;步进电机;步进电机驱动电路;循迹;避障SteppingmotorvehiclesdrivesystemdesignbasedonSingle-ChipMicrocomputerAbstractThisdesignwithSTC89C52SCMsmallestsystemasthecore,designedatwophasefour-wiresteppingmotordrivecircuit.Thewholesystembysinglechipmicrocomputercontrolsteppingmotordrivestheoutputsignal,tocontrolthemotionofthesteppermotor,andrealizesthecartowalk.Articlesincludingthesteppermotorareturning,inversion,acceleration,deceleration,thesebasicrotation,andonthisbasisatthesametimecontroltwosteppermotors,implementthecarmoveforward,backward,turnleftandturnright.Andaddsomeonthecarsensormodule,MCUtonormaldrivingsteppingmotor,drivecarcorrespondingtasksatthesametime,accordingtothefeedbackofsensormodule,thecorrectionunceasingly,untilthetasktorealizethecartrackingandobstacleavoidancefunction.Atthispointtoprovethefeasibilityofthedesigneddrivercircuit.Notonlyincludedinthearticlebasedonstepmotordrivecircuitofsinglechipmicrocomputerextendedcircuit,alsoincludedforMCUpowersupply5vvoltageregulatorcircuitanalysisanddesign,andmakethemicrocontrollerserialportandthecomputerUSBinterfacedirectlycommunicatesuperiormechanicalandelectricaldesignoftheroad.Keywords:STC89C52;steppermotor;steppermotordrivecircuit;tracking;obstacleavoidanceI目录第1章绪论.........................................................................11.1课题背景.....................................................................11.2课题研究的内容..............................................................1第2章系统总体设计...............................................................22.1系统设计要求................................................................22.2系统框图.....................................................................22.3设计规划.....................................................................2第3章系统硬件设计................................................................43.1单片机介绍...................................................................43.1.1单片机概述.............................................................43.1.2单片机的特点...........................................................43.1.3单片机的应用领域.......................................................43.1.4单片机选用............................................................53.1.5控制电路设计...........................................................63.1.6单片机供电模块设计.....................................................93.2步进电机介绍................................................................103.2.1步进电机的概述........................................................103.2.2步进电机的特点........................................................103.2.3步进电机的工作原理....................................................113.2.4步进电机选用..........................................................113.3步进电机驱动器的设计........................................................113.4系统功能设计................................................................133.4.1循迹功能..............................................................133.4.2避障功能..............................................................153.5上位机电路设计..............................................................15第4章系统软件设计...............................................................194.1电机控制流程图..............................................................194.2电机方向控制...............................................................194.3速度控制....................................................................204.4循迹........................................................................214.5避障流程图..................................................................21第5章总结与展望.................................................................235.1总结........................................................................235.2展望........................................................................23II参考文献..........................................................................24附录Ⅰ程序清单..................................................................251.电机旋转程序.................................................................252.循迹程序.....................................................................273.避障程序.....................................................................31附录Ⅱ单片机驱动电机电路.......................................................35附录Ⅲ外文文献翻译..............................................................36第1章绪论-1-第1章绪论1.1课题背景步进电机是自动控制系统中常用的执行部件。步进电机的输入信号为脉冲电流,它能将输入的脉冲信号转换为阶跃型的角位移或直线位移,因而步进电机可看作是一个串行的数/模转换器。由于步进电机能够直接接受数字信号,而不需数/模转换,所以使用微机控制步进电机显得非常方便[1]。步进电机有以下优点:(1)通常不需要反馈就能对位置和速度进行控制;(2)位置误差不会积累;(3)与数组设备兼容,能够直接接收数字信号;(4)可以快速启停。步进电机的品种规格很多,按照它们的结构和工作原理可以划分为磁阻式(也称反应式或变磁阻式)电机、混合式电机、永磁式电机和特种电机等四种主要型式。步进电机不需位移传感器就可精确定位,所以在精确定位系统中应用广泛。目前打字机、计算机外部设备、数控机床、传真机等设备都使用了步进电机。随着电子计算机技术的发展,步进电机