A
Andrew Turner
Guest
I am fairly new to VHDL and recently bought a Spartan 3 kit from Digilent
(S3Board with an XC3S1000-4). I found I was having problems with the some
of the outputs occasinally not having the values I expected. So I made the
simplest design I could think of that when synthesised has the same
problem, yet simulates correctly.
The design below is designed to be connected to a push button switch and
LED array (and clock) and to count (in binary) on the LEDs each time the
button is presed. To do this there is a delay counter to overcome contact
bounce and to make sure you have to press the button again before it will
increment.
I expect the values displayed on the LED array to be one behind the value
stored in cntr and this is usually the case. However, sometimes when you
press the button one bit of the LED array may not update, but when you
press the button again it (usually) goes to the next value OK.
eg (LED array output after each button press)
00000000
00000001
00000011 <-- bit 0 did not go low
00000011
00000100
or
00000000
00000001
00000010
00000010 <-- bit 0 did not go high
00000100
There does not seem to be any particular bit that is more prone to this
than any other, and I really have no idea what is causing this. I am using
ISE Webpack 7.1.03i (the latest version) and my design generates no
warnings/errors and the maximum clockspeed is far above the one I am
actually using.
Design:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.numeric_std.all;
entity counter is
port (
clk : in std_logic;
button : in std_logic;
leds : out std_logic_vector(7 downto 0)
);
end counter;
architecture behav of counter is
signal cntr : std_logic_vector(7 downto 0) := x"00";
signal delay : natural range 0 to 5000000 := 0;
begin
process(clk)
begin
if (rising_edge(clk)) then
if (button='0' and delay/=0) then
delay <= delay - 1;
elsif (button='1' and delay=0) then
delay <= 5000000;
cntr <= std_logic_vector(to_unsigned
(to_integer(unsigned(cntr))+1,8));
leds <= cntr;
end if;
end if;
end process;
end behav;
I would greatly appreciate any help as I don't know whether I don't fully
understand VHDL or if there is some other cause of this problem.
Thanks in advance,
Andrew
(S3Board with an XC3S1000-4). I found I was having problems with the some
of the outputs occasinally not having the values I expected. So I made the
simplest design I could think of that when synthesised has the same
problem, yet simulates correctly.
The design below is designed to be connected to a push button switch and
LED array (and clock) and to count (in binary) on the LEDs each time the
button is presed. To do this there is a delay counter to overcome contact
bounce and to make sure you have to press the button again before it will
increment.
I expect the values displayed on the LED array to be one behind the value
stored in cntr and this is usually the case. However, sometimes when you
press the button one bit of the LED array may not update, but when you
press the button again it (usually) goes to the next value OK.
eg (LED array output after each button press)
00000000
00000001
00000011 <-- bit 0 did not go low
00000011
00000100
or
00000000
00000001
00000010
00000010 <-- bit 0 did not go high
00000100
There does not seem to be any particular bit that is more prone to this
than any other, and I really have no idea what is causing this. I am using
ISE Webpack 7.1.03i (the latest version) and my design generates no
warnings/errors and the maximum clockspeed is far above the one I am
actually using.
Design:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.numeric_std.all;
entity counter is
port (
clk : in std_logic;
button : in std_logic;
leds : out std_logic_vector(7 downto 0)
);
end counter;
architecture behav of counter is
signal cntr : std_logic_vector(7 downto 0) := x"00";
signal delay : natural range 0 to 5000000 := 0;
begin
process(clk)
begin
if (rising_edge(clk)) then
if (button='0' and delay/=0) then
delay <= delay - 1;
elsif (button='1' and delay=0) then
delay <= 5000000;
cntr <= std_logic_vector(to_unsigned
(to_integer(unsigned(cntr))+1,8));
leds <= cntr;
end if;
end if;
end process;
end behav;
I would greatly appreciate any help as I don't know whether I don't fully
understand VHDL or if there is some other cause of this problem.
Thanks in advance,
Andrew