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

Subversion Repositories instruction_list_pipelined_processor_with_peripherals

[/] [instruction_list_pipelined_processor_with_peripherals/] [trunk/] [hdl/] [uartBrg.vhd] - Blame information for rev 3

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 maheshpalv
library IEEE;
2
use IEEE.STD_LOGIC_1164.ALL;
3
use IEEE.math_real.all;
4
use ieee.std_logic_unsigned.all;
5
 
6
entity uartBrg is
7
  generic (
8
    DIVISOR: natural := 32000000/(16*9600) -- DIVISOR = 100,000,000 / (16 x BAUD_RATE)
9
    -- 2400 -> 2604
10
    -- 9600 -> 651
11
    -- 115200 -> 54
12
    -- 1562500 -> 4
13
    -- 2083333 -> 3
14
  );
15
  port (
16
    clk: in std_logic;                         -- clock
17
    reset: in std_logic;                      -- reset
18
         outp : out std_logic
19
  );
20
end uartBrg;
21
 
22
architecture Behavioral of uartBrg is
23
 
24
  constant COUNTER_BITS : natural := integer(ceil(log2(real(DIVISOR))));
25
  signal sample: std_logic; -- 1 clk spike at 16x baud rate
26
  signal sample_counter: std_logic_vector(COUNTER_BITS-1 downto 0) := (others=> '0'); -- should fit values in 0..DIVISOR-1
27
 
28
begin
29
 
30
  -- sample signal at 16x baud rate, 1 CLK spikes
31
  sample_process: process (clk,reset) is
32
  begin
33
    if reset = '1' then
34
      sample_counter <= (others => '0');
35
      sample <= '0';
36
    elsif rising_edge(clk) then
37
      if sample_counter = DIVISOR-1 then
38
        sample <= '1';
39
        sample_counter <= (others => '0');
40
      else
41
        sample <= '0';
42
        sample_counter <= sample_counter + 1;
43
      end if;
44
    end if;
45
  end process;
46
 
47
  outp <= sample;
48
 
49
end Behavioral;

powered by: WebSVN 2.1.0

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