Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6712561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:16:26+00:00 2026-05-26T08:16:26+00:00

I am designing a shift key detector.I wrote a test bench. The test showed

  • 0

I am designing a shift key detector.I wrote a test bench. The test showed that my implementation was incorrect.

Here is the simulation in ModelSim.

enter image description here

The red line indicated UNDEFINED. This behavior only occurred twice.

What puzzled me is: why is there such a big gap between those two values? If you look at the test bench, the 3rd and 4th procedures are using the format used for the 1st and 2rd.


Test bench is here: http://pastebin.com/BJVFFgGr

The detector code is here: http://pastebin.com/di42FLqT

As you can see. I have two states in my design. PS2 receiver will filter and generate clean 8-bit make code when a key is pressed (or released). The break code is simply F0 follow by the make code of the key just released. My state machine uses two extra bits to keep track of which shift key has been pressed.

I went through debug, and when we entered the 3rd test values, SHIFT = U instead of 1 from the previous value.

-- release left shift
hex <= "11110000";
wait for 5 ns;
clk <= NOT clk;
wait for 50 ns;
clk <= NOT clk;
wait for 50 ns;

hex <= "00010010";       <----- when I am here shift is already U
wait for 5 ns;
clk <= NOT clk;
wait for 50 ns;
clk <= NOT clk;
wait for 50 ns;

if (shift /= '0')then
    error <= '1'; 
end if;

left_pressed and right_pressed are signals, not variables. So they should have the a value at any instance. If one of them changes, the connection to shift signal will be updated automatically.

Can someone please help me? Thanks.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:16:26+00:00Added an answer on May 26, 2026 at 8:16 am

    I expect you’re getting the ‘U’ output because

    shift <= left_pressed or right_pressed;
    

    and right_pressed is undefined, so when left_pressed becomes ‘0’ the ‘U’ in right_pressed shows through.

    Remember that

    1 or x == 1
    0 or x == x
    

    where x can be ‘0’, ‘1’, ‘U’, ‘X’, ‘Z’, ‘-‘, ‘H’, ‘L’

    There are a few problems with your code that stand out to me

    1. At the moment left_pressed and right_pressed are latches as they will carry their value from one cycle to the next in some conditions, but they’re not in a clocked process. If you want them to be plain signals, then you need to give them default values at the start of the process. If you want them to be registers, they need to be in a clocked process.

      This is also true of next_state. It should have a default value.

      next_state <= current_state;
      
    2. current_state needs to be in the sensitivity list of the asynchronous process.

    3. Use a separate process to generate your clock in your test bench. At the moment it’s mixed in with the stimulus which is messing up your clock period. It also makes it difficult to read.

      process p_clkgen
      begin
          repeat begin
              clk <= NOT clk;
              wait for 50 ns;
          end;
      end process;
      

      Then the other process is only dealing with when the input transitions. (I can’t remember if repeat is a valid keyword in VHDL, but you get the idea)

    4. I suspect your thinking about your state is mixed up. Probably the state should be that the left or right shift key is pressed, and a make or break on each of them is the transition between states. I think this mix-up is part of the reason why left_pressed and right_pressed are currently latches.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While designing a table my colleague here says that I should avoid identity column
I have noticed that when designing a database I tend to shift any repeating
When designing a web service that will allow the consumer of the service to
Designing a simple HTML table that I am going to implement alternate-row coloring on...
I am designing universal shift arithmetic operator. Is there a better way to achieve
When designing a RESTful API that uses a datastore that makes use of auto-generated
When designing my homepage, I feel like the common knowledge is that it is
I am designing this database that must maintain a history of employee salary and
I'm designing a database for an employee scheduling system. Each shift has M different
For a simulation of a laser-based sensor I am designing, I want to verify

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.