在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 9096|回复: 24

[求助] 高手看过来:简易鉴相器问题(附代码)

[复制链接]
发表于 2010-5-4 11:04:46 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
今天仿真网友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导致了错误!但小弟却担心改动此处将造成一发而动全身的结果,望高手支招!
发表于 2010-5-4 11:58:36 | 显示全部楼层
posedge 加 ==0 ??? 你觉得合适吗?
 楼主| 发表于 2010-5-4 12:39:42 | 显示全部楼层
谢谢回复。关于这一点我注意到的。问题在于就是要对上升沿进行判别啊。
发表于 2010-5-4 13:34:40 | 显示全部楼层
2楼的正解
 楼主| 发表于 2010-5-4 16:01:55 | 显示全部楼层
本帖最后由 zhinvxing 于 2010-5-6 14:25 编辑

谢谢回复。下面是我改写的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
signal  cnt_start :std_logic;             --开始计数标志
signal  cnt1:std_logic_vector(3 downto 0); --计数器
signal  puls :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;  
            elsif  puls1='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仍在计数!这不是我所需要的。产生的原因在于上面代码中的红色语句部分。但我暂时不愿去修改了,以免牵一发而动全身!
                                  edacn.jpg
发表于 2010-5-4 17:29:32 | 显示全部楼层
第一个代码是个初学者,只知HDL,不知电路的人,第二个代码没看.
 楼主| 发表于 2010-5-4 20:41:43 | 显示全部楼层
好了,终于把图弄上来了。大家看看吧
 楼主| 发表于 2010-5-5 09:25:25 | 显示全部楼层
别沉了
发表于 2010-5-5 10:12:10 | 显示全部楼层
cnt_start这个信号是用来控制计数的吧?但是根本没用上。
还有程序写的太乱。建议用case。
 楼主| 发表于 2010-5-5 12:08:27 | 显示全部楼层
第一个进程中关于上升沿的到来,以及cnt_star的判断的确有可以改进的地方。但代码的总体结构不算太乱吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条

×

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-4 20:03 , Processed in 0.044420 second(s), 10 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表