Contact me for VHDL or Verilog projects and assignments

Sunday, July 25, 2010

Binary counter IP core in Xilinx Core Generator

      Even though a custom VHDL program can be written very easily for a counter, Xilinx Core Generator provides free Counter IP core.This can be used if you want to save time and your code need many extra  functionality. The counter can be up to 256 bits wide.
      This tutorial is for binary counter version 11.0 and I am using xilinx 12.1 webpack for this project.But without any major changes you can follow the same rules for other versions of the IP.
The counter IP can be viewed under the category , Basic elements -> Counters.I have written a tutorial earlier, on how to create a core generator project and about its simulation. If this is your first project using Core generator then I suggest you go through it first . It is available here.
Now double click on the binary counter IP, for setting the generic parameters as required.A new window similar to the one shown below will show up: 

 Now I will go through the general settings and their meaning.
1)Component name : Name of the module you want .
2)Implement using : You have two options here – DSP blocks and fabric. If you select DSP then the Core generator will use the in built DSP blocks available in the FPGA chip for making the counter. Selecting Fabric will result in only usage of available Look up table’s and flip flops. If you want the counter to be very wide enough then select the Fabric option.
3)Output width : Width of the counter output. If you choose ‘n’ then the counter can count up to the max value value 2^n-1.
4)Increment value : This is the value by which counter value gets incremented or decremented in each step.
5)Loadable : If you want the counter value to be changed at any stage make it loadable.This will introduce a std_logic and a std_logic_vector input in the IP port list.When load=1 the value available at the input std_logic_vector port will replace the counter value after some latency cycles.
6)Restrict Count : Fix a maximum count value.Use this if your final count value is not 2^n-1.
7)Count mode: You have three options – UP,DOWN and UPDOWN. They have their usual meanings with respect to a counter.
8)Sync Threshold output : If you select this then when the count value is equal to the “Threshold value” given, the std_logic signal will go high for one clock cycle.
9)Clock Enable : Enables the clock.This input should be high for the core to work properly.This is also an example of gated clock.
10)Synchronous clear : Clear the output at the clock edge when activated.       
11)Synchronous set : Set the output at the clock edge when activated.
12)Synchronous Init : Initialize the count value(output) at the clock edge when activated.Initialization value can be set by you.
13)Power-on reset init value : The count value when the module is switched ON.
14)Latency configuration : Give the latency(delay). Select “automatic” for optimal latency settings.

I have tested some of the features of the IP core. The settings I have used are given in the image shown above. The testbench code I have used is given below:
library IEEE;

entity blog_cg is
end blog_cg;

architecture Behavioral of blog_cg is

signal clk,sset,load,thresh0 : std_logic:='0';
signal l,q : std_logic_vector(2 downto 0):="000";

component counter IS
        port (
        clk: IN std_logic;
        sset: IN std_logic;

        load: IN std_logic;
        l: IN std_logic_VECTOR(2 downto 0);
        thresh0: OUT std_logic;
        q: OUT std_logic_VECTOR(2 downto 0));
END component;


UUT : counter port map(clk,sset,load,l,thresh0,q);

--Generate 2 ns clock.
clock : process begin
                clk <= '0';
                wait for 1 ns;
                clk <= '1';
                wait for 1 ns;
end process;

--Generate the required inputs for testing/simulation.
simulate : process begin
wait for 3 ns;
wait for 2 ns;
load <='1';
wait for 2 ns;
load <= '0';
end process;

end Behavioral;

Here is the simulation waveform:
If you look carefully, you can notice that there is a delay of one clock cycle in affecting the output value after applying sset and load control signals.This is the latency value the I made "automatic" in the IP core setting.If you make it manual, then this delay can be set as per your wish.

No comments:

Post a Comment

Related Posts with Thumbnails