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

Subversion Repositories uart_fiber

[/] [uart_fiber/] [trunk/] [Version4/] [TX_to_spdif.vhd] - Blame information for rev 20

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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