3 基于CPLD的程序设计设计系统软件时运用VHDL语言,可将系统分为频率计、分频器、相位计数器3个子模块,现对其分别进行描述:(1)频率计library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity fcounter isport(sig:in std_logic; --输入信号clk:in std_logic; --0.5Hz的闸门信号,可由晶振分频得到counter:out std_logic_vector(19 downto 0));--计数输出end;architecture data of fcounter issignal temp:std_logic_vector(19 downto 0);beginP1:process(sig)beginif sig'event and sig=‘1’thenif clk=‘1’ thentemp<=temp+1; --在闸门的高电平时段计数elsetemp<=“00000000000000000000” --在闸门的低电平时段清零end if;end if;end process P1;P2process(clk)beginif clk′event and clk=′0′ thencounter<=temp;在闸门的下降沿将数据读出end if;
end process P2;end;由于闸门采用的是0.5Hz的方波,因此输出数值即为频率值。(2) 分频模块通过此模块可对频率计得到的频率进行分频,也可在异或后再分频得到频率为0.5Hz的矩形波。library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity fen isport(qin:in std_logic vector(19 downto 0);--连接频率计输出的频率值qout:out std_logic);end;architecture data of fen issignal temp:std_logic_vector(19 downto 0);signal a:std_logic;beginprocess(temp)beginif temp<qin thentemp<=temp+1;elsetemp<=“00000000000000000000”;a<=not a;end if;qout<=a; --进行2f倍分频end process;end;3相位测量该模块将分频模块得到的信号作为闸门,然后利用外部晶振进行计数,其设计原理与频率计相同。由于相异或的一个周期对应输入的两路方波信号的半个周期(180°),而且只能测量到最大180°的相位差,因此还须判断超前或滞后,才能测量出大于180°的相位差,具体程序如下:library ieee;use ieee.std_logic_1164.all;entity pre_lag isport(s1,s2:in std_ ogic; --两输入信号pre:out std_logic); --判断结果输出end;architecture data of pre_lag isbeginlag:process(s1)beginif s1′event and s1=′1′ thenif s2=′0′thenpre<=′1′; --若s1超前s2,输出为′1′,否则输出′0′;elsepre<=′0′;end if;end if;end process lag;end;(4) 模块的组合图3 在Max+PlusII中,采用原理图输入方式可将上述各模块组合成一个软件系统,然后将其综合下载到CPLD即可完成相位测量仪的设计,其具体设计图见图3所示。图3中, A、B为输入信号a、b经过整形得到的方波信号。Fcounter为频率计模块,Fen为分频器,Phasecounter为相位测量计数器,Pre-lag为超前滞后判断模块。4 结束语基于CPLD逻辑器件 EMP7128SLC84-15构成的相位测量系统具有测量频带宽、分辨率高、误差小、成本低、简单易行等优点,完全能够满足实际测量的要求。而且,由于完全采用的是CPLD设计,因此,该系统十分易于升级。
| 欢迎光临 美丽的网站-英华家电维修论坛 (http://www.bsss.info/) | Powered by Discuz! X3.2 |