
上QQ阅读APP看本书,新人免费读10天
设备和账号都新为新人
软件设计
本电路的软件设计主要由主程序、液晶显示程序组成。主程序对系统环境进行初始化,设置T0、T1的工作方式,采用软件启动方式,当TR0、TR1同时为1时启动计时、计数方式为方式1(16位),TH0=(65536-50000)/256,TL0=(65536-50000)%256。T0每次溢出中断1次,计时50ms,所以总共溢出中断20次,定时1s,T1此时计算所有脉冲的个数,这样就可以准确找出1s内所计数脉冲的总数n。由于经过两个脉冲后是一个工作循环,所以n/2即为转速值。其计数工作示意图如图7-12所示。主程序流程图如图7-13所示。

图7-11 霍尔转速计电路原理图

图7-12 计数工作示意图

图7-13 主程序流程图
按照程序流程图,编写程序如下:



将程序下载到单片机中进行仿真,由霍尔传感器原理可知,用脉冲信号代替即可,脉冲信号参数如图7-14所示。为了使软件仿真更加方便,用如图7-15所示的电路进行仿真。图7-16所示为仿真结果。

图7-14 脉冲信号参数

图7-15 仿真原理图

图7-16 仿真结果
改变脉冲参数,其输出的转速值也会不同,当脉冲频率改变后,其输出的转速也发生了改变,如图7-17和图7-18所示。
通过对实物的测试,可以看出此电路能够实现霍尔转速计的功能,并且能够显示当前测量的值,符合设计要求。

图7-17 脉冲参数