uoficowboy
Full Member level 3
- Joined
- Apr 4, 2009
- Messages
- 169
- Helped
- 6
- Reputation
- 12
- Reaction score
- 5
- Trophy points
- 1,298
- Location
- Seattle, Wa, USA
- Activity points
- 2,964
Hi - I'm trying to learn VHDL. I'm using ISE Webpack 12.1 with ISim. I want to make a simple bit of code that divides a clock signal by two. My idea was to invert the output of entity on every rising edge of the input clock.
The code is below, and I've attached a screenshot of the simulation. The problem is that the output goes undefined every other clock cycle.
Can anybody tell me what I'm doing wrong? I suspect there are better ways to do this, but I'd really like to figure out what is wrong with this code.
Thanks!
The code is below, and I've attached a screenshot of the simulation. The problem is that the output goes undefined every other clock cycle.
Can anybody tell me what I'm doing wrong? I suspect there are better ways to do this, but I'd really like to figure out what is wrong with this code.
Thanks!
Code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity DivideClockBy2 is
Port ( Clk : in STD_LOGIC;
ClkOut : out STD_LOGIC);
end DivideClockBy2;
architecture Behavioral of DivideClockBy2 is
signal ClkOutInt : STD_LOGIC := '0';
begin
ClkOut <= ClkOutInt;
process (Clk)
begin
if (Clk'event and Clk = '1') then
ClkOutInt <= not ClkOutInt;
else
ClkOutInt <= ClkOutInt; --not sure if this is needed, but it doesn't seem to change anything
end if;
end process;
end Behavioral;