Repository navigation
Expand file tree
/
Copy pathuart.v.bak
More file actions
78 lines (70 loc) · 1.93 KB
/
Copy pathuart.v.bak
File metadata and controls
78 lines (70 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// SB : Task 2 B : UART
/*
Instructions
-------------------
Students are not allowed to make any changes in the Module declaration.
This file is used to design UART Transmitter.
Recommended Quartus Version : 19.1
The submitted project file must be 19.1 compatible as the evaluation will be done on Quartus Prime Lite 19.1.
Warning: The error due to compatibility will not be entertained.
-------------------
*/
//UART Transmitter design
//Input : clk_50M : 50 MHz clock
//Output : tx : UART transmit output
//////////////////DO NOT MAKE ANY CHANGES IN MODULE//////////////////
module uart(
input clk_50M, //50 MHz clock
output tx //UART transmit output
);
//////////////////////////WRITE YOUR CODE FROM HERE////////////////////
reg [31:0] s = 32'b00111000001101110100001001010011; //01010011 01000010 00110111 00111000;
//reg [4:0] c = 5'd0;
reg tx_reg = 1;
reg baud_clk = 0;
reg [8:0] baud_counter = 9'd0;
reg [2:0]currentPacket = 0;
reg [3:0]packetState = 4'd11;//0 is start bit
//1-8 is data
//9-10 is end bit
//11-16 is not transmitting
assign tx = tx_reg;
//
//clock set according to baud rate
always @(negedge clk_50M) begin
if(baud_counter == 9'd217) begin
baud_counter <= 1;
baud_clk <= ~baud_clk;
end
else begin
baud_counter <= baud_counter + 9'd1;
end
end
// transmitting data
always @(negedge baud_clk)begin
if(currentPacket <= 'd4) begin
if(packetState == 'd0)begin
tx_reg = 1'b0;
packetState = packetState + 'd1;
end
else if(packetState <= 'd8)begin
tx_reg = s[0];
s = {1'b1, s[31:1]};
packetState = packetState + 'd1;
end
else if(packetState < 'd10) begin
tx_reg = 1'b1;
packetState = packetState + 'd1;
end
else begin
packetState = 0;
currentPacket = currentPacket + 1'b1;
end
end
else begin
tx_reg = 1'b1;
end
end
////////////////////////YOUR CODE ENDS HERE//////////////////////////
endmodule
///////////////////////////////MODULE ENDS///////////////////////////