集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 2175|回复: 2

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

[复制链接]
老怪甲 该用户已被删除
老怪甲 发表于 2010-5-5 22:02:54 | 显示全部楼层 |阅读模式
今天仿真网友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-5 22:03:29 | 显示全部楼层
谢谢回复。下面是我改写的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仍在计数!这不是我所需要的。产生的原因在于上面代码中的红色语句部分。但我暂时不愿去修改了,以免牵一发而动全身!
Sunlife 发表于 2015-4-7 11:17:02 | 显示全部楼层
是两个周期相同但相位不同的方波。pf_up、ps_down用于向其他模块输出超前或滞后信号
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

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

QQ|小黑屋|手机版|Archiver|fpga论坛|fpga设计论坛 ( 京ICP备20003123号-1 )

GMT+8, 2025-5-7 05:05 , Processed in 0.059621 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表