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

Subversion Repositories uart_block

[/] [uart_block/] [trunk/] [hdl/] [iseProject/] [serial_receiver.vhd] - Blame information for rev 10

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 leonardoar
--! Data receiver
2
--! http://www.fpga4fun.com/SerialInterface.html
3
library IEEE;
4
use IEEE.STD_LOGIC_1164.ALL;
5
 
6
--! Use CPU Definitions package
7
use work.pkgDefinitions.all;
8
 
9
entity serial_receiver is
10
    Port (
11
                          rst : in STD_LOGIC;
12
                          baudClk : in  STD_LOGIC;
13
                          baudOverSampleClk : in  STD_LOGIC;
14
           serial_in : in  STD_LOGIC;
15
           data_ready : out  STD_LOGIC;
16
           data_byte : out  STD_LOGIC_VECTOR ((nBits-1) downto 0));
17
end serial_receiver;
18
 
19
architecture Behavioral of serial_receiver is
20
signal current_s,next_s: rxStates;
21
signal filterRx : rxFilterStates;
22
signal syncDetected : std_logic;
23
 
24
begin
25
        -- First we need to oversample(8x baud rate) out serial channel to syncronize with the PC
26 4 leonardoar
        process (rst, baudOverSampleClk, serial_in, current_s)
27 2 leonardoar
        begin
28
                if rst = '1' then
29
                        filterRx <= s0;
30
                        syncDetected <= '0';
31
                elsif rising_edge(baudOverSampleClk) then
32
                        case filterRx is
33
                                when s0 =>
34
                                        syncDetected <= '0';
35
                                        -- Spike down detected, verify if it's valid for at least 3 cycles
36
                                        if serial_in = '0' then
37
                                                filterRx <= s1;
38
                                        else
39
                                                filterRx <= s0;
40
                                        end if;
41
 
42
                                when s1 =>
43
                                        syncDetected <= '0';
44
                                        if serial_in = '0' then
45
                                                filterRx <= s2;
46
                                                syncDetected <= '0';
47
                                        else
48
                                                filterRx <= s0;
49
                                        end if;
50
 
51 4 leonardoar
                                when s2 =>
52
                                        syncDetected <= '0';
53
                                        if serial_in = '0' then
54
                                                filterRx <= s3;
55
                                                syncDetected <= '0';
56
                                        else
57
                                                filterRx <= s0;
58
                                        end if;
59
 
60
                                when s3 =>
61 2 leonardoar
                                        -- Real Beginning of start bit detected 
62
                                        if serial_in = '0' then
63 4 leonardoar
                                                filterRx <= s3;
64
                                                syncDetected <= '1';
65 2 leonardoar
                                        end if;
66 4 leonardoar
 
67
                                        -- Reset out sync detector when finished to receive a byte
68
                                        if current_s = rx_stop then
69
                                                filterRx <= s0;
70
                                        end if;
71 2 leonardoar
                        end case;
72
                end if;
73
        end process;
74
 
75
        -- Next state logic for rx Receiver (On this case our reset is the syncDetected signal
76
        process (syncDetected, baudClk, serial_in)
77
        begin
78
                if syncDetected = '0' then
79
                        current_s <= rx_idle;
80
                elsif rising_edge(baudClk) then
81
                        current_s <= next_s;
82
                end if;
83
        end process;
84
 
85
        -- Process to handle the serial receive
86
        process (current_s)
87 4 leonardoar
        variable byteReceived : STD_LOGIC_VECTOR ((nBits-1) downto 0);
88 2 leonardoar
        begin
89
                case current_s is
90
                        when rx_idle =>
91
                                data_ready <= '0';
92 4 leonardoar
                                byteReceived := (others => 'Z');
93 2 leonardoar
                                next_s <=  bit0;
94
 
95
                        when bit0 =>
96
                                data_ready <= '0';
97 4 leonardoar
                                byteReceived(0) := serial_in;
98 2 leonardoar
                                next_s <=  bit1;
99
 
100
                        when bit1 =>
101
                                data_ready <= '0';
102 4 leonardoar
                                byteReceived(1) := serial_in;
103 2 leonardoar
                                next_s <=  bit2;
104
 
105
                        when bit2 =>
106
                                data_ready <= '0';
107 4 leonardoar
                                byteReceived(2) := serial_in;
108 2 leonardoar
                                next_s <=  bit3;
109
 
110
                        when bit3 =>
111
                                data_ready <= '0';
112 4 leonardoar
                                byteReceived(3) := serial_in;
113 2 leonardoar
                                next_s <=  bit4;
114
 
115
                        when bit4 =>
116
                                data_ready <= '0';
117 4 leonardoar
                                byteReceived(4) := serial_in;
118 2 leonardoar
                                next_s <=  bit5;
119
 
120
                        when bit5 =>
121
                                data_ready <= '0';
122 4 leonardoar
                                byteReceived(5) := serial_in;
123 2 leonardoar
                                next_s <=  bit6;
124
 
125
                        when bit6 =>
126
                                data_ready <= '0';
127 4 leonardoar
                                byteReceived(6) := serial_in;
128 2 leonardoar
                                next_s <=  bit7;
129
 
130
                        when bit7 =>
131
                                data_ready <= '0';
132 10 leonardoar
                                byteReceived(7) := serial_in;
133
                                data_byte <= byteReceived;
134 2 leonardoar
                                next_s <=  rx_stop;
135
 
136
                        when rx_stop =>
137 10 leonardoar
                                data_ready <= '1';
138 4 leonardoar
                                next_s <=  rx_stop;
139
                end case;
140 2 leonardoar
 
141
        end process;
142
 
143
end Behavioral;
144
 

powered by: WebSVN 2.1.0

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