Self adjust the speed of the ball

This commit is contained in:
eeeXun 2021-01-14 14:26:15 +08:00
parent 83d7b2205f
commit b5f7082311

View File

@ -8,7 +8,8 @@ module FPGA_FINAL(
input show_two_row, input show_two_row,
output testLED, output testLED,
output reg a,b,c,d,e,f,g, output reg a,b,c,d,e,f,g,
output reg [0:3] COM output reg [0:3] COM,
input highSpeed
); );
reg [7:0]blockFirst = 8'b11111111; reg [7:0]blockFirst = 8'b11111111;
@ -65,7 +66,7 @@ module FPGA_FINAL(
// 開始所有除頻器 // 開始所有除頻器
divfreq F(CLK, divclk); divfreq F(CLK, divclk);
buttondivfreq BT(CLK, buttonclk); buttondivfreq BT(CLK, highSpeed, buttonclk);
@ -517,16 +518,29 @@ endmodule
// 按鈕用的除頻器 // 按鈕用的除頻器
module buttondivfreq(input CLK, output reg CLK_div); module buttondivfreq(input CLK, highSpeed, output reg CLK_div);
reg[24:0] Count; reg[24:0] Count;
always @(posedge CLK) always @(posedge CLK)
begin begin
if(Count>2500000) // 20 Hz if(highSpeed == 0)
begin begin
Count <= 25'b0; if(Count>2500000) // 20 Hz
CLK_div <= ~CLK_div; begin
end Count <= 25'b0;
CLK_div <= ~CLK_div;
end
else
Count <= Count + 1'b1;
end
else else
Count <= Count + 1'b1; begin
if(Count>1000000) // 50 Hz
begin
Count <= 25'b0;
CLK_div <= ~CLK_div;
end
else
Count <= Count + 1'b1;
end
end end
endmodule endmodule