OpenCores
URL https://opencores.org/ocsvn/othellogame/othellogame/trunk

Subversion Repositories othellogame

[/] [othellogame/] [trunk/] [rtl/] [rs232.v] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 marius_mtm
`timescale 1ns / 1ps
2
//////////////////////////////////////////////////////////////////////////////////
3
// Company: 
4
// Engineer: 
5
// 
6
// Create Date:    11:20:21 05/08/2009 
7
// Design Name: 
8
// Module Name:    rs232 
9
// Project Name: 
10
// Target Devices: 
11
// Tool versions: 
12
// Description: 
13
//
14
// Dependencies: 
15
//
16
// Revision: 
17
// Revision 0.01 - File Created
18
// Additional Comments: 
19
//   original source fpga4fun.com
20
//
21
//////////////////////////////////////////////////////////////////////////////////
22
module rs232(
23
                clk,
24
                RST,
25
                TxD_start,
26
                TxD_data,
27
                TxD,
28
                TxD_busy
29
    );
30
input clk, TxD_start;
31
input [7:0] TxD_data;
32
input RST;
33
output TxD, TxD_busy;
34
 
35
 
36
parameter ClkFrequency = 50000000; // 50MHz
37
parameter Baud = 115200;
38
parameter BaudGeneratorAccWidth = 17;
39
parameter BaudGeneratorInc = ((Baud<<(BaudGeneratorAccWidth-4))+(ClkFrequency>>5))/(ClkFrequency>>4);
40
//(Baud<<BaudGeneratorAccWidth)/ClkFrequency;
41
//parameter RegisterInputData = 1;      // in RegisterInputData mode, the input doesn't have to stay valid while the character is been transmitted
42
 
43
 
44
reg [BaudGeneratorAccWidth:0] BaudGeneratorAcc;
45
 
46
/*always @(posedge clk)
47
  BaudGeneratorAcc <= BaudGeneratorAcc[BaudGeneratorAccWidth-1:0] + BaudGeneratorInc;
48
*/
49
always @(posedge clk)
50
     if(TxD_busy)
51
              BaudGeneratorAcc <= BaudGeneratorAcc[BaudGeneratorAccWidth-1:0] + BaudGeneratorInc;
52
 
53
 
54
wire BaudTick = BaudGeneratorAcc[BaudGeneratorAccWidth];
55
 
56
// Transmitter state machine
57
reg [3:0] state;
58
wire TxD_ready = (state==0);
59
assign TxD_busy = ~TxD_ready;
60
 
61
//reg [7:0] TxD_dataReg_d;
62
reg [7:0] TxD_dataReg_q;
63
 
64
always @(posedge clk)
65
        if ( RST ) begin
66
                TxD_dataReg_q <= 8'b0;
67
        end
68
        else
69
        if(TxD_ready & TxD_start) begin
70
                TxD_dataReg_q <= TxD_data;
71
        end
72
        else begin
73
                TxD_dataReg_q <= TxD_dataReg_q;
74
        end
75
 
76
 
77
wire [7:0] TxD_dataD = TxD_dataReg_q;
78
 
79
always @(posedge clk)
80
case(state)
81
        4'b0000: if(TxD_start) state <= 4'b0001;
82
        4'b0001: if(BaudTick) state <= 4'b0100;
83
        4'b0100: if(BaudTick) state <= 4'b1000;  // start
84
        4'b1000: if(BaudTick) state <= 4'b1001;  // bit 0
85
        4'b1001: if(BaudTick) state <= 4'b1010;  // bit 1
86
        4'b1010: if(BaudTick) state <= 4'b1011;  // bit 2
87
        4'b1011: if(BaudTick) state <= 4'b1100;  // bit 3
88
        4'b1100: if(BaudTick) state <= 4'b1101;  // bit 4
89
        4'b1101: if(BaudTick) state <= 4'b1110;  // bit 5
90
        4'b1110: if(BaudTick) state <= 4'b1111;  // bit 6
91
        4'b1111: if(BaudTick) state <= 4'b0010;  // bit 7
92
        4'b0010: if(BaudTick) state <= 4'b0011;  // stop1
93
        4'b0011: if(BaudTick) state <= 4'b0000;  // stop2
94
        default: if(BaudTick) state <= 4'b0000;
95
endcase
96
 
97
// Output mux
98
reg muxbit;
99
always @( * )
100
case(state[2:0])
101
        3'd0: muxbit <= TxD_dataD[0];
102
        3'd1: muxbit <= TxD_dataD[1];
103
        3'd2: muxbit <= TxD_dataD[2];
104
        3'd3: muxbit <= TxD_dataD[3];
105
        3'd4: muxbit <= TxD_dataD[4];
106
        3'd5: muxbit <= TxD_dataD[5];
107
        3'd6: muxbit <= TxD_dataD[6];
108
        3'd7: muxbit <= TxD_dataD[7];
109
endcase
110
 
111
// Put together the start, data and stop bits
112
reg TxD;
113
always @(posedge clk)
114
        TxD <= (state<4) | (state[3] & muxbit);  // register the output to make it glitch free
115
 
116
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.