hassan590
Newbie level 3
- Joined
- Sep 17, 2013
- Messages
- 3
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 37
I am new in VHDL. I wrote a code of decrement counter in which counter picks integer from the array and counts it down to zero and increments the check output. I want you guys to verify if the code is logically correct. If yes then how can i test it using the test bench.
Code:
entity counter is
port(clk :in bit;
check : out integer);
end counter;
architecture imp of counter is
type my_array is array(natural range<>) of integer;
constant set:my_array(1 to 5):= (2,4,6,8,10);--array of 5 integers
signal count:integer:=set(1); --initiating count with integer at first location of array
signal t : integer;
begin
process(clk)
variable i : integer:= 1;--to be used to indicate the locations of array
begin
if (clk='1' and clk'event) and (count>0) then
count<=count-1;
elsif (clk='1' and clk'event) and (i<5) then
i:=i+1;
count<= set(i);
t<=t+1;
end if;
end process;
check<=t;
end imp;