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.

Why my 2-digit counter w/VHDL didn't work?

Status
Not open for further replies.

huytergan

Member level 3
Joined
Jun 18, 2018
Messages
57
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
372
Tryna see 00-99 counter in Xilinx Vivado's simulation.
Code:
entity twodigitcounter is
  Port ( 
  
  clk : in std_logic;
  digit1,digit2 : out integer range 0 to 9
  );
end twodigitcounter;

architecture Behavioral of twodigitcounter is

shared variable temp1,temp2 : integer range 0 to 9;
begin
proc1:process(clk)

begin

    if rising_edge(clk) then
        if temp1 = 9 then
            temp1:=0;
        else
            temp1:=temp1+1;
        end if;
    end if;
end process proc1;

proc2:process(clk)

begin

    if rising_edge(clk) then
        if temp1=9 then
            if temp2=9 then
                temp2:=0;
            else   
            temp2:=temp2+1;
            end if;
        end if; 
   end if;
end process proc2;

digit1 <= temp1;
digit2 <= temp2;

end Behavioral;

couldn't understand what was wrong. In simulation, digit1 and digit2 stuck with 0.
For any help, thanks in advance.
Regards
 

First of all, did you provide a clock in the testbench?
Second - please dont use shared variables. You should be using signals.
 

Thanks for your response,
Yes I did, I’d have done it with a single process and without using shared variable actully. Just wanted to see how it’s used.
Do you think the code seems inaccurate?
 

There are no problems with your code as posted. Hence why I think theres no clock. Can you post the testbench and waveform showing the problem?
 

Code:
entity twodigitcounter_tb is
--  Port ( );
end twodigitcounter_tb;

architecture Behavioral of twodigitcounter_tb is

signal clk :  std_logic;
signal digit1,digit2 :  integer range 0 to 9;

component twodigitcounter 
port(
  clk : in std_logic;
  digit1,digit2 : out integer range 0 to 9
  );
end component;


begin

uut:twodigitcounter port map(

clk => clk,
digit1 => digit1,
digit2 => digit2

);

process 
begin
    if clk /= '1' then clk <= '1';
    else clk <= '0';
    end if;
    wait for 10 ns;
    end process;
    

end Behavioral;


clk.png
 

The problem is you are using shared variables. Because variables have no 'event attribute, the digit1/2 outputs never get updated
You need to use signals instead, or assign digit1/2 inside the processes.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top