Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Adding to vector

Reply
Thread Tools

Adding to vector

 
 
thecity00 thecity00 is offline
Junior Member
Join Date: Dec 2009
Posts: 1
 
      12-06-2009
Hey all,
I am having an issue where adding 1 to a vector is resulting in the vector incrementing by 8 in decimal, while I want it to just increment by 1.

Here is my code:

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( 
		CLK: in std_logic;
		output: out std_logic_vector(0 to 3);
end counter;

architecture behavioral of counter is
   signal temp: std_logic_vector(0 to 3);
	begin process(CLK)
	begin
		if(CLK'event and CLK='1') then
			temp <= (temp + 1);
			end if;
	end process;
	output <= temp;
end behavioral;
This is how the output is incrementing:
0,8,4,12,2,10

Seems it is adding 8...


Thanks in advance
 
Reply With Quote
 
 
 
 
jeppe jeppe is offline
Senior Member
Join Date: Mar 2008
Location: Denmark
Posts: 348
 
      12-06-2009
Hi

Try this and note the difference between to and downto.

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( 
		CLK: in std_logic;
		output: out std_logic_vector(3 downto 0);
end counter;

architecture behavioral of counter is
   signal temp: std_logic_vector(3 downto 0);
	begin process(CLK)
	begin
		if(CLK'event and CLK='1') then
			temp <= (temp + 1);
			end if;
	end process;
	output <= temp;
end behavioral;
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
const vector<A> vs vector<const A> vs const vector<const A> Javier C++ 2 09-04-2007 08:46 PM
Initializing vector<vector<int> > and other vector questions... pmatos C++ 6 04-26-2007 05:39 PM
Free memory allocate by a STL vector, vector of vector, map of vector Allerdyce.John@gmail.com C++ 8 02-18-2006 12:48 AM
how the vector is created, how to pass vector to webservices method apachesoap:Vector Rushikesh Joshi Perl Misc 0 07-10-2004 01:04 PM
how do i create a vector within a vector ? learningjava Java 5 10-17-2003 10:19 PM



Advertisments