一个关于延迟检测的问题

[复制链接]
4723|28
 楼主| dandanzhou 发表于 2012-7-2 09:55 | 显示全部楼层 |阅读模式
以下的代码,老是通不过编译,显示的错误是:Error (10822): HDL error at test17.vhd(384): couldn't implement registers for assignments on this clock edge
这段代码的主要意思是当speed2有下降沿时,通过外部时钟开始计数,等到“11111111”时间后,如果speed2还是低电平,则给计数器result加1,否则不加。主要是防止信号误操作的。
请各位大侠帮忙看看,是顺序有问题,还是哪里 有问题。谢谢

test:process(speed2,EXTCLK)
begin
case speedtest3 is
when 0 =>
    if speed2'event and speed2='0'then
     m<='1';
     end if;
     when 1 =>
   result1<=result;
     result<="0000000000000000";
end case;
if(m<='1')then
  if EXTCLK'event and EXTCLK='1'then
     if counter100="11111111" then
        if(speed2<='0')then
        result<=result+1;
        counter100<="00000000";
        m<='0';
        else m<='0';
        counter100<="00000000";
        end if;  
      else
      counter100<=counter100+1;
     end if;
     end if;
     end if;
end process;
GoldSunMonkey 发表于 2012-7-2 15:47 | 显示全部楼层
if speed2'event and speed2='0'then,一个进程中,从来没见过使用两个时钟。
这个应该是问题的所在。
if(speed2<='0')then这个也不对,应该是if(speed2='0')then
 楼主| dandanzhou 发表于 2012-7-2 15:52 | 显示全部楼层
问题是我想在一个进程中,由一个下降沿触发,来开始计数,那怎么办啊?
GoldSunMonkey 发表于 2012-7-2 16:20 | 显示全部楼层
用15M时钟采样10k的时钟,
让a=10k时钟,b=a,

然后用15M的时钟检查AB,如果发现a=0,b=1,则为下降沿。
 楼主| dandanzhou 发表于 2012-7-2 17:19 | 显示全部楼层
您这是回复我发给你的消息吧,我需求对speed2
测试下降沿,应该把上楼中的10可时钟换成speed2吧
GoldSunMonkey 发表于 2012-7-2 18:07 | 显示全部楼层
嗯。~~
有体会了再来。
 楼主| dandanzhou 发表于 2012-7-3 12:47 | 显示全部楼层
刚刚测试了一下,如果用10k的时钟做定时器,在1秒钟内,对Speed2的下降沿计数,把speed2的下降沿改为“a=0,b=1,”的语句,的确可以计数。但是,现在还有一个问题,如果在此基础上,再引入一个外部时钟15M,当speed2下降沿触发后,想通过一段时间后再次测试speed2,是否为低电平,来判断该下降沿是否有效。我把15M时钟也采用“a=0,b=1,”的方式,可是发现没法计数,不知道是为什么啊
 楼主| dandanzhou 发表于 2012-7-3 12:55 | 显示全部楼层
commu:process (Tclk1)
begin
      if tclk1'event and tclk1='1'then
     if counter1000="100111000100000"then
      int_t(3)<='0';
     en_serial<='1';
    counter1000<="00000000000000";
    else counter1000<=counter1000+1;
     int_t(3)<='1';
     end if;
     end if;
     
      if (en_serial='1')then
      result1<=result;
      clear<='1';
      en_serial<='0';
      end if;
     
     if (clear='1') then result<="0000000000000000";
     clear<='0';
     else
  --if speed2'event and speed2='0'then
  if c='0'and d='1'then     
       if a='0'and b='1'then
            if counter100="11111111"then
                            result<=result+1;
                counter100<="00000000";
                else counter100<=counter100+1;
                    end if;
                 end if;
             end if;
            end if;
         end process;

可能看着程序更能表达我的意思,第一段的主要通过10K时钟的tclk在1s内进行计数,第三段是当这1s内,speed2下降沿触发后,不是立马使计数器加一,而是通过15M的时钟EXTCLK经过一段时间延迟后,再让计数器result加一。可是,程序能通过综合,却运行起来无法计数。
GoldSunMonkey 发表于 2012-7-3 13:10 | 显示全部楼层
:L15M的时钟无法如此做,因为他们频率相同,无法采样到啊
 楼主| dandanzhou 发表于 2012-7-3 13:12 | 显示全部楼层
15M的时钟我只用了一次啊,就是在第三段里面啊,没有和其他的时钟频率一样啊
 楼主| dandanzhou 发表于 2012-7-3 13:14 | 显示全部楼层
我想我明白了,你说的是cpld本身的外部时钟已经是15M的是吧,没法再采样了吧
GoldSunMonkey 发表于 2012-7-3 13:16 | 显示全部楼层
GoldSunMonkey 发表于 2012-7-3 13:16 | 显示全部楼层
你明白了。
 楼主| dandanzhou 发表于 2012-7-3 15:08 | 显示全部楼层
我要崩溃了,重新测试了一下程序,就是把下降沿改为“c=0,d=1,”的句式,可是发现又没有办法计数了,Goldsunmonkey,能帮我看看是什么问题么?

commu:process (Tclk1)
begin
      if tclk1'event and tclk1='1'then
      if counter1000="10011011010100"then
     int_t(3)<='0';
     en_serial<='1';
     counter1000<="00000000000000";
     else counter1000<=counter1000+1;
     int_t(3)<='1';
     end if;
     end if;
     
      if (en_serial='1')then
      result1<=result;
      clear<='1';
      en_serial<='0';
      end if;
     
     if (clear='1') then result<="0000000000000000";
     clear<='0';
     else
       if c='0'and d='1'then     
             result<=result+1;
             end if;
            end if;
            
   
     end process;
GoldSunMonkey 发表于 2012-7-3 15:28 | 显示全部楼层
做不了,证明你没有采到,你自己检查原因。

代码关于下降沿的写法没有问题。
我没有看其他部分
 楼主| dandanzhou 发表于 2012-7-3 15:41 | 显示全部楼层
想问一下,将时钟信号赋值给c,d是应该在进程之外赋值吧。
GoldSunMonkey 发表于 2012-7-3 16:08 | 显示全部楼层
:L肯定进程之内,否则怎么保证寄存器呢?
 楼主| dandanzhou 发表于 2012-7-3 16:14 | 显示全部楼层
我要疯了,估计你也差不多了吧,我写了一个小程序来测试,可是居然也没法计数:
test1:process(tclk1)
begin
  if TCLK1'event and TCLK1='1'then
  c<=speed2;
  d<=c;
  end if;
if  c='0'and d='1'then
             e<=not e;
             speed1<=e;
end if;
end process;

如你所说的,tclk1是高频时钟,speed2是低频脉冲,可是这个简单程序都没**常输出speed1信号。我真的弄得头都大了。谢谢了啊
GoldSunMonkey 发表于 2012-7-3 16:17 | 显示全部楼层
首先这个代码风格太差了。
 楼主| dandanzhou 发表于 2012-7-3 16:18 | 显示全部楼层
我真的是刚整这个vhdl,拜托你帮我看看吧
您需要登录后才可以回帖 登录 | 注册

本版积分规则

13

主题

41

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部