0

I've been trying to write VHDL code for a counter. Ultimately, I would like to take the output value, check it with a constant value, and see if the counter has reached the constant value. if it reaches there, I want to reset it. and if not I want to keep counting. What I wrote for the counter process is the following:

CNT: process(clk,reset)
begin
     if (reset='0') then
        cnt_tmp<= (others=>'0');
     elsif (rising_edge(clk)) then
        if (enable= '1') then
            if (match='1') then
                cnt_tmp <= (others => '0');
            else
                cnt_tmp <= cnt_tmp + 1;
            end if;
        else
            cnt_tmp <= cnt_tmp;
        end if;
    end if;
end process;
cnt<= cnt_tmp; 

So, when the match is 1, we synchronously reset the counter and it also has an enable pin.

This match signal is generated by bitwise xnor the constant with the counter output and "and" of the xnor outputs all together.

However, when I run the simulation, I see some glitches like this:

enter image description here

Does anyone have any idea how can I deal with this problem?

I am expecting to eliminate these glitches even though they don't affect the functionality in my simulations.

4
  • 5
    Provide a minimal reproducible example. The glitches are not produced in your process statement snippet, enable isn't assigned there. Identity assignment in sequential logic is not required (cnt_tmp <= cnt_tmp;). Commented Feb 28, 2024 at 19:58
  • @user16145658 the cnt_tmp signal is std_logic_vector and enable is the input. Commented Feb 28, 2024 at 20:08
  • 2
    I could tell that. The glitches are on your enable. Where's the driver? Commented Feb 28, 2024 at 23:33
  • 2
    The glitches are on en_i which is not in the code excerpt you show us. Please edit your question to provide the minimal reproducible example. Commented Feb 29, 2024 at 6:45

1 Answer 1

0

Lots going on here:

  1. Your glitch isn't important: the signal is sampled on a clock edge. You don't need to get rid of all glitches in your sims, and this is not practical in bigger designs
  2. Your glitch will be caused by your xnor/and structure. The inputs will change at slightly different times, so the output glitches
  3. Don't do this. Why can't you just replace match='1' with a compare against 'the constant'? Glitch gone
  4. What is cnt_tmp for? It's not necessary
  5. What's the point of cnt_tmp <= cnt_tmp? That's just pointless extra typing
  6. VHDL isn't C. Get rid of all the brackets in the if statements
Sign up to request clarification or add additional context in comments.

5 Comments

Well, the cnt_tmp is necessary because you cannot use the output port and feedback it. The constant value may change as I am using a nested counter structure.
But yes, the problem was for xnor and structure, and problem is solved.
@NimaKolahimahmodi: VHDL-2008 lets you read back output ports; it would be very surprising if any tool nowadays didn't let you do this. And, if the answer helped, you should accept it. I don't normally bother reading VHDL/Verilog questions because most of the questions are from low-rep users who don't acknowledge answers, or don't accept them, or accept the wrong one.
Thanks a lot! Even after all these years, I am learning something new. Thank you.
@NimaKolahimahmodi: :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.