I'm a analogue engineer trying to learn VHDL for a project i have. the project is to count the rising edge of a input signal and prescale the counts to a smaller number. for example if there are 8 counts on the input then 1 count will be outputted. the prescale value can be user changed. i have managed to work the prescale part out but at pressent the output will constantly go high .
what i am trying to do is once the prescale count is = to the user selected value then a 1us pulse is outputted rather then the constant logic high.
i have a 50 MHz clk, so the output needs to stay high for 50 clock cycles, however i am unsure how to to do this.
i am using a DE0 development board that has debounced switches so there is no need for a debounce circuit.
any help would be great
what i am trying to do is once the prescale count is = to the user selected value then a 1us pulse is outputted rather then the constant logic high.
i have a 50 MHz clk, so the output needs to stay high for 50 clock cycles, however i am unsure how to to do this.
i am using a DE0 development board that has debounced switches so there is no need for a debounce circuit.
any help would be great
Rich (BB code):
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity counter is
port (
pushbutton: in std_logic;
SW: in std_logic_vector(7 downto 0); -- user select switches
RESET: in std_logic;
OUTPUT: out std_logic;
LEDS: out std_logic_vector(8 downto 0) -- un used leds
);
end counter;
architecture Behavioral of counter is
signal COUNTER: std_logic;
signal PRESCALER: std_logic_vector(7 downto 0);
signal SWITCH: std_logic_vector(7 downto 0);
begin
CounterProcess: process(RESET, pushbutton)
begin
if rising_edge(pushbutton) then
if RESET = '0' then
PRESCALER <= (others => '0');
COUNTER <= '0';
else
if PRESCALER < SWITCH - 1 then
PRESCALER <= PRESCALER + 1;
else
PRESCALER <= (others => '0');
COUNTER <= '1';
end if;
end if;
end if;
end process;
LEDS <= (others => '0'); -- Turn off all unsed LEDs
SWITCH <= SW; -- Asign switch value into a signal
OUTPUT <= COUNTER;
end Behavioral;