You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
2.8 KiB
Coq

5 months ago
module timer_decoder(
input wire sys_clk ,
input wire sys_rst_n ,
input wire [1: 0] dev_id ,
input wire [3: 0] opcode ,
input wire [4: 0] hour ,
input wire [5: 0] min ,
input wire [5: 0] sec ,
output reg [7: 0] seg_led ,
output reg [5: 0] sel_led
);
parameter FPS = 10'd1000;//20us
reg [9: 0] cnt_fps;
wire add_cnt_fps;
wire end_cnt_fps;
reg start_flag;
reg [3: 0] value ;
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
start_flag <= 1'b0;
end
else if((dev_id == 2'd2) && (opcode == 4'b0010))begin
start_flag <= 1'b1;
end
else if((dev_id == 2'd2) && (opcode == 4'b0001))begin
start_flag <= 1'b0;
end
else begin
start_flag <= start_flag;
end
end
//20us
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
cnt_fps <= 10'd0;
end
else if((dev_id == 2'd2) && (opcode == 4'b0001))begin
cnt_fps <= 10'd0;
end
else if(add_cnt_fps)begin
if(end_cnt_fps)begin
cnt_fps <= 10'd0;
end
else begin
cnt_fps <= cnt_fps + 1'd1;
end
end
else begin
cnt_fps <= cnt_fps;
end
end
assign add_cnt_fps = start_flag;
assign end_cnt_fps = add_cnt_fps && (cnt_fps == FPS - 1'd1);
//sel_led
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
sel_led <= 6'b111_111;
end
else if(dev_id == 2'd2 && opcode == 4'b0001)begin
sel_led <= 6'b111_111;
end
else if(dev_id == 2'd2 && opcode == 4'b0010)begin
sel_led <= 6'b111_110;
end
else if(cnt_fps == FPS - 1'd1)begin
sel_led <= {sel_led[4: 0], sel_led[5]};//
end
else begin
sel_led <= sel_led;//
end
end
always @(*)begin
case(sel_led)
6'b111_110: value = hour / 10;
6'b111_101: value = hour % 10;
6'b111_011: value = min / 10 ;
6'b110_111: value = min % 10 ;
6'b101_111: value = sec / 10 ;
6'b011_111: value = sec % 10 ;
default : value = 0 ;
endcase
end
always @(*)begin
case(value)
4'd0 : seg_led = 8'b1100_0000;
4'd1 : seg_led = 8'b1111_1001;
4'd2 : seg_led = 8'b1010_0100;
4'd3 : seg_led = 8'b1011_0000;
4'd4 : seg_led = 8'b1001_1001;
4'd5 : seg_led = 8'b1001_0010;
4'd6 : seg_led = 8'b1000_0010;
4'd7 : seg_led = 8'b1111_1000;
4'd8 : seg_led = 8'b1000_0000;
4'd9 : seg_led = 8'b1001_0000;
default : seg_led = 8'b1100_0000;
endcase
end
endmodule