File: signal_generator.vhd

package info (click to toggle)
bladerf 0.2017.12~rc1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 14,620 kB
  • sloc: ansic: 50,123; vhdl: 12,873; python: 1,062; tcl: 1,060; xml: 1,017; makefile: 657; sh: 589; csh: 18; cpp: 9
file content (64 lines) | stat: -rw-r--r-- 2,082 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
library ieee;
    use ieee.std_logic_1164.all ;
    use ieee.numeric_std.all ;

entity signal_generator is
  port (
    clock           :   in      std_logic ;
    reset           :   in      std_logic ;
    enable          :   in      std_logic ;

    mode            :   in      std_logic ;

    sample_i        :   out     signed(15 downto 0) ;
    sample_q        :   out     signed(15 downto 0) ;
    sample_valid    :   buffer  std_logic
  ) ;
end entity ;

architecture arch of signal_generator is

begin

    counter : process(clock, reset)
        constant COUNT_RESET    :   natural := 256 ;
        variable count12        :   integer range -2047 to 2047 := COUNT_RESET ;
        variable count32        :   unsigned(31 downto 0) ;
    begin
        if( reset = '1' ) then
            count12 := COUNT_RESET ;
            count32 := (others =>'0') ;
            sample_i <= (others =>'0') ;
            sample_q <= (others =>'0') ;
            sample_valid <= '0' ;
        elsif( rising_edge(clock) ) then
            if( mode = '0' ) then
                sample_i <= to_signed( count12, sample_i'length) ;
                sample_q <= to_signed(-count12, sample_q'length) ;
            else
                sample_i <= signed(std_logic_vector(count32(15 downto 0))) ;
                sample_q <= signed(std_logic_vector(count32(31 downto 16))) ;
            end if ;

            if( enable = '0' ) then
                count12 := COUNT_RESET ;
                count32 := (others =>'0') ;
                sample_i <= (others =>'0') ;
                sample_q <= (others =>'0') ;
                sample_valid <= '0' ;
            else
                sample_valid <= not sample_valid ;
                if( sample_valid = '1' ) then
                    if( count12 < 2047 ) then
                        count12 := count12 + 1 ;
                    else
                        count12 := -2047 ;
                    end if ;
                    count32 := count32 + 1 ;
                end if ;
            end if ;

        end if ;
    end process ;

end architecture ;