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

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [rtl/] [gnsslib/] [sync/] [greycnt.vhd] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 sergeykhbr
library ieee;
2
    use ieee.std_logic_1164.all;
3
    use ieee.std_logic_unsigned.all;
4
    use ieee.std_logic_arith.all;
5
 
6
entity GrayCounter is
7
    generic (
8
        generic_width : integer := 4
9
    );
10
    port (                            --'Gray' code count output.
11
        i_nrst : in  std_logic;       -- Count reset.
12
        i_clk  : in  std_logic;       -- Input clock
13
        i_ena  : in  std_logic;       -- Count enable.
14
        o_cnt  : out std_logic_vector (generic_width-1 downto 0)
15
    );
16
end entity;
17
 
18
architecture rtl of GrayCounter is
19
    type regs is record
20
        bin_cnt  : std_logic_vector (generic_width-1 downto 0);
21
        grey_cnt : std_logic_vector (generic_width-1 downto 0);
22
    end record;
23
    signal r : regs;
24
begin
25
    proc0 : process (i_clk) begin
26
        if (rising_edge(i_clk)) then
27
            if i_nrst = '0' then
28
                r.bin_cnt  <= conv_std_logic_vector(1, generic_width);
29
                r.grey_cnt <= (others=>'0');
30
            elsif i_ena = '1' then
31
                r.bin_cnt  <= r.bin_cnt + 1;
32
                r.grey_cnt <= r.bin_cnt(generic_width-1) &
33
                                 (r.bin_cnt(generic_width-2 downto 0) xor
34
                                  r.bin_cnt(generic_width-1 downto 1));
35
            end if;
36
        end if;
37
    end process;
38
 
39
    o_cnt <= r.grey_cnt;
40
 
41
end architecture;

powered by: WebSVN 2.1.0

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