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

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

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 11021|回复: 26

[讨论] 请求verilog高手指点程序问题!!!

[复制链接]
发表于 2011-11-3 10:12:56 | 显示全部楼层 |阅读模式

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

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

x
新接触verilog,自己写了一段代码,用到了case的嵌套,但是一直执行内部的case,跳不出来,请高手指点迷津!
case(state)
    idle: begin
      case({A,B})   //four initial states of A and B
        2'b00: begin        
          AO<=0;
          BO<=0;
          if(a2==0&a1==1&b1==b2==0) //a==b==0,but posedge of A comes first,A lead
           begin
            dependa<=1;
            AO<=~AO;
            state<=edgecount;  //goto count the edge of A,AO and BO change according their counters
           end
          else
           begin
           if(b2==0&b1==1&a1==a2==0) //a==b==0,but posedge of B comes first,B lead
            begin
             dependb<=1;
             BO<=~BO;
                state<=edgecount; //goto count the edge of A,AO and BO change according their counters
            end
           else state<=idle;
           end
                  
         end
      
       2'b01: begin
          AO<=0;
          BO<=1;
          if(a1==a2==0&b2==1&b1==0) //A==0,B==1,but negedge of B comes first, A lead
           begin
            dependb<=1;
            BO<=~BO;
            state<=edgecount;
           end
          else
          begin
           if (b1==b2==1&a2==0&a1==1) //A==0,B==1,but posedge of A comes first,B lead
           begin
            dependa<=1;
            AO<=~AO;
            state<=edgecount;
           end
           else state<=idle;
          end
        
         
         end
        
      
       2'b10: begin   
          AO<=1;
          BO<=0;
          if(a1==a2==1&b2==0&b1==1)//A==1,B==0,but posedge of B comes first, A lead
           begin
            dependb<=1;
            BO<=~BO;
            state<=edgecount;
           end
             else  begin
          if(b1==b2==0&a2==1&a1==0)//A==1,B==0,but negedge of A comes first ,B lead
            begin
             dependa<=1;
             AO<=~AO;
             state<=edgecount;
            end
           else state<=idle;
           end
                  
         end
        
        
       2'b11: begin     
          AO<=1;
          BO<=1;
          if(b1==b2==1&a2==1&a1==0) //A==B==1,but negedge of A comes first,A lead
           begin
            dependa<=1;
            AO<=~AO;
            state<=edgecount;
           end
          else
           begin
           if(a1==a2==1&b2==1&b1==0) //A==B==1,but negedge of B comes first,B lead
           begin
            dependb<=1;
            BO<=~BO;
            state<=edgecount;
           end
           else state<=idle;
              end
                end
         endcase
      end
edgecount:   begin
                               if(ena)
         state<=achange;       //state changes form edgecount to achange
                             
         else begin
            if(enb)
                                    state<=bchange;       //state changes form edgecount to bchange
         else state<=edgecount;
           end
       end
achange: begin
                            state<=edgecount;              //state changes from change to edgecount
                                 AO<=~AO;                       //AO changes  
                         end
               
bchange: begin
                            state<=edgecount;              //state changes from change to pulsecount
                                 BO<=~BO;                       //BO changes
                        end
              endcase
QQ截图20111103095303.jpg
代码实现的任务是:检测原信号AB,先判断它们的初值,直接赋给AO、BO,然后哪个边沿先到,对应的输出信号跳变,然后跳出内部case,执行外部case的edgecount分支。但是实际上程序好像是一直在内部case中执行。
     请路过的高手帮帮忙哦,不胜感激!
发表于 2011-11-3 11:43:46 | 显示全部楼层
好熟悉的界面,难道是ActiveHDL?
发表于 2011-11-3 11:47:12 | 显示全部楼层
本帖最后由 marsfabio 于 2011-11-3 11:48 编辑

回复 1# jeamie
你再多拉点信号才好帮你分析啊,比如state信号
发表于 2011-11-3 11:50:34 | 显示全部楼层
本帖最后由 marsfabio 于 2011-11-3 11:52 编辑

回复 1# jeamie
而且你最好把整个always语句块拉出来,我想看看你的敏感列表是怎么写的,虽然我猜应该是posedge clk反正你这个状态机风格写的不是很好
发表于 2011-11-3 12:21:27 | 显示全部楼层
回复 4# marsfabio


    是不是由于你内部case形成了锁存器导致的呢,你可以在endcase前加上default语句,即不满足上述情况后是什么状态,你可以尝试一下。
发表于 2011-11-3 12:25:09 | 显示全部楼层
回复 5# zhangkui711

他内部的case情况已经都写到了,没有default感觉也没关系
发表于 2011-11-3 12:35:20 | 显示全部楼层
本帖最后由 marsfabio 于 2011-11-3 12:39 编辑

回复 1# jeamie
我的一个考虑是,是不是因为你在做边沿检测的时候采样时钟频率太低?这样当A和B两个沿的时间比较接近的时候,你可能判断得到两个沿是同时采到的,这样导致你的状态一直停留在idle状态。你可以拉出a1,a2,b1,b2信号看看是不是这个原因。如果是的话,你可以试着把B再delay的时间多一点,或者采样时钟周期再短一点。
发表于 2011-11-3 12:50:54 | 显示全部楼层



同意楼上的,而且我很好奇你的a1,a2,b1,b2是什么。怎么判断A和B的跳变沿的??
如果没有看错的话,A和B都是一位的信号。
那么
alway@(posedge A or negedge A or posedge B or negedge B)
case({A,B}):
2'b00:
    if(A==1'b0 & B==1'b1)begin
         //这个地方就是B发生上跳沿了。
    end
    if(A==1'b1 & B==1'b0)begin
         //这个地方就是A发生上跳沿了。
    end
应该是这种写法吧。可以参照一般的 rst 信号的写法。
BTW:敏感列表我也不知道能不能这么写。
BTW-2:楼主的这个最好写成两个状态机吧。看这个嵌套有点乱~
发表于 2011-11-3 13:18:04 | 显示全部楼层
回复 8# Emersondjp
a1,a2我猜应该就是两个级联的DFF输出,用于边沿检测的
 楼主| 发表于 2011-11-3 14:17:53 | 显示全部楼层
回复 1# jeamie

always @ (posedge clk or posedge rst)
    begin
        if(rst)
        begin
            a1<=0;
            a2<=0;
            b1<=0;
            b2<=0;
    end
        else
        begin
            a1<=A;
            a2<=a1;           //a2 delay a1 one clk
            b1<=B;
            b2<=b1;           //b2 delay b1 one clk
     end
end
  

always @(posedge clk or posedge rst)
begin
  if(rst)
   begin
    AO<=0;
    BO<=0;
    state<=idle;
    dependa<=0;
    dependb<=0;
   end
  else
  begin
case(state)
   
idle: begin
      case({A,B})   //four initial states of A and B
        2'b00: begin        
               AO<=0;
               BO<=0;
               if(a2==0&a1==1&b1==b2==0) //a==b==0,but posedge of A comes first,A lead
               begin
                   dependa<=1;
                   AO<=~AO;
                  state<=edgecount;  //goto count the edge of A,AO and BO change according their counters
              end
             else if (b2==0&b1==1&a1==a2==0) //a==b==0,but posedge of B comes first,B lead
                  begin
                  dependb<=1;
                  BO<=~BO;
                 state<=edgecount; //goto count the edge of A,AO and BO change according their counters
                  end
            else state<=idle;
       end
      
       2'b01: begin
          AO<=0;
          BO<=1;
          if(a1==a2==0&b2==1&b1==0) //A==0,B==1,but negedge of B comes first, A lead
           begin
            dependb<=1;
            BO<=~BO;
            state<=edgecount;
           end
          else if (b1==b2==1&a2==0&a1==1) //A==0,B==1,but posedge of A comes first,B lead
           begin
            dependa<=1;
            AO<=~AO;
            state<=edgecount;
           end
           else state<=idle;
        end
        
      
       2'b10: begin   
          AO<=1;
          BO<=0;
          if(a1==a2==1&b2==0&b1==1)//A==1,B==0,but posedge of B comes first, A lead
           begin
            dependb<=1;
            BO<=~BO;
            state<=edgecount;
           end
             else  if (b1==b2==0&a2==1&a1==0)//A==1,B==0,but negedge of A comes first ,B lead
            begin
             dependa<=1;
             AO<=~AO;
             state<=edgecount;
            end
           else state<=idle;
       end
        
        
       2'b11: begin     
          AO<=1;
          BO<=1;
          if(b1==b2==1&a2==1&a1==0) //A==B==1,but negedge of A comes first,A lead
           begin
            dependa<=1;
            AO<=~AO;
            state<=edgecount;
           end
          else if (a1==a2==1&b2==1&b1==0) //A==B==1,but negedge of B comes first,B lead
           begin
            dependb<=1;
            BO<=~BO;
            state<=edgecount;
           end
           else state<=idle;
          end
         endcase
         end
edgecount:   begin
                               if(ena)
         state<=achange;       //state changes form edgecount to achange
                             
         else begin
            if(enb)
                                    state<=bchange;       //state changes form edgecount to bchange
         else state<=edgecount;
           end
       end
achange: begin
                            state<=edgecount;              //state changes from change to edgecount
                                 AO<=~AO;                       //AO changes  
                         end
               
bchange: begin
                            state<=edgecount;              //state changes from change to pulsecount
                                 BO<=~BO;                       //BO changes
                        end
endcase
环境是Active—HDL的。以上就是和case嵌套相关的程序了,a1、a2和b1、b2是为了检测A、B信号的边沿。
从仿真波形我分析了一下是一直在执行内部case,但是没分析出什么原因。理论上执行完内部case的一个分支以后(并且总会执行四个情况中的一种)就跳到外部case的edgecount分支。
请大家帮忙分析一下原因,因为刚接触,没什么经验。
非常感谢!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

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

×

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

GMT+8, 2024-5-12 12:40 , Processed in 0.048695 second(s), 13 queries , Gzip On, Redis On.

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