]> rtime.felk.cvut.cz Git - fpga/uart.git/commitdiff
Baud generator ClockEnable added.
authorVladimir Burian <buriavl2@fel.cvut.cz>
Fri, 4 Feb 2011 10:14:31 +0000 (11:14 +0100)
committerVladimir Burian <buriavl2@fel.cvut.cz>
Fri, 4 Feb 2011 11:04:02 +0000 (12:04 +0100)
baud_gen.vhd
tb/tb_baud_gen.vhd
uart.vhd

index e778c713a4bafe609732387a12b0d1284b6ca017..81dfa5cab9fa14f23dbfcbd0bdac363e08888ffb 100644 (file)
@@ -11,16 +11,22 @@ use ieee.std_logic_unsigned.all;
 --
 -- The divided clock signal has a duty cycle of 50%.
 --
--- The reset input signal is asynchronous. When held active, the output is 0.
--- When released, the output starts a new period and goes high with the next 
--- rising edge of the input clock signal.
+-- Change of 'scale' doesn't affect current half-period.
+--
+-- The reset input signal is asynchronous. All others are synchronous to clk
+-- rising egde. In default state (when stopped), output is low. When CE goes
+-- high, 'clk_baud' goes high with next clock rising edge. When CE goes low,
+-- eventual high half-period is finished and then generator stops with low
+-- output.
 --
 --             _   _   _   _   _   _   _   _   _   _   _   _
 --  CLK      _| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_
---                        _________
---  RESET    ____________|         |__________________________
---             ___     __              ___     ___     ___ 
---  CLK_BAUD _|   |___|  |____________|   |___|   |___|   |___
+--                            _____
+--  RESET    ________________|     |__________________________
+--                _____________________________
+--  CE       ____|                             |______________
+--                 ___     __          ___     ___    
+--  CLK_BAUD _____|   |___|  |________|   |___|   |___________
 --
 --------------------------------------------------------------------------------
 
@@ -30,6 +36,7 @@ entity baud_gen is
   );
   port (
     clk      : in  std_logic;
+    ce       : in  std_logic;
     reset    : in  std_logic;
     scale    : in  std_logic_vector (SCALE_WIDTH-1 downto 0);
     clk_baud : out std_logic
@@ -54,13 +61,18 @@ begin
       clk_baud_s <= '0';
       
     elsif (rising_edge(clk)) then
-      if (counter = 0) then
-        counter <= scale;
-        clk_baud_s <= not clk_baud_s;
-        
+      if (clk_baud_s = '0' and ce = '0') then
+        counter <= (others => '0');
+
       else
-        counter <= counter - 1;
+        if (counter = 0) then
+          counter    <= scale;
+          clk_baud_s <= not clk_baud_s;
+
+        else
+          counter <= counter - 1;
 
+        end if;
       end if;
     end if;
   end process;
index 7981c32a371889f880d63696ed50bb932e01963a..3f85beed0c21f45c59b67da1318ac77697a8251e 100644 (file)
@@ -12,6 +12,7 @@ architecture testbench of tb_baud_gen is
   component baud_gen is
     port (
       clk      : in  std_logic;
+      ce       : in  std_logic;
       reset    : in  std_logic;
       scale    : in  std_logic_vector (15 downto 0);
       clk_baud : out std_logic
@@ -19,6 +20,7 @@ architecture testbench of tb_baud_gen is
   end component;
   
   signal clk   : std_logic;
+  signal ce    : std_logic;
   signal reset : std_logic;
   
   constant period : time := 2 us;
@@ -32,6 +34,7 @@ architecture testbench of tb_baud_gen is
 begin
   UUT : baud_gen port map (
     clk      => clk,
+    ce       => ce,
     reset    => reset,
     scale    => scale,
     clk_baud => clk_baud
@@ -54,10 +57,18 @@ begin
   process
   begin
     reset <= '0';
+    ce    <= '0';
+    
     wait for 1.2 * period;
     reset <= '1';
     wait for 3 * period;
     reset <= '0';
+
+    wait for 2 * period;
+    ce <= '1';
+    wait for 7 * period;
+    ce <= '0';
+
     wait;
   end process;
 
index a5999089a11135173158276724b9db9ee5b7e5f8..cddd6c86f23984958f5aa143d2861db09486ab44 100644 (file)
--- a/uart.vhd
+++ b/uart.vhd
@@ -88,6 +88,7 @@ architecture dataflow of uart is
   component baud_gen is
     port (
       clk      : in  std_logic;
+      ce       : in  std_logic;
       reset    : in  std_logic;
       scale    : in std_logic_vector (15 downto 0);
       clk_baud : out  std_logic
@@ -172,6 +173,7 @@ begin
 
   baud_gen_0 : baud_gen port map (
     clk      => mclk,
+    ce       => '1',
     reset    => puc,
     scale    => "0000000000000000",
     clk_baud => tx_clk