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

Subversion Repositories uart_fiber

[/] [uart_fiber/] [trunk/] [Version2/] [TX_to_spdif_full.vhd] - Blame information for rev 11

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 11 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');     --value 0 to 9 (divide 50Mhz/10=5Mhz)
27
signal optic_bit:STD_LOGIC;
28
--input stage
29
signal tx_cnt : STD_LOGIC_VECTOR(6 downto 0);            --value 0-19 (divide 50Mhz/20=2.5Mhz)
30
signal tx_bit:STD_LOGIC:='1';
31
signal start_detected : STD_LOGIC:='0';
32
signal tx_half : STD_LOGIC;                                                             --1/2 bit
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);
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
 
56
        if((optic_cnt=period or optic_cnt=periodA) or
57
        ((optic_cnt=period10 or optic_cnt=period01) and optic_bit='1')) then
58
                optic_flop<=not optic_flop;             --2.5Mhz / 1.25Mhz signal  for 1 / 0
59
        end if;
60
 
61
        if(optic_cnt=period) then
62
                        optic_bit<=tx_bit;      --reload input at baud rate
63
        end if;
64
 
65
 
66
end if;
67
 
68
end process;
69
 
70
--Synchronize input (TX pin) with local clock
71
input_stage: process (iCLK,TX)
72
begin
73
if (iCLK'event and iCLK = '1') then
74
        if(start_detected='0') then
75
                if(TX='0') then
76
                        start_detected<='1';
77
                        tx_cnt<=(0=>'1',others=>'0');
78
                        bit_position<=(others=>'0');
79
                        tx_half<='0';
80
                        baud_div_cnt<=(0=>'1',others=>'0');
81
                end if;
82
        else                                                                                    --start detected=1
83
                if(baud_div_cnt=baud_div)then           --multiply with baud div
84
                        if(tx_cnt=periodA or tx_cnt=period) then                --0.5 bit time
85
                                if(tx_half='0')then
86
                                        tx_bit<=TX;                                             --sample every bit time (n+0.5 bit time from start)
87
                                        if(TX='1' and bit_position=9 and baud_div/=1)then
88
                                                start_detected<='0';--resync early if 2 x baudrate <= optic rate (in this case baudrate could be an approximation)
89
                                        end if;
90
                                elsif(tx_half='1')then
91
                                        if(bit_position/=9)then
92
                                                bit_position<=bit_position+1;
93
                                        end if;
94
                                        if(bit_position=9 and tx_bit='1') then --stop bit
95
                                                bit_position<=(others=>'0');
96
                                                if(TX='1')then
97
                                                        start_detected<='0';--resync
98
                                                end if;
99
                                        end if;
100
                                end if;
101
                                tx_half<=not tx_half;                   --next 1/2 bit
102
                        end if;--tx_cnt
103
                        if(tx_cnt=period)then
104
                                tx_cnt<=(0=>'1',others=>'0');
105
                        else
106
                                tx_cnt<=tx_cnt+1;
107
                        end if;
108
                        baud_div_cnt<=(0=>'1',others=>'0');
109
                else
110
                        baud_div_cnt<=baud_div_cnt+1;
111
                end if;--baud_div
112
        end if;--start detected
113
end if;--clk event                      
114
 
115
end process;
116
end Behavioral;
117
 

powered by: WebSVN 2.1.0

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