高手看过来:简易鉴相器问题(附代码)
今天仿真网友yayapei在帖子中说到的鉴相器。其中,pf_up是local相比reference朝前,pf_down是滞后。我编译后QII报错,各位看看
原作者——yayapei
其原代码见下:
module top_jianxiang(reference_frq, local_frq, pf_up, pf_down );
input reference_frq;
input local_frq;
output pf_up;
output pf_down ;
reg pf_up,pf_down;
always @(posedge reference_frq or posedge local_frq)
begin
if (local_frq == 0) //reference_frq的上升沿先到
pf_down <= 1;
else
if (local_frq == 1) //local_frq的上升沿先到
pf_down <= 0;
end
always @(posedge reference_frq or posedge local_frq)
begin
if (reference_frq == 0)
pf_up <= 1;
else
if (reference_frq == 1)
pf_up <= 0;
end
endmodule
在用Quartus II编译时报错:“Error (10200): Verilog HDL Conditional Statement error at top_jianxiang.v(11): cannot match operand(s) in the condition to the corresponding edges in the enclosing event control of the always construct”
很明显这是指代码中always部分有问题,将local_frq要求为上升沿启动always导致了错误!但小弟却担心改动此处将造成一发而动全身的结果,望高手支招! 谢谢回复。下面是我改写的VHDL代码,但仍有一些bug,小弟贴出来,就算是抛砖引玉一下,望各位路过高手支招。
说明: puls1(本地估算时钟)和puls2(输入信号)是两个周期相同但相位不同的方波。pf_up、ps_down用于向其他模块输出超前或滞后信号。
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity phase_detect is
port(reset :in std_logic;
clk :in std_logic;
puls1 :in std_logic;
puls2 :in std_logic;
pf_up :out std_logic; --pf_up表示puls1 比puls2超前
pf_down : out std_logic; --pf_down表示puls1 比puls2滞后
cnt : out std_logic_vector(3 downto 0) --超前或滞后的计数值输出
);
end phase_detect;
architecture behav of phase_detect is
signalcnt_start :std_logic; --开始计数标志
signalcnt1:std_logic_vector(3 downto 0); --计数器
signalpuls :std_logic;
begin
puls<=puls1 or puls2; --用于检测puls1或者puls2的上跳沿
P1:process(puls,puls1,puls2)
begin
if puls='1' then --出现上跳沿,则置cnt_start标志位
cnt_start<='1';
end if;
if (puls1 and puls2)='1' then--当puls1和puls2同时出现时,清除标志位
cnt_start<='0';
end if;
end process;
P2:process(reset,clk)
begin
if reset='0' then
cnt1<="0000";
pf_up<='0';
pf_down<='0';
elsif clk'event and clk='1' then
if cnt_start='1' then
if puls1='1' and puls2='0' then --当puls1脉冲先到的时候
if cnt1>="0011" then --如果相位误差大于3个时钟,pf_up有输出
pf_up<='1';
cnt1<="0000";
else
cnt1<=cnt1+1;
end if;
elsifpuls1='0' and puls2='1' then--当puls2脉冲先到的时候
if cnt1>="0011" then --如果相位误差大于3个时钟,pf_down有输出
pf_down<='1';
cnt1<="0000";
else
cnt1<=cnt1+1;
end if;
end if;
else
cnt1<="0000";
end if;
end if;
end process;
cnt<=cnt1;
end behav;
从下面仿真图可见,在puls1比puls2先到的情形下,cnt1的确能进行相位误差计数。但是,在两条红线之间,cnt1仍在计数!这不是我所需要的。产生的原因在于上面代码中的红色语句部分。但我暂时不愿去修改了,以免牵一发而动全身! 是两个周期相同但相位不同的方波。pf_up、ps_down用于向其他模块输出超前或滞后信号
页:
[1]