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

Subversion Repositories uart_fiber

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 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
                          );
13
end TX_to_spdif_full;
14
 
15
architecture Behavioral of TX_to_spdif_full is
16
 
17
 
18
--output flip-flop
19
signal optic_flop:STD_LOGIC:='0';
20
--optic stage 
21
signal optic_cnt : STD_LOGIC_VECTOR(3 downto 0); --value 0 to 9 (divide 50Mhz/10=5Mhz)
22
signal half0 : STD_LOGIC;
23
signal half1 : STD_LOGIC;
24
signal optic_bit:STD_LOGIC;
25
--input stage
26
signal tx_cnt : STD_LOGIC_VECTOR(4 downto 0);            --value 0-19 (divide 50Mhz/20=2.5Mhz)
27
signal tx_bit:STD_LOGIC:='1';
28
signal start_detected : STD_LOGIC:='0';
29
signal tx_half : STD_LOGIC;                                                             --1/2 bit
30
signal bit_position : STD_LOGIC_VECTOR(3 downto 0);--value 0-9 (bit position from start to stop)
31
 
32
 
33
 
34
 
35
 
36
 
37
begin
38
 
39
 
40
optic_out<=optic_flop;  --output (fiber optic)
41
 
42
--generate signal on fiber optic
43
optic_stage:process (iCLK)
44
begin
45
 
46
if (iCLK'event and iCLK = '1') then
47
 
48
        if(optic_cnt=9) then                    --divide 50Mhz / 10 = 5 Mhz 
49
                half0<=not half0;
50
                if(half0='1') then
51
                        half1<=not half1;
52
                end if;
53
                if(optic_bit='1' or half0='0') then
54
                        optic_flop<=not optic_flop;             --2.5Mhz / 1.25Mhz signal  for 1 / 0
55
                end if;
56
                if((half0='1') and (half1='1'))then
57
                        optic_bit<=tx_bit;      --reload input at 1.25Mb/s rate
58
--                      optic_flop<=tx_bit;
59
 
60
                end if;
61
                optic_cnt<=(others=>'0');
62
        else
63
                optic_cnt<=optic_cnt+1;
64
        end if;
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
 
75
 
76
 
77
        if(start_detected='0') then
78
                if(TX='0') then
79
                        start_detected<='1';
80
                        tx_cnt<=(others=>'0');
81
                        bit_position<=(others=>'0');
82
                        tx_half<='0';
83
                end if;
84
        else                                                                                    --start detected=1
85
                if(tx_cnt=19) then                                      --0.5 bit time
86
                        if(tx_half='0')then
87
                                tx_bit<=TX;                                             --sample every bit time (n+0.5 bit time from start)
88
                        elsif(tx_half='1')then
89
                                if(bit_position/=9)then
90
                                        bit_position<=bit_position+1;
91
                                end if;
92
                                if(bit_position=9 and tx_bit='1') then --stop bit
93
                                        bit_position<=(others=>'0');
94
                                        if(TX='1')then
95
                                                start_detected<='0';--resync
96
                                        end if;
97
                                end if;
98
                        end if;
99
                        tx_half<=not tx_half;                   --next 1/2 bit
100
                        tx_cnt<=(others=>'0');
101
                else
102
                        tx_cnt<=tx_cnt+1;
103
                end if;
104
        end if;--start detected
105
end if;--clk event                      
106
 
107
end process;
108
end Behavioral;
109
 

powered by: WebSVN 2.1.0

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