我用VHDL写了一个等精度测频的程序,其中标准频率用的是100M ,待测频率为32768左右,对两路待测频率同时测量.用的是7160SCL84-6的片子,可在实际使用时发现隔几秒就会跳出一个错值出来,而且也没有精度也没有想像中的高.要当测量时间到200毫秒时,测得结果才会比较稳定(比理论上的差大多了).怀疑是对100M频率计数的程序有点问题.第一次接触VHDL语言,有点搞不清楚,希望高手指教.<br />程序如下:<br />library ieee;<br />use ieee.std_logic_1164.all;<br />use ieee.std_logic_unsigned.all;<br /><br />entity four0ut is<br /> port(<br /> f0,fx,fy,rs,en : in std_logic; -- f0:标准频率 fx:待测频率1 fy待测频率2 rs:清零程序 en:允许信号<br /> choose: in std_logic_vector (4 downto 0); --输出选择信号<br /> output: out std_logic_vector (7 downto 0)); --输出信号<br /> end four0ut;<br />architecture behave of four0ut is<br /><br />signal out_fx0,out_fx1,out_fx2,out_fx3 :std_logic_vector (3 downto 0); --待测频率1计数存放<br />signal out_fy0,out_fy1,out_fy2,out_fy3 :std_logic_vector (3 downto 0); --待测频率2计数存放<br /> signal out_f00,out_f01,out_f02,out_f03,out_f04,out_f05,out_f06 :std_logic_vector (3 downto 0); --待测频率1对应的标准频率计数存放<br /> signal out_f10,out_f11,out_f12,out_f13,out_f14,out_f15,out_f16 :std_logic_vector (3 downto 0); --待测频率2对应的标准频率计数存放<br /><br /> signal star1,star2: std_logic; --两路信号开始计数的标志位(类似用来实现D触发器的功能) <br /> begin<br />--*********以下是第一路频率的测量部分************************<br /><br /> process(fx,rs,en)<br /> begin <br /> if(rs='0') then <br /> star1 <= '0';<br /> out_fx0 <="0000"; out_fx1 <="0000"; out_fx2 <="0000"; out_fx3 <="0000"; <br /> elsif(fx' event and fx = '1') then <br /> if(en='1') then<br /> if (out_fx0 = 15) then out_fx0 <="0000";<br /> if (out_fx1 = 15) then out_fx1 <="0000";<br /> if (out_fx2 = 15) then out_fx2 <="0000";<br /> if (out_fx3 = 15) then out_fx3 <="0000";<br /> else out_fx3 <= out_fx3 + 1 ;<br /> end if;<br /> else out_fx2 <= out_fx2 + 1 ;<br /> end if;<br /> else out_fx1 <= out_fx1 + 1 ;<br /> end if;<br /> else out_fx0 <= out_fx0 + 1 ;<br /> end if; <br /> star1 <= '1';<br /> elsif(star1 ='1') then<br /> star1 <= '0';<br /> end if; <br /> end if;<br /> end process;<br /><br /> <br />--**************以下是第二路频率的测量部分*************************<br /><br /> process(fy,rs,en)<br /> begin <br /> if(rs='0') then <br /> star2 <= '0';<br /> out_fy0 <="0000"; out_fy1 <="0000"; out_fy2 <="0000"; out_fy3 <="0000"; <br /> elsif(fy' event and fy = '1') then <br /> if(en='1') then<br /> if (out_fy0 = 15) then out_fy0 <="0000";<br /> if (out_fy1 = 15) then out_fy1 <="0000";<br /> if (out_fy2 = 15) then out_fy2 <="0000";<br /> if (out_fy3 = 15) then out_fy3 <="0000";<br /> else out_fy3 <= out_fy3 + 1 ;<br /> end if;<br /> else out_fy2 <= out_fy2 + 1 ;<br /> end if;<br /> else out_fy1 <= out_fy1 + 1 ;<br /> end if;<br /> else out_fy0 <= out_fy0 + 1 ;<br /> end if; <br /> star2 <= '1';<br /> elsif(star2 ='1') then<br /> star2 <= '0';<br /> end if; <br /> end if;<br /> end process;<br /><br /><br /><br />--*************以下是标准频率的测量部分**********************<br /><br /> process(f0,rs,star1)<br /> begin<br /> if(rs = '0') then <br /> out_f00 <="0000"; out_f01 <="0000"; out_f02 <="0000"; out_f03 <="0000"; out_f04 <="0000"; out_f05 <="0000"; out_f06<="0000";<br /> elsif(f0' event and f0 = '1') then<br /> if(star1 = '1') then<br /> if (out_f00 = 15) then out_f00 <="0000";<br /> if (out_f01 = 15) then out_f01 <="0000";<br /> if (out_f02 = 15) then out_f02 <="0000";<br /> if (out_f03 = 15) then out_f03 <="0000";<br /> if (out_f04 = 15) then out_f04 <="0000";<br /> if (out_f05 = 15) then out_f05 <="0000";<br /> if(out_f06 = 15 ) then out_f06 <="0000";<br /> else out_f06 <= out_f06+1 ;<br /> end if;<br /> else out_f05 <= out_f05 + 1 ;<br /> end if;<br /> else out_f04 <= out_f04 + 1 ;<br /> end if;<br /> else out_f03 <= out_f03 + 1 ;<br /> end if;<br /> else out_f02 <= out_f02 + 1 ;<br /> end if;<br /> else out_f01 <= out_f01 + 1 ;<br /> end if;<br /> else out_f00 <= out_f00 + 1 ;<br /> end if; <br /> end if;<br /> end if;<br /> end process;<br /><br /> process(f0,rs,star2)<br /> begin<br /> if(rs = '0') then <br /> out_f10 <="0000"; out_f11 <="0000"; out_f12 <="0000"; out_f13 <="0000"; out_f14 <="0000"; out_f15 <="0000"; out_f16<="0000";<br /> elsif(f0' event and f0 = '1') then<br /> if(star2 = '1') then<br /> if (out_f10 = 15) then out_f10 <="0000";<br /> if (out_f11 = 15) then out_f11 <="0000";<br /> if (out_f12 = 15) then out_f12 <="0000";<br /> if (out_f13 = 15) then out_f13 <="0000";<br /> if (out_f14 = 15) then out_f14 <="0000";<br /> if (out_f15 = 15) then out_f15 <="0000";<br /> if(out_f16 = 15 ) then out_f16 <="0000";<br /> else out_f16 <= out_f16+1 ;<br /> end if;<br /> else out_f15 <= out_f15 + 1 ;<br /> end if;<br /> else out_f14 <= out_f14 + 1 ;<br /> end if;<br /> else out_f13 <= out_f13 + 1 ;<br /> end if;<br /> else out_f12 <= out_f12 + 1 ;<br /> end if;<br /> else out_f11 <= out_f11 + 1 ;<br /> end if;<br /> else out_f10 <= out_f10 + 1 ;<br /> end if; <br /> end if;<br /> end if;<br /> end process;<br /><br />--*******以下是输出部分程序***************************<br /><br /> process(choose)<br /> begin<br /> case choose is<br /><br />--*****************以下是第一组测量结果的输出 ******* when "00111" => output(7 downto 4) <= "0000";<br /> output(3 downto 0) <= out_f06;<br /> when "00100" => output(7 downto 4) <= out_f05 ;<br /> output(3 downto 0) <= out_f04 ;<br /> when "00101" => output(7 downto 4) <= out_f03 ;<br /> output(3 downto 0) <= out_f02 ;<br /> when "00110" => output(7 downto 4) <= out_f01 ;<br /> output(3 downto 0) <= out_f00 ;<br /> <br /><br /> when "00001" => output(7 downto 4) <= out_fx3 ;<br /> output(3 downto 0) <= out_fx2 ;<br /> when "00010" => output(7 downto 4) <= out_fx1 ;<br /> output(3 downto 0) <= out_fx0 ;<br /><br />--*********以下是第二组测量结果的输出*********************<br /><br /> when "01111" => output(7 downto 4) <= "0000";<br /> output(3 downto 0) <= out_f16;<br /> when "01100" => output(7 downto 4) <= out_f15 ;<br /> output(3 downto 0) <= out_f14 ;<br /> when "01101" => output(7 downto 4) <= out_f13 ;<br /> output(3 downto 0) <= out_f12 ;<br /> when "01110" => output(7 downto 4) <= out_f11 ;<br /> output(3 downto 0) <= out_f10 ;<br /><br /> when "01001" => output(7 downto 4) <= out_fy3 ;<br /> output(3 downto 0) <= out_fy2 ;<br /> when "01010" => output(7 downto 4) <= out_fy1 ;<br /> output(3 downto 0) <= out_fy0 ;<br /><br /> when others => output <= "ZZZZZZZZ";<br /> end case; <br /> end process;<br /> end behave;<br /><br /> |
|