E
Eli Bendersky
Guest
Hi all,
My usage of counters undergoes evolution with my gaining experience in
VHDL, and I wondering what other people use for implementing counters.
All my design's boundaries (i.e. pins) are, naturally std_logic and
std_logic_vector. So are my registers for CPU access. But I like to
implement counters with 'natural' signals, because it's simpler.
So I define:
constant MAX_COUNT: natural := 42;
signal my_counter: natural range 0 to MAX_COUNT;
Then I can simply increment the counter with my_counter <= my_counter +
1, and compare it to numeric constants like 0, 1 and MAX_COUNT.
The interesting thing comes when there's need to convert back from
natural to std_logic_vector. I prefer not to intermix mathematical
libraries and use solely ieee.numeric_std, so my conversion is:
my_slv <= std_logic_vector(to_unsigned(my_counter, 6));
(Not that I think of it, I could use my_slv'size or 'length or
something, would that be synthesizable ?)
What are other people's approaches when implementing counters ?
Thanks in advance
Eli
My usage of counters undergoes evolution with my gaining experience in
VHDL, and I wondering what other people use for implementing counters.
All my design's boundaries (i.e. pins) are, naturally std_logic and
std_logic_vector. So are my registers for CPU access. But I like to
implement counters with 'natural' signals, because it's simpler.
So I define:
constant MAX_COUNT: natural := 42;
signal my_counter: natural range 0 to MAX_COUNT;
Then I can simply increment the counter with my_counter <= my_counter +
1, and compare it to numeric constants like 0, 1 and MAX_COUNT.
The interesting thing comes when there's need to convert back from
natural to std_logic_vector. I prefer not to intermix mathematical
libraries and use solely ieee.numeric_std, so my conversion is:
my_slv <= std_logic_vector(to_unsigned(my_counter, 6));
(Not that I think of it, I could use my_slv'size or 'length or
something, would that be synthesizable ?)
What are other people's approaches when implementing counters ?
Thanks in advance
Eli