流水灯不受控制
时间:10-02
整理:3721RD
点击:
input SYSCLK_50M; //System clock, 50MHz.
input RST_B; //Global reset, low active.
input PUSH_SW1; //G
//input key; //G
output [5:0] LED_DATA; //LED data output.
//===========================================================================
//Wire and reg declaration
//===========================================================================
wire SYSCLK_50M;
wire RST_B;
reg [5:0] LED_DATA;
//wire key;reg [23:0] TIME_CNT; //Count the time, everyone show 1ms.
reg [5:0] LED_DATA_N; //Next value of LED_DATA.
wire [23:0] TIME_CNT_N; //Next value of TIME_CNT.
reg led_dir;always @(negedge RST_B or negedge SYSCLK_50M)
begin
if(!RST_B)
TIME_CNT <= `UD 21'b0;
else
TIME_CNT <= `UD TIME_CNT_N;
end
assign TIME_CNT_N = TIME_CNT + 21'b1;
always @(negedge RST_B or negedge SYSCLK_50M)
begin
if(!RST_B)
LED_DATA <= `UD 6'b11_1110;//这里LED同样是低电平有效,初值只允许一个LED亮
else
LED_DATA <= `UD LED_DATA_N;
end
always @(negedge RST_B or negedge SYSCLK_50M)
begin
if(!RST_B)
led_dir <=1'b0;
else
begin
if(PUSH_SW1)
led_dir <= 1'b0; //从低到高流动
else
led_dir <= 1'b1; //从高到低流动
end
endalways @ (*)
begin
if(TIME_CNT == 24'h0 )
case(led_dir)
1'b0: LED_DATA_N = {LED_DATA[5],LED_DATA[4:0]};
1'b1: LED_DATA_N = {LED_DATA[4:0],LED_DATA[5]};
default: ;
endcase
else
LED_DATA_N = LED_DATA;
end
endmodule
我想的是拨码开关led_dir 为高时流水灯正常流动,为低时反向流动,可我下载到板子上后为低能流动 为高电平时不流动为什么呢
input RST_B; //Global reset, low active.
input PUSH_SW1; //G
//input key; //G
output [5:0] LED_DATA; //LED data output.
//===========================================================================
//Wire and reg declaration
//===========================================================================
wire SYSCLK_50M;
wire RST_B;
reg [5:0] LED_DATA;
//wire key;reg [23:0] TIME_CNT; //Count the time, everyone show 1ms.
reg [5:0] LED_DATA_N; //Next value of LED_DATA.
wire [23:0] TIME_CNT_N; //Next value of TIME_CNT.
reg led_dir;always @(negedge RST_B or negedge SYSCLK_50M)
begin
if(!RST_B)
TIME_CNT <= `UD 21'b0;
else
TIME_CNT <= `UD TIME_CNT_N;
end
assign TIME_CNT_N = TIME_CNT + 21'b1;
always @(negedge RST_B or negedge SYSCLK_50M)
begin
if(!RST_B)
LED_DATA <= `UD 6'b11_1110;//这里LED同样是低电平有效,初值只允许一个LED亮
else
LED_DATA <= `UD LED_DATA_N;
end
always @(negedge RST_B or negedge SYSCLK_50M)
begin
if(!RST_B)
led_dir <=1'b0;
else
begin
if(PUSH_SW1)
led_dir <= 1'b0; //从低到高流动
else
led_dir <= 1'b1; //从高到低流动
end
endalways @ (*)
begin
if(TIME_CNT == 24'h0 )
case(led_dir)
1'b0: LED_DATA_N = {LED_DATA[5],LED_DATA[4:0]};
1'b1: LED_DATA_N = {LED_DATA[4:0],LED_DATA[5]};
default: ;
endcase
else
LED_DATA_N = LED_DATA;
end
endmodule
我想的是拨码开关led_dir 为高时流水灯正常流动,为低时反向流动,可我下载到板子上后为低能流动 为高电平时不流动为什么呢
1.PUSH_SW1是对于本时钟来说,是异步信号,需要使用寄存器打二拍同步,2.PUSH_SW1输入信号要消抖
3.1'b0: LED_DATA_N = {LED_DATA[5],LED_DATA[4:0]};这条语句不会产生LED偏移,应该改为:
1'b0: LED_DATA_N = {LED_DATA[0],LED_DATA[5:1]};
纯汇编 ,表示看不懂。
谢谢哈哈,你完美解决我的问题啦