VHDL code for Counterlibrary IEEE;use IEEE.std_logic_1164.all;use IEEE.numeric_std.all; -- for the unsigned typeentity counter_example isgeneric ( WIDTH : integer := 32);port (CLK, RESET, LOAD : in std_logic;DATA : in unsigned(WIDTH-1 downto 0);Q : out unsigned(WIDTH-1 downto 0));end entity counter_example;architecture counter_example_a of counter_example issignal cnt : unsigned(WIDTH-1 downto 0);beginprocess(RESET, CLK)beginif RESET = '1' thencnt <= (others => '0');elsif rising_edge(CLK) thenif LOAD = '1' thencnt <= DATA;elsecnt <= cnt + 1;end if;end if;end process;Q <= cnt;end architecture counter_example_a;
This blog contains all the information, latest technologies in VLSI and interview questions for freshers
Friday, October 30, 2009
VHDL code for Counter
VHDL code for FlipFlops
VHDL code for FlipFlops
Some flip-flops also have Enable signals and asynchronous or synchronous Set and Reset signals:
-- template for asynchronous reset with clock enable:process(CLK, RESET)beginif RESET = '1' then -- or '0' if RESET is active low...Q <= '0';elsif rising_edge(CLK) thenif Enable = '1' then -- or '0' if Enable is active low...Q <= D;end if;end if;end process;-- template for synchronous reset with clock enable:process(CLK)beginif rising_edge(CLK) thenif RESET = '1' thenQ <= '0';elsif Enable = '1' then -- or '0' if Enable is active low...Q <= D;end if;end if;end process;
VHDL code for D-type flipflops
D-type flipflops
-- simplest DFF template (not recommended)
Q <= D when rising_edge(CLK);-- recommended DFF template:process(CLK)begin-- use falling_edge(CLK) to sample at the falling edge insteadif rising_edge(CLK) thenQ <= D;end if;end process;-- alternative DFF template:processbeginwait until rising_edge(CLK);Q <= D;end process;-- alternative template:process(CLK)beginif CLK = '1' and CLK'event --use rising edge, use "if CLK = '0' and CLK'event" instead for falling edgeQ <= D;endif;end process;
Latch Templates
Latch Templates
A transparent latch is basically one bit of memory which is updated when an enable signal is raised:
-- latch template 1:Q <= D when Enable = '1' else Q;-- latch template 2:process(D,Enable)beginif Enable = '1' thenQ <= D;end if;end process;
A SR-latch uses a set and reset signal instead:
-- SR-latch template 1:Q <= '1' when S = '1' else'0' when R = '1' else Q;-- SR-latch template 2:process(S,R)beginif S = '1' thenQ <= '1';elsif R = '1' thenQ <= '0';end if;end process;
Template 2 has an implicit "else Q <= Q;" which may be explicitly added if desired.
-- This one is a RS-latch (i.e. reset dominates)process(S,R)beginif R = '1' thenQ <= '0';elsif S = '1' thenQ <= '1';end if;end process;
Subscribe to:
Posts (Atom)
Popular Posts
-
http://www.mediafire.com/?n77dan3ovdwyoy3 http://www.mediafire.com/?8ncruxr37o1dbqb http://www.mediafire.com/?jqhvobf6j4gbp6e ...
-
Verilog code for an 8-bit shift-left register with a positive-edge clock, serial in and serial out. module shift (clk, si, so);...
-
Verilog code for a 4-bit unsigned up counter with asynchronous clear. module counter (clk, clr, q); input ...
-
seminar topics with ppts if u need any topics below mail me: bsnspkumar_484@yahoo.co.in Analysis of the Performance of DOA Algorithms in sma...
-
ECE Seminar topics These are the seminar topics based on Electronics and Communications. If u need abstracts of the below seminar topics u c...
-
// memory module `timescale 1ns/1ns module ram(wr_ad,rd_ad,wr_en,rd_en,clk,wr_dat,rd_dat); //parameter addr_width=4; //parameter depth=16; /...
-
Verilog code for single-port RAM in read-first mode. module raminfr (clk, en, we, addr, di, do); input clk; input ...
-
If inverted output of D flip-flop is connected to its input how the flip-flop behaves? Design a circuit to divide input frequency by 2...
-
Synthesizeable constructs and VHDL templates VHDL is frequently used for two different goals: simulation of electronic designs and synthesis...
-
http://www.mediafire.com/?h1bj9w1bx8kja69 http://www.mediafire.com/?yot1d4b0u344lmc http://www.mediafire.com/?hzqj1m6j91mg9td http://ww...