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

Subversion Repositories uart_fiber

[/] [uart_fiber/] [trunk/] [Version3/] [TX_to_spdif_full.vhd] - Blame information for rev 16

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 chipmaker7
library IEEE;
2
use IEEE.STD_LOGIC_1164.ALL;
3
use IEEE.STD_LOGIC_ARITH.ALL;
4
use IEEE.std_logic_unsigned.all;
5
--use IEEE.NUMERIC_STD.ALL;
6
 
7
 
8
entity TX_to_spdif_full is
9
    Port ( iCLK : in  STD_LOGIC;
10
           TX : in  STD_LOGIC;
11
           optic_out : out  STD_LOGIC;
12
                          period01 : in STD_LOGIC_VECTOR(6 downto 0);
13
                          periodA : in STD_LOGIC_VECTOR(6 downto 0);
14
                          period10 : in STD_LOGIC_VECTOR(6 downto 0);
15
                          period : in STD_LOGIC_VECTOR(6 downto 0);
16
                          baud_div : in STD_LOGIC_VECTOR(6 downto 0)
17
                          );
18
end TX_to_spdif_full;
19
 
20
architecture Behavioral of TX_to_spdif_full is
21
 
22
 
23
--output flip-flop
24
signal optic_flop:STD_LOGIC:='0';
25
--optic stage 
26
signal optic_cnt : STD_LOGIC_VECTOR(6 downto 0):=(0=>'1',others=>'0');     --count 1 to Fosc/fiber bitrate
27
signal optic_bit:STD_LOGIC;
28
--input stage
29
signal tx_cnt : STD_LOGIC_VECTOR(6 downto 0);            --count 1 to Fosc/fiber bitrate
30
signal tx_bit:STD_LOGIC:='1';                                                           --bit received on TX
31
signal start_detected : STD_LOGIC:='0';
32
signal bit_position : STD_LOGIC_VECTOR(3 downto 0);--value 0-9 (bit position from start to stop)
33
--baud division
34
signal baud_div_cnt : STD_LOGIC_VECTOR(6 downto 0);--fiber bitrate / TX bitrate
35
 
36
 
37
begin
38
 
39
optic_out<=optic_flop;  --output (fiber optic)
40
 
41
--generate signal on fiber optic
42
optic_stage:process (iCLK)
43
 
44
begin
45
 
46
if (iCLK'event and iCLK = '1') then
47
 
48
        if(optic_cnt = period) then
49
                optic_cnt<=(0=>'1',others=>'0');
50
        else
51
                optic_cnt<=optic_cnt+1;
52
        end if;
53
 
54
        if((optic_cnt=periodA) or
55
        ((optic_cnt=period10 or optic_cnt=period01) and optic_bit='1')) then
56
                optic_flop<=not optic_flop;--other edge
57
        end if;
58
 
59
        if(optic_cnt=period)then
60
                optic_flop<='1';                                --rising edge
61
        end if;
62
 
63
        if(optic_cnt=period) then
64
                        optic_bit<=tx_bit;              --reload input at fiber baud rate
65
        end if;
66
 
67
 
68
end if;
69
 
70
end process;
71
 
72
--Synchronize input (TX pin) with local clock
73
input_stage: process (iCLK,TX)
74
begin
75
if (iCLK'event and iCLK = '1') then
76
        if(start_detected='0') then
77
                if(TX='0') then
78
                        start_detected<='1';
79
                        tx_cnt<=(0=>'1',others=>'0');
80
                        bit_position<=(others=>'0');
81
                        baud_div_cnt<=(0=>'1',others=>'0');
82
                end if;
83
        else                                                                                    --start detected=1
84
                if(baud_div_cnt=baud_div)then           --multiply with baud div
85
                        if(tx_cnt=periodA)then
86
                                tx_bit<=TX;                                             --sample every bit time (n+0.5 bit time from start)
87
                        elsif(tx_cnt=period10)then
88
                                if(tx_bit='1' and bit_position=9 and baud_div>2)then
89
                                        start_detected<='0';             --resync early stop length >=3/4 period
90
                                end if;
91
                        elsif(tx_cnt=period)then
92
                                if(bit_position/=9)then
93
                                        bit_position<=bit_position+1;
94
                                end if;
95
                                if(bit_position=9 and tx_bit='1') then --stop bit
96
                                        bit_position<=(others=>'0');
97
                                        if(TX='1')then
98
                                                start_detected<='0';     --resync
99
                                        end if;
100
                                end if;
101
                        end if;
102
                        if(tx_cnt=period)then
103
                                tx_cnt<=(0=>'1',others=>'0');
104
                        else
105
                                tx_cnt<=tx_cnt+1;
106
                        end if;
107
                        baud_div_cnt<=(0=>'1',others=>'0');
108
                else
109
                        baud_div_cnt<=baud_div_cnt+1;
110
                end if;--baud_div
111
        end if;--start detected
112
end if;--clk event                      
113
 
114
end process;
115
end Behavioral;
116
 

powered by: WebSVN 2.1.0

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