Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me to fix my counter code (Modelsim simulation)

Status
Not open for further replies.

lzh08

Member level 2
Member level 2
Joined
May 28, 2004
Messages
45
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
565
the following is source code.I think the count should be 8,16......at the
St8_1,but the simulation result is 16,32......,why?
(use modelsim simulation)
library ieee;
use IEEE.Std_Logic_1164.all;
use IEEE.Std_Logic_Unsigned.all;
use IEEE.Std_Logic_Arith.all;

entity teststate is
port
(
SysClk : in Std_Logic; --timer
Reset : in std_logic
);
end teststate;

architecture Action of teststate is

type State_1 is (St0_1, St1_1, St2_1, St3_1, St4_1, St5_1,St6_1,St7_1,St8_1);
signal Cur_State_1, Next_State_1:State_1 := St0_1;
signal count : integer range 0 to 128;

begin

process(SysClk,ReSet)
begin
if Reset = '0' then
count <= 0;
elsif rising_edge(SysClk) then
case Cur_State_1 is
when St0_1 => Next_State_1 <= St1_1;
count <= count + 1;
when St1_1 => Next_State_1 <= St2_1;
count <= count + 1;
when St2_1 => Next_State_1 <= St3_1;
count <= count + 1;
when St3_1 => Next_State_1 <= St4_1;
count <= count + 1;
when St4_1 => Next_State_1 <= St5_1;
count <= count + 1;
when St5_1 => Next_State_1 <= St6_1;
count <= count + 1;
when St6_1 => Next_State_1 <= St7_1;
count <= count + 1;
when St7_1 => Next_State_1 <= St8_1;
count <= count + 1;
when St8_1 => Next_State_1 <= St0_1;
count <= count + 1;
when others => Next_State_1 <= St0_1;
end case;
end if;
end process;

process(Reset, SysClk)
begin
if Reset = '0' then
Cur_State_1 <= St0_1;
elsif rising_edge(SysClk) then
Cur_State_1 <= Next_State_1;
end if;
end process;

end Action;
 

Re: please help me!thx

Check with the following code!

Code:
library ieee;
use IEEE.Std_Logic_1164.all;
use IEEE.Std_Logic_Unsigned.all;
use IEEE.Std_Logic_Arith.all;

entity teststate is
  port
    (
      SysClk : in std_logic;            --timer
      Reset  : in std_logic
      );
end teststate;

architecture Action of teststate is

  type State_1 is (St0_1, St1_1, St2_1, St3_1, St4_1, St5_1, St6_1, St7_1, St8_1);
  signal Cur_State_1, Next_State_1 : State_1 := St0_1;
  signal count                     : integer range 0 to 128;
  signal count_nx                  : integer range 0 to 128;
begin

  process(Cur_State_1, count)
  begin
      case Cur_State_1 is
        when St0_1  => Next_State_1 <= St1_1;
                      count_nx <= count + 1;
        when St1_1  => Next_State_1 <= St2_1;
                      count_nx <= count + 1;
        when St2_1  => Next_State_1 <= St3_1;
                      count_nx <= count + 1;
        when St3_1  => Next_State_1 <= St4_1;
                      count_nx <= count + 1;
        when St4_1  => Next_State_1 <= St5_1;
                      count_nx <= count + 1;
        when St5_1  => Next_State_1 <= St6_1;
                      count_nx <= count + 1;
        when St6_1  => Next_State_1 <= St7_1;
                      count_nx <= count + 1;
        when St7_1  => Next_State_1 <= St8_1;
                      count_nx <= count + 1;
        when St8_1  => Next_State_1 <= St0_1;
                      count_nx <= count + 1;
        when others => Next_State_1 <= St0_1;
                       count_nx <= count;
      end case;
  end process;

  process(Reset, SysClk)
  begin
    if Reset = '0' then
      Cur_State_1 <= St0_1;
      count <= 0;
    elsif rising_edge(SysClk) then
      Cur_State_1 <= Next_State_1;
      count <= count_nx;
    end if;
  end process;

end Action;
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top