library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; LIBRARY lpm; USE lpm.lpm_components.ALL; --used in calculating the wind speed, this counter increments forwards entity bigcounter is generic(Width: positive:= 4 ); port( clock: in std_logic; clk_en: in std_logic; cnt_en: in std_logic; sclr: in std_logic; q1: OUT STD_LOGIC_VECTOR(Width -1 DOWNTO 0); tq10: OUT STD_LOGIC_VECTOR(Width -1 DOWNTO 0); hq100: OUT STD_LOGIC_VECTOR(Width -1 DOWNTO 0) ); end bigcounter; architecture calculation of bigcounter is --uses the decadecounter function to increment component decadecount is generic (Width : POSITIVE := 4; MODULUS : STRING := "10"); port( clock: IN STD_LOGIC; clk_en: IN STD_LOGIC; cnt_en: IN STD_LOGIC; sclr: IN STD_LOGIC; Carryout: out STD_LOGIC; q: OUT STD_LOGIC_VECTOR(Width -1 DOWNTO 0)); end component; signal carry10ready: std_logic; signal carry100ready: std_logic; signal carry10, carry100, carryextra: std_logic; begin --call three times the decade counter, count by ones, tens and hundreds --by counting in decades rather than having one large counter, the --chip can work more efficiently ones: decadecount generic map (Width=> Width, MODULUS => "10") port map ( clock=> clock, clk_en => clk_en, cnt_en => cnt_en, sclr=> sclr, carryout => carry10, q => q1); carry10ready <= carry10 and cnt_en; tens: decadecount generic map (Width=> Width, MODULUS => "10") port map ( clock=> clock, clk_en => clk_en, cnt_en => carry10ready, sclr=> sclr, carryout => carry100, q => tq10); carry100ready <= carry10 and carry100 and cnt_en; hundreds: decadecount generic map (Width=> Width, MODULUS => "10") port map ( clock=> clock, clk_en => clk_en, cnt_en => carry100ready, sclr=> sclr, carryout => carryextra, q => hq100); end calculation;