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

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

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
12
返回列表 发新帖
楼主: alyssa

FPGA并行的研究与困惑!!

[复制链接]
 楼主| 发表于 2007-5-26 14:51:52 | 显示全部楼层
终于分成模块了!谢谢大家的指点

//LAMP:灯的状态
//num: 倒计时
//numa: 倒计时赋值的中间变量
module traffic0(CLK,LAMP,nrst,num);
output[7:0] num;
output[2:0] LAMP;
input CLK,nrst;
reg[7:0] num,numa;
reg[3:0] CS,NS;
reg[2:0] LAMP;
reg temp;//倒计时赋值标志
parameter IDLE=4'b001, S1=4'b0010, S2=4'b0100,S3=4'b1000; //one_hot
parameter red=8'd15,yellow=8'd10,bule=8'd5; //红,黄,蓝各亮的时间  
always @(posedge CLK )
if(!nrst)
   CS<=IDLE;
else
   CS<=NS;
always @(CS or temp )
begin
   NS=4'bx;
case(CS)
IDLE:
   if(temp)
  NS=IDLE;
    else
     NS=S1;
S1:
    if(temp)
  NS=S1;
    else
     NS=S2;      
S2:   
    if(temp)
  NS=S2;
    else
     NS=S3;
      
S3:  
    if(temp)
     NS=S3;
    else
     NS=S1;
      
default:NS=IDLE;
endcase
end
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
always @(NS or nrst)//倒计时模块 赋值模块
   
if(!nrst)
begin
numa=8'd0;
end
else   
begin
case(NS)
  IDLE:
    numa=8'd0;   
  S1:
    numa=red;      
  S2:  
    numa=yellow;
  S3:  
    numa=bule;
endcase
end
  
always @(posedge CLK)//灯的状态模块
   
if(!nrst)
LAMP<=3'b000;
else   
begin
case(NS)
   IDLE:
     LAMP<=3'b000;
   S1:  
     LAMP<=3'b001;
   
   S2:  
     LAMP<=3'b010;
      
   S3:  
     LAMP<=3'b100;  
   endcase
end
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
  
always @(posedge CLK ) //倒计时模块         
if(!nrst)
begin
num<=0;
temp<=0;
end
else
begin               
  
   if(!temp)
    begin
    num<=numa;
    temp<=1;
    end            
  
   else  
     begin            
   if(num>0)            
     
    begin
      if(num[3:0]==0)
        begin   
        num[3:0]<=9;
        num[7:4]<=num[7:4]-4'b0001;
        end
      else
        num[3:0]<=num[3:0]-4'b0001;
   
      if(num==1)
     temp<=0;
    else
     temp<=1;
     end
        
         else
       temp<=0;
   end            
   
   end
   

endmodule
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

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

×

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

GMT+8, 2024-5-22 13:53 , Processed in 0.013703 second(s), 6 queries , Gzip On, Redis On.

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