Project

General

Profile

RE: uPP receiving problem » cloccodivider.vhd

Silvano Bertoldo, 07/21/2014 11:34 AM

 
1
----------------------------------------------------------------------------------
2
-- Company: 
3
-- Engineer: 
4
-- 
5
-- Create Date:    10:34:38 04/02/2014 
6
-- Design Name: 
7
-- Module Name:    cloccodivider - Behavioral 
8
-- Project Name: 
9
-- Target Devices: 
10
-- Tool versions: 
11
-- Description: 
12
--
13
-- Dependencies: 
14
--
15
-- Revision: 
16
-- Revision 0.01 - File Created
17
-- Additional Comments: 
18
--
19
----------------------------------------------------------------------------------
20
library IEEE;
21
use IEEE.STD_LOGIC_1164.ALL;
22

    
23
-- Uncomment the following library declaration if using
24
-- arithmetic functions with Signed or Unsigned values
25
--use IEEE.NUMERIC_STD.ALL;
26

    
27
-- Uncomment the following library declaration if instantiating
28
-- any Xilinx primitives in this code.
29
--library UNISIM;
30
--use UNISIM.VComponents.all;
31

    
32
library IEEE;
33
use IEEE.STD_LOGIC_1164.all;
34

    
35
-- Uncomment the following library declaration if using
36
-- arithmetic functions with Signed or Unsigned values
37
use IEEE.NUMERIC_STD.all;
38

    
39
entity scale_clock is
40
  port (
41
    clk_20Mhz : in  std_logic;
42
    rst       : in  std_logic;
43
	 clk_1Hz	  : out std_logic;
44
	 clk_2Hz   : out std_logic
45
	 );
46
end scale_clock;
47

    
48
architecture Behavioral of scale_clock is
49

    
50
 signal prescaler : integer range 0 to 1500000:=0;
51
 signal pre_scaler : integer range 0 to 3000000:=0;
52
  
53
  signal clk_2Hz_i : std_logic;
54
  signal clk_1Hz_i : std_logic;
55
begin
56

    
57
  gen_clk_2Hz : process (clk_20Mhz, rst)
58
  begin  -- process gen_clk
59
    if rst = '1' then
60
      clk_2Hz_i   <= '0';
61
      prescaler   <=  0;
62
    elsif rising_edge(clk_20Mhz) then   -- rising clock edge
63
      if prescaler = 1500000 then     -- 1500000 
64
        prescaler <= 0;
65
        clk_2Hz_i   <= not clk_2Hz_i;
66
      else
67
        prescaler <= prescaler + 1;
68
      end if;
69
    end if;
70
  end process gen_clk_2Hz;
71
  
72
  gen_clk_1Hz : process (clk_20Mhz, rst)
73
  begin  -- process gen_clk
74
    if rst = '1' then
75
      clk_1Hz_i   <= '0';
76
      pre_scaler   <=  0;
77
    elsif rising_edge(clk_20Mhz) then   -- rising clock edge
78
      if pre_scaler = 3000000 then     -- 3000000
79
        pre_scaler <= 0;
80
        clk_1Hz_i   <= not clk_1Hz_i;
81
      else
82
        pre_scaler <= pre_scaler + 1;
83
      end if;
84
    end if;
85
  end process gen_clk_1Hz;
86

    
87
clk_2Hz <= clk_2Hz_i;
88
clk_1Hz <= clk_1Hz_i;
89

    
90
end Behavioral;
(1-1/6) Go to top
Add picture from clipboard (Maximum size: 1 GB)