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

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

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 3120|回复: 0

[求助] 求助

[复制链接]
发表于 2011-7-18 21:57:23 | 显示全部楼层 |阅读模式

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

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

x
初学verilog,编了一个交通控制的逻辑程序,有两个错误我一直没办法解决,求大师帮忙!不慎感激!
module train_trafic (//input
                      clk,rst_n,train_coming,
                      timed,
                     //output
                      light);
       input clk,rst_n,train_coming,tim_over;
       output light;
      
       reg light;
       reg [2:0] state;
       reg [2:0] nextstate;
      
       wire enable;
      
       parameter IDLE  = 0;
       parameter START = 1;
       parameter SECND = 2;
       parameter FINL  = 3;
       parameter RED   = 4;
       parameter GREEN = 5;
  cnt_time(enable,tim_over);
      
  /******************state transferring************/     
       always @(posedge clk or negedge rst_n)begin
           if (!rst_n)begin
              state<=GREEN;
              end
              else
              state<=nextstate;
         end  
/************State machine coding**********/
            
       always @(state or train_coming)      
            case(state)
             IDLE: if(train_coming)
                      nextstate = START;
                      else
                      nextstate = IDLE;
             START:
                      nextstate = SECND;
                     
             SECND:
                     nextstate = FINL;
              FINL: if(tim_over)
                      nextstate = IDLE;
                      else
                      nextstate = FINL;
            default:  nextstate = GREEN;        
          endcase
/*********** output*************************/
                     
       always @(posedge clk or negedge rst_n)
            begin
               if(!rst_n)
                  light<= GREEN;
                  else
                  if(nextstate == SECND) begin
                   cnt_time(.enable(enable),.tim_over(tim_over));
                   if(tim_over)
                     light<=RED;
                    else
                     light<=GREEN;
               end
             end
   endmodule
/**************Counting time*******************/
  task cnt_time;
       input enable;
       output tim_over;
      
       reg tim_over;
       parameter TOPTIM=255;
       integer i;
                  
     always @(i) begin   
       if(enable)begin
           if(i==TOPTIM)
              tim_over=1;
              else
               i=i+1;
           end
          else
         i=0;
        end
  endtask
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

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

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

GMT+8, 2024-9-21 10:40 , Processed in 0.024262 second(s), 11 queries , Gzip On, Redis On.

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