module rot(led,rot_a,rot_b,rotary_press,clk,rst
);
output [7:0]led;
input rot_a;
input rot_b;
input rotary_press;
input clk;
input rst;
//internal signals
wire rot_a_pulse;
wire rot_b_pulse;
wire rotary_push_down;
reg [1:0]rot_a_buffer;
reg [1:0]rot_b_buffer;
reg [1:0]rotary_press_buffer;
reg rot_clk;
reg [6:0]cnt1;
reg [5:0]cnt2;
reg rot_left;
reg rot_right;
reg [7:0]led_pattern;
//--module code-----
//------------------
//---generate rot_clk
clk)
if(rst)
begin
cnt1<=7'd0;
end
else
begin
cnt1<=cnt1+1;
end
clk)
if(rst)
begin
rot_clk<=1'b0;
cnt2<=6'd0;
end
else
begin
if(cnt1==7'b111_1111)
begin
rot_clk<=1'b1;
cnt2<=6'd1;
end
else
begin
rot_clk<=1'b0;
cnt2<=cnt2+1;
end
end
//----
rot_clk)
if(rst)
begin
rot_a_buffer<=2'b00;
end
else
begin
rot_a_buffer[0]<=rot_a;
rot_a_buffer[1]<=rot_a_buffer[0];
end
rot_clk)
if(rst)
begin
rot_b_buffer<=2'b00;
end
else
begin
rot_b_buffer[0]<=rot_b;
rot_b_buffer[1]<=rot_b_buffer[0];
end
rot_clk)
if(rst)
begin
rotary_press_buffer<=2'b00;
end
else
begin
rotary_press_buffer[0]<=rotary_press;
rotary_press_buffer[1]<=rotary_press_buffer[0];
end
assign rot_a_pulse=~rot_a_buffer[0]&&rot_a_buffer[1];
assign rot_b_pulse=~rot_b_buffer[0]&&rot_b_buffer[1];
assign rotary_push_down=~rotary_press_buffer[0]&&rotary_press_buffer[1];
rot_clk)
if(rst)
begin
rot_left<=1'b0;
rot_right<=1'b0;
end
else
begin
if((rot_a_buffer[1]==1'b0)&&(rot_b_pulse==1'b1))
begin
rot_left<=1'b1;
end
else
begin
rot_left<=1'b0;
end
if((rot_b_buffer[1]==1'b0)&&(rot_a_pulse==1'b1))
begin
rot_right<=1'b1;
end
else
begin
rot_right<=1'b0;
end
end
endmodule
旋转按钮驱动程序,是基于Spartan3E板子实现的...... 需要注意的是,去抖电路的实现,这里应用了分段式分频写法,是综合速度更快。
阅读(995) | 评论(0) | 转发(0) |