[email protected] wrote:
> What is this for? If you are a student and this is part of an
> assignment I don't want to just give you the answer but that doesn't
> mean I won't try to help you.
I am ofcourse a student, but it's quite some time ago that I learned
about statemachine design (two years actually). Right now I'm trying to
do my bachelor, where I deciden to use VHDL and the Spartan III for my
project. I am supposed to build the digital sampling part of a digital
storage oscilloscope.
But all the theory and implementation which I haven't done a lot of work
of is being my trouble.
So it's not an assignment, more a tiny part of my own project.
> Are there any design requirements that need to be followed or met?
Well, as fast as possible (aiming for 200MHz maximum speed)!
> Style and presentation is very important with VHDL. WIth a programming
> language like 'C' you can get away with creating compound and nested if
> statements with different structures and with an optimizing compiler
> end up with the same result.
Well, if my litterature is outdated I'm very happy if someone could give
me advice for some more updated litterature.
> Early when I was learning VHDL, I noticed that depending on how you
> structure your code effects the circuit design. In VHDL the compiler
> tries to implement designs it recognizes ie. state machines.
Both the single-process, the xilinx-template, and the one-hot approach I
tried to build did the job as being recognized as statemachines (FSM's).
> As, someone else pointed out, the way you went about implementing your
> state machine isn't the expected way. Try implementng using case
> structure instead of if control structure. Don't forget the differences
> between case and if statements - if statements are evaluated sequential
> and case states are evaluated parallel.
I'm aware of that if-statements are "sequential" (the last if-statement
has the "power"), but in hardware they are still quite parallel (even
though more if's costs more time in some cases).
> In VHDL as in C, if you have a large chunk of code and are having
> trouble with it you should break it up into smaller chunks. Use block
> and process structures to make your code smaller. It should make your
> code easier to read and make the compilers job easier.
Yeah, but I'm not able to break a state machine into smaller pieces, and
this is even though quite simple!
How do you like my new design (single-process)
----------------------------------------------
entity holdoffcontroller is
Port ( clk : in std_logic;
reset : in std_logic;
save : in std_logic;
trig : in std_logic;
read : in std_logic;
holdoff : in std_logic;
hold : out std_logic := '0';
state : out std_logic_vector(4 downto 0));
end holdoffcontroller;
architecture Behavioral of holdoffcontroller is
type states is (stateStart, stateWait, stateTrigger, stateHold,
stateRead);
begin
STATEMACHINE: block
signal current_state : states := stateStart;
begin
stateRegister : process(clk, reset)
begin
if reset = '1' then
current_state <= stateStart;
elsif rising_edge(clk) then
current_state <= current_state;
case current_state is
when stateStart =>
--holdoff_counter_enable <= '0';
--holdoff_counter_reset <= '1';
hold <= '0';
if holdoff = '0' and read = '0' and trig = '0' then
current_state <= stateWait;
end if;
when stateWait =>
if trig = '1' then
current_state <= stateTrigger;
end if;
when stateTrigger =>
--holdoff_counter_enable <= '1';
hold <= '1';
if holdoff = '1' and read = '0' then
current_state <= stateHold;
end if;
if holdoff = '0' and read = '1' then
current_state <= stateRead;
end if;
if holdoff = '1' and read = '1' then
current_state <= stateStart;
end if;
when stateHold =>
--holdoff_counter_enable <= '0';
if read = '1' then
current_state <= stateStart;
end if;
when stateRead =>
if holdoff = '1' then
current_state <= stateStart;
end if;
end case;
end if;
end process;
process(current_state)
begin
case current_state is
when stateStart => state <= "00001";
when stateWait => state <= "00010";
when stateTrigger => state <= "00100";
when stateHold => state <= "01000";
when stateRead => state <= "10000";
end case;
end process;
end block;
end Behavioral;
----------------------------------------------