Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - constants declaration

 
Thread Tools Search this Thread
Old 02-12-2004, 10:48 AM   #1
Default constants declaration


does anyone know a quick method of declaring an alternating pattern with a
variable length?

constant FAIL_LOW : std_logic_vector (WATCH_LENGTH-1 downto 0) := (others
=> '0');
-- above is great, you change WATCH_LENGTH and the rest is ok
constant WATCH_STARTUP : std_logic_vector(WATCH_LENGTH-1 downto 0) :=
"10101010";
-- with this you have to make sure you dont forget to re-write the value!

Ben

--
Benjamin Todd
European Organisation for Nuclear Research
Accelerator and Beam -- Control -- Infrastructure Division
CERN, Geneva, Switzerland, CH-1211
Building 864 Room 1 - A24




Benjamin Todd
  Reply With Quote
Old 02-12-2004, 06:14 PM   #2
Tim Hubberstey
 
Posts: n/a
Default Re: constants declaration
Benjamin Todd wrote:
>
> does anyone know a quick method of declaring an alternating pattern with a
> variable length?
>
> constant FAIL_LOW : std_logic_vector (WATCH_LENGTH-1 downto 0) := (others
> => '0');
> -- above is great, you change WATCH_LENGTH and the rest is ok
> constant WATCH_STARTUP : std_logic_vector(WATCH_LENGTH-1 downto 0) :=
> "10101010";
> -- with this you have to make sure you dont forget to re-write the value!


A general solution is to define a function:

function alternate(size : natural) return std_logic_vector is
variable v_result : std_logic_vector(size-1 downto 0);
begin
for i in 0 to size-1 loop
if ( (i mod 2) = 0 ) then
v_result(i) := '0';
else
v_result(i) := '1';
end if;
end loop;
return v_result;
end alternate;

and use it to initialize your constant:

constant FAIL_LOW : std_logic_vector(WATCH_LENGTH-1 downto 0) :=
alternate(WATCH_LENGTH);

A quick and dirty solution is to define a constant that is as large as
WATCH_LENGTH could ever reasonably be, initialize it with your pattern,
and then take a slice of it to initialize your variable size vector:

constant pattern : std_logic_vector(31 downto 0) :=
"10101010101010101010101010101010";
constant FAIL_LOW : std_logic_vector(WATCH_LENGTH-1 downto 0) :=
pattern(WATCH_LENGTH-1 downto 0);

This may be a bit less typing but has obvious problems if you can't put
an upper bound on WATCH_LENGTH.
--
Tim Hubberstey, P.Eng. . . . . . Hardware/Software Consulting Engineer
Marmot Engineering . . . . . . . VHDL, ASICs, FPGAs, embedded systems
Vancouver, BC, Canada . . . . . . . . . . . http://www.marmot-eng.com


Tim Hubberstey
  Reply With Quote
Old 02-15-2004, 01:49 PM   #3
Benjamin Todd
 
Posts: n/a
Default Re: constants declaration
thanks!

"Tim Hubberstey" <> wrote in message
news:...
> Benjamin Todd wrote:
> >
> > does anyone know a quick method of declaring an alternating pattern with

a
> > variable length?
> >
> > constant FAIL_LOW : std_logic_vector (WATCH_LENGTH-1 downto 0) :=

(others
> > => '0');
> > -- above is great, you change WATCH_LENGTH and the rest is ok
> > constant WATCH_STARTUP : std_logic_vector(WATCH_LENGTH-1 downto 0) :=
> > "10101010";
> > -- with this you have to make sure you dont forget to re-write the

value!
>
> A general solution is to define a function:
>
> function alternate(size : natural) return std_logic_vector is
> variable v_result : std_logic_vector(size-1 downto 0);
> begin
> for i in 0 to size-1 loop
> if ( (i mod 2) = 0 ) then
> v_result(i) := '0';
> else
> v_result(i) := '1';
> end if;
> end loop;
> return v_result;
> end alternate;
>
> and use it to initialize your constant:
>
> constant FAIL_LOW : std_logic_vector(WATCH_LENGTH-1 downto 0) :=
> alternate(WATCH_LENGTH);
>
> A quick and dirty solution is to define a constant that is as large as
> WATCH_LENGTH could ever reasonably be, initialize it with your pattern,
> and then take a slice of it to initialize your variable size vector:
>
> constant pattern : std_logic_vector(31 downto 0) :=
> "10101010101010101010101010101010";
> constant FAIL_LOW : std_logic_vector(WATCH_LENGTH-1 downto 0) :=
> pattern(WATCH_LENGTH-1 downto 0);
>
> This may be a bit less typing but has obvious problems if you can't put
> an upper bound on WATCH_LENGTH.
> --
> Tim Hubberstey, P.Eng. . . . . . Hardware/Software Consulting Engineer
> Marmot Engineering . . . . . . . VHDL, ASICs, FPGAs, embedded systems
> Vancouver, BC, Canada . . . . . . . . . . . http://www.marmot-eng.com





Benjamin Todd
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
constants as of array of integers, for loops octavsly Hardware 0 04-25-2009 11:53 AM
error: ISO C++ forbids declaration of ‘vector’ with no type samsneelam Software 0 08-28-2008 11:20 AM
Shinto, Normism & Declaration of Heaven on Earth937 Maria Barti A+ Certification 0 03-16-2005 12:54 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46