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

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

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 2569|回复: 5

[求助] 学校的FPGA 设计---交通灯卫星控制器

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

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

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

x
高手们 别笑我..我对这个确实不会.可是实习马上就要验收了..用MODELSIM 仿真..再网上看了个 学长 写的代码 没看懂.更不会写仿真激励 .希望高手们 给我解答一下吧。那个控制模块确实没看懂  这种分模块的 激励怎么写呢?。。小弟在这谢谢你们了...您的大恩大德  小弟记住了 以后多来论坛里报答  代码如下:

分频模块:

module fenpinqi(clk,rst,clk_odd);


input
clk,rst;


output
clk_odd;


reg
clk_odd;


reg[13:0]
count;


parameter
N = 10000;



always @ (posedge clk)


if(! rst)


begin


count <= 1'b0;


clk_odd <= 1'b0;


end


else


if ( count < N/2-1)


begin


count <= count + 1'b1;


end


else


begin


count <= 1'b0;


clk_odd <= ~clk_odd;


end

endmodule

控制及计时模块:

module control(led,car,rst,clk,count_H_1,count_L_1,count_H_2,count_L_2);



output [3:0]count_H_1,count_L_1,count_H_2,count_L_2;


output [5:0]led;


input clk,rst,car;


reg [5:0] led;


reg [3:0]count_H_1,count_L_1,count_H_2,count_L_2;


reg [1:0]state;



parameter S0=2'b00,


S1=2'b01,


S2=2'b10,


S3=2'b11;



always @(posedge clk or negedge rst)


if(!rst)


begin


led=6'b010100;


state=S0;


count_H_1=4'b0000;count_L_1=4'b0000;


count_H_2=4'b0000;count_L_2=4'b0000;


end


else


begin


case(state)



S0:



begin


if(!car)


begin


led=6'b010100;


count_H_1=4'b0100;count_L_1=4'b0101;




end


else if(count_L_1==0)


begin


if(count_H_1==0)


begin


led=6'b001100;



count_H_1=4'b0000;count_L_1=4'b0100;



state<=S1;


end


else



begin


count_H_1<=count_H_1-1'b1;



count_L_1<=4'b1001;



end



end


else begin


count_L_1<=count_L_1-1'b1;


//
count_L_2<=count_L_2-1'b1;



end


if(!car)



begin






count_H_2=4'b0101;count_L_2=4'b0000;



end



else if(count_L_2==0)



begin




count_H_2<=count_H_2-1'b1;




count_L_2<=4'b1001;




end



else begin




count_L_2<=count_L_2-1'b1;



end



end



S1:


begin


if(count_L_1==0)


begin



if(count_H_1==0)


begin


led=6'b100010;


count_H_1=4'b0010;count_L_1=4'b1001;


count_H_2=4'b0010;count_L_2=4'b0100;



state<=S2;


end


else
begin


count_H_1<=count_H_1-1'b1;


count_H_2<=count_H_2-1'b1;


end


end



else begin


count_L_1<=count_L_1-1'b1;


count_L_2<=count_L_2-1'b1;


end


end



S2:


begin


if(count_L_2==0)


begin


if(count_H_2==0)


begin


led=6'b100001;



count_H_2=4'b0000;count_L_2=4'b0100;



state<=S3;


end


else
begin



count_H_2<=count_H_2-1'b1;



count_L_2=4'b1001;


end



end


else begin



count_L_2<=count_L_2-1'b1;


end




if(count_L_1==0)


begin



begin


count_H_1<=count_H_1-1'b1;



count_L_1=4'b1001;



end


end


else begin


count_L_1<=count_L_1-1'b1;



end



end



S3:


begin


if(count_L_2==0)


begin


if(count_H_2==0)


begin


led=6'b010100;



count_H_1=4'b0100;count_L_1=4'b1001;


count_H_2=4'b0100;count_L_2=4'b0100;


state<=S0;


end


else
begin


count_H_1<=count_H_1-1'b1;


count_H_2<=count_H_2-1'b1;


end


end


else


begin


count_L_1<=count_L_1-1'b1;



count_L_2<=count_L_2-1'b1;


end


end


endcase

end

endmodule

扫描译码显示模块:

module saomiao(rst,clk,count_H_1,count_L_1,count_H_2,count_L_2,sel,seg);



input rst,clk;


input [3:0]count_H_1,count_L_1,count_H_2,count_L_2;


output [6:0]sel;


output [3:0]seg;


reg [6:0]sel;


reg [3:0]seg;



reg [15:0] count;


reg [1:0] cnt;


reg
[3:0] data;


reg clk_odd;




always@(posedge clk or negedge rst)//50M-1k,50M/1k/2//??,50Mhz~1khz,???50%


begin


if(!rst)begin


count<=0;


clk_odd<=0;


end


else if(count==16'd2)



begin


clk_odd<=~clk_odd;


count<=0;


end


else


count<=count+1'b1;


end


always @(negedge rst or posedge clk_odd)//????1ms


if (!rst)begin



cnt<=2'b00;


end


else cnt<=cnt+1'b1;

always@(negedge rst or posedge clk)
//????

if(!rst)
begin



// sel = 7'b0000000 ;



seg = 4'b1111 ;



end


else begin



case (cnt)


2'b00: begin


seg =4'b1110 ;// ?????



data=count_H_1;



end



2'b01: begin


seg
= 4'b1101 ;// ?????



data
=count_L_1;



end



2'b10:begin // ?????


seg= 4'b1011 ;



data=count_H_2;



end



2'b11: begin// ?????


seg= 4'b0111 ;



data=count_L_2;




end


default :


begin


//
sel = 8'b0000000 ;


seg = 4'b0000 ;


end


endcase


end


always @ (data or seg)begin


case(data)


4'b0000:sel=7'b1111110;


4'b0001:sel=7'b0110000;


4'b0010:sel=7'b1101101;


4'b0011:sel=7'b1111001;


4'b0100:sel=7'b0110011;


4'b0101:sel=7'b1011011;


4'b0110:sel=7'b1011111;


4'b0111:sel=7'b1110000;


4'b1000:sel=7'b1111111;


4'b1001:sel=7'b1111011;


default:sel=7'b1111110;


endcase


end



endmodule

顶层模块:

module jiaotongdeng(clk,rst,car,led,sel,seg);


input clk,rst,car;

output [3:0] seg;

output [6:0] sel;

output [5:0] led;

wire [3:0]count_H_1,count_L_1,count_H_2,count_L_2;

wire
clk_odd;

saomiao ee(rst,clk,count_H_1,count_L_1,count_H_2,count_L_2,sel,seg);

control rr(led,car,rst,clk_odd,count_H_1,count_L_1,count_H_2,count_L_2);

fenpinqi tt(clk,rst,clk_odd);

endmodule

它的设计图

它的设计图
发表于 2011-3-2 10:14:58 | 显示全部楼层
有勇气不学就要有勇气宕。
 楼主| 发表于 2011-3-3 10:50:54 | 显示全部楼层
回复 2# jackertja


   呵呵    今天早上 仔细看了一下 里面有些错误 已经改了...
发表于 2011-3-4 14:24:10 | 显示全部楼层
学习下
发表于 2011-3-4 15:38:24 | 显示全部楼层
学习下
发表于 2012-4-18 19:40:38 | 显示全部楼层
同样是新手
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

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


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

GMT+8, 2024-11-23 10:27 , Processed in 0.030502 second(s), 10 queries , Gzip On, Redis On.

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