always @(posedge clk)
case(state)
RDY: begin
bitIndex <= 1'b0;
timer <= 14'b0;
txBit <= 1'b1;
if(send == 1'b1) begin
txData <= {1'b1, data, 1'b0};
state <= LOAD_BIT;
end
end
LOAD_BIT: begin
if(timer == baud_timer) begin
timer <= 14'b0;
state <= SEND_BIT;
txBit <= txData[bitIndex];
bitIndex <= bitIndex + 1'b1;
end else timer <= timer + 1'b1;
end
SEND_BIT: begin
if(bitIndex == bit_index_max) state <= RDY;
else state <= LOAD_BIT;
end
default: state <= RDY;
endcase
debounce debounce_UT(.clk(clk),
.sw(btnC), .sw_out(btnC_clr));
UART_tx_ctrl #(19200) uart(.clk(clk),
.send(uartSend), .data(uartData), .uart_tx(RsTx), .ready(uartRdy));
always @(posedge clk) begin
btnC_prev <= btnC_clr;
case(state)
btnWait: if(btnC_clr == 1'b1 && btnC_prev == 0) state
<= btnSend;
btnSend: begin
uartData <= initStr;
initStr <= initStr + 1'b1;
state <= btnWait;
end
btnSendWait: if(uartRdy) state <= btnWait;
default: state <= btnWait;
endcase
end
assign uartSend = (state == btnSend);
endmodule
3) Repeat the work in
Section 3. & Show the numbers you typed in the serial monitor
on one seven segment display unit (less than 10). (25 points)
I
combined these two sections because it seemed silly not to do them
together (Means I only have to verify a few binary numbers and then can
just look at the SSD). I reused the SSDecode module I wrote before and
added the code given to get this result:
always @ (posedge clk)
case (state)
RDY: if (rx == 1'b0) begin
state <= START;
bitIndex <= 3'b0;
end
START: if (timer == baud_timer / 2) begin
state <= WAIT;
timer <= 14'b0;
error <= 1'b0;
ready <= 1'b0;
end else timer <= timer + 1'b1;
WAIT: if (timer == baud_timer) begin
timer <= 14'b0;
if (ready) state <= RDY;
else state <= RECEIVE;
end else timer <= timer + 1'b1;
RECEIVE: begin
rxdata[bitIndex] <= rx;
bitIndex <= bitIndex + 1'b1;
if (bitIndex == 4'd8) state <= CHECK;
else state <= WAIT;
end
CHECK: if(^rxdata [7:0] == rxdata [8]) begin
ready <= 1'b1;
state <= RDY;
data <= rxdata [7:0];
parity <= rxdata[8];
end else begin
ready <= 1'b1;
data [7:0] <= 8'bx;
error <= 1'b1;
state <= RDY;
end
endcase
endmodule
module
UART_rx_top(clk, RsRx, led, seg, an);
input clk, RsRx;
output [6:0] seg;
output [3:0] an;
output reg [15:0] led = 0;
localparam RX_RDY = 2'b00, RX_WAIT =
2'b01, RX_DATARDY = 2'b10;
reg [1:0] state = RX_RDY;
wire data_ready;
wire [7:0] out;
wire parity;
wire error;
UART_rx_ctrl #(19200) RX(.clk(clk),
.rx(RsRx), .data(out), .parity(parity), .ready(data_ready),
.error(error));
SSDecode UUT(.clk(clk), .x(out [3:0]),
.g_to_a(seg), .an(an));
always @ (posedge clk) case (state)
RX_RDY: if(!data_ready) state <= RX_WAIT;
RX_WAIT: if (data_ready) state <= RX_DATARDY;
RX_DATARDY: begin
led [9:0] <= {error, parity, out};
led [15:10] <= led[15:10] + 1'b1;
state <= RX_RDY;
end
endcase
endmodule
which resulted in the following functionality.
Discussion: Easy
peasy. The Tera Term download is exceptionally sketchy and the link on
the website didn't work. I ended up downloading off of github because
it seemed the safest with the published source code but at leats one of
the other links MUST have been a virus (they were bad).