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

  • Home
  • SEARCH
  • 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 8083103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:21:05+00:00 2026-06-05T17:21:05+00:00

I wrote some code in VHDL that is expected to look at a rotory

  • 0

I wrote some code in VHDL that is expected to look at a rotory switch and feed back to me what position it is in.

When it gets turned it will read in the greycode from the rotor dial and switch states to the corresponding greycode state.

The act of changing states tells me which way the rotor is being twisted so I can indicate either an up or down state on a counter module later in the circuit.

If the state changes it should trigger a pulse on Mag and triger either a 1 or 0 on up_dwn.

It doesn’t work when I simulate it. I get an occassional blip on Mag but no up_dwn change.

I suspect it’s stuck in theSTARTstate.

Anyone care to look and tell me what I’ve done wrong?

[Ed: Using Quartus II Version 9 ]

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;

ENTITY EncoderV2    IS
PORT(
    CH_AB           :   IN  STD_LOGIC_VECTOR (1 downto 0);
    clk             :   IN  STD_LOGIC;
    nReset          :   IN  STD_LOGIC;
    up_dwn, Mag     :   OUT STD_LOGIC);

    END EncoderV2;

ARCHITECTURE a OF EncoderV2 IS  --  
TYPE STATE_TYPE IS ( START, s00, s01, s11, s10);
SIGNAL state:   STATE_TYPE;

BEGIN
PROCESS (clk, nReset)
BEGIN
    IF nReset = '0' THEN                        --    asynch Reset to zero
        state   <=  START;
    ELSIF clk'EVENT AND clk = '1' THEN          --  triggers on PGT
        CASE state IS 
            WHEN START =>
                    IF CH_AB ="00" THEN
                                state   <= s00;
                                Mag <='0';
                    ELSIF CH_AB="01" THEN
                                state   <= s01;
                                Mag <='0';
                    ELSIF CH_AB= "11" THEN
                                state   <= s11;
                                Mag <='0';
                    ELSIF CH_AB= "10" THEN
                                state   <= s10;
                                Mag <='0';
                    ELSE  state <= START;
                    END IF;

            WHEN s00 =>                 --  S10 <- S00 -> S01
                    IF CH_AB= "00" THEN
                                state   <= s00;
                                Mag <='0';
                    ELSIF CH_AB= "10" THEN
                                state   <= s10;
                                up_dwn  <= '0';
                                Mag <='1';
                    ELSIF CH_AB= "01" THEN
                                state   <= s01;
                                up_dwn  <='1';
                                Mag <='1';
                    ELSE  state <= START;
                    END IF;

            WHEN s01 =>                 --  S00 <- S01 -> S11
                    IF CH_AB= "01" THEN
                                state   <= s01;
                                Mag <='0';
                    ELSIF CH_AB= "00" THEN
                                state   <= s00;
                                up_dwn  <= '0';
                                Mag <='1';
                    ELSIF CH_AB= "11" THEN
                                state   <= s11;
                                up_dwn  <='1';
                                Mag <='1';
                    ELSE state <= START;
                    END IF;

            WHEN s11 =>                 --  S01 <- S11 ->S10
                    IF CH_AB= "11" THEN
                                state   <= s11;
                                Mag <='0';
                    ELSIF CH_AB= "01" THEN
                                state   <= s01;
                                up_dwn  <= '0';
                                Mag <='1';
                    ELSIF CH_AB= "10" THEN
                                state   <= s10;
                                up_dwn  <='1';
                                Mag <='1';
                    ELSE state <= START;
                    END IF;

            WHEN s10 =>                 --  S11 <- S10 -> S00
                    IF CH_AB= "10" THEN
                                state   <= s10;
                                Mag <='0';
                    ELSIF CH_AB= "11" THEN
                                state   <= s11;
                                up_dwn  <= '0';
                                Mag <='1';
                    ELSIF CH_AB= "00" THEN
                                state   <= s00;
                                up_dwn  <='1';
                                Mag <='1';
                    ELSE state <= START;
                    END IF;





            END CASE;
        END IF;
    END PROCESS;
END a;
  • 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-06-05T17:21:09+00:00Added an answer on June 5, 2026 at 5:21 pm

    works fine for me … simulated with Modelsim

    I simuleted it with 50, 100 and 200 MHz.
    The only thing I wonder about is you use “IF .. nReset = ‘0’ THEN” .. are you sure about it?
    It cost me like 20minutes before I saw it and changed it in my stimulus file.

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

Sidebar

Related Questions

I've wrote some code that will check two dates - they are split into
I wrote some code to ensure that my database will be updated properly when
I wrote some code to periodically post data to a NodeJs program that listens
I wrote some code that modifies the images on a webpage. Works with firefox
I wrote some code (about 100 lines) that is working fine on version 5.12.1.
I wrote some code to save images on the SD Card a while back.
I wrote some code that spits out an image. The code ran on my
I accidently wrote some code today that was like this: Private Sub Foo() Dim
I recently wrote some code that uses the same unsigned short to store two
I wrote some code that looks like this: def get(x, y) @cachedResults.set(x,y, Math.hypot(x, y))

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.