uart-test/top.v

30 lines
910 B
Coq
Raw Normal View History

2022-05-02 14:26:36 +00:00
// Simple test of the UART pins and clock, no CPU needed
2022-05-03 17:37:22 +00:00
module top(input clk, output ser_tx, input ser_rx, output [13:0] led);
2022-05-02 14:26:36 +00:00
//assign ser_tx = test_chars; // uncomment for a bunch of ASCII "U" characters
assign ser_tx = ser_rx; // uncomment first for serial echo
2022-05-03 17:37:22 +00:00
assign led = 'b11111111111110;
2022-05-02 14:26:36 +00:00
wire serclk;
reg test_chars;
clkdiv clock_generator (clk, serclk);
always @(posedge serclk) begin
test_chars = !test_chars;
end
endmodule
module clkdiv(input clock_in, output reg clock_out);
reg[15:0] counter=16'd0;
parameter DIVISOR = 16'd104; //set according to desired baudrate for test characters (e.g. 12,000,000 Hz / 115200 baud ~= clock divider 104)
always @(posedge clock_in) begin
counter <= counter + 16'd1;
if(counter>=(DIVISOR-1))
counter <= 16'd0;
clock_out <= (counter<DIVISOR/2)?1'b1:1'b0;
end
endmodule