0

A colleague an I are working on a course project to calculate the GCD (greater common divider) of N numbers using VHDL. We are using Euclid algorithm and have written the code below:


     P1: process(clk,rstN)
    begin
    if (rstn = '1') then
    CS <= redy;
        eqsig <= '0';
        x <= (others => '0');
        y <= (others => '0');
    elsif (clk'EVENT and clk = '1') then
        CS <= NS;  
   end if;
end process P1;


    P2: process(CS,eqsig,NS)
begin

    case CS is
        when redy =>
            NS <= inpt;
        when inpt =>
            NS <= comp;
        when comp =>
            if (eqsig = '1') then
                NS <= otpt;
            else 
                NS <= oper;
            end if;
        when oper =>
            NS <= comp;
        when otpt =>
            NS <= redy;
        when others =>
            NS <= redy;
    end case;
end process P2;

    P3: Process(CS,eqsig)
begin

    case CS is
        when oper =>
            if x<y then
            y <= y-x;
            elsif y<x then
            x <= x-y;
            end if;

        when comp =>
            if x=y then
                eqsig <= '1';
            else
                eqsig <= '0';
            end if;
       when otpt =>
           if (rden = '1') then
           rdata <= x;
           end if;
       when inpt =>
             if (wren'EVENT and wren = '1') then
                if (waddr = "00") then
                    x <= wdata;
              end if;
             end if;
             if (wren'EVENT and wren = '0') then
                 if (waddr = "01") then
                     y <= wdata;
               end if;
             end if;
        when others =>
            null;
    end case; 
end process P3;

When trying to simulate it, it shows that output is "U" although the code seems correct with no errors and it can read inputs. Here is the testbench:


rstN <= '0' after 10 ns;
        wren <= '1' after 10 ns, '0' after 70 ns;
        wdata <= "00000000000000000000000000000011" after 20 ns,
                 "00000000000000000000000000000110" after 60 ns;
        waddr <= "00"after 20 ns,
                 "01"after 60 ns;
        rden <= '1' after 90 ns;

clk_process : process
begin
    clk <= '0' ;
    wait for cp/2;
    clk <= '1';
    wait for cp/2;
end process;

Thank you so much. BR//Dee

5
  • 1
    What is the GCD? (yes I did google it, but the question should be clear)
    – scary_jeff
    May 18, 2018 at 8:47
  • 3
    Welcome to Stack Overflow. You're more likely to get a useful answer if you follow the guidelines here. Specifically, what is happening, what were you expecting to happen? Secondly, provide something executable so that someone else can easily see what you're seeing. Finally, just supply the minimum code required to reproduce the problem. These last two are called an MCVE. May 18, 2018 at 8:51
  • Are you by accident simulation the top-level entity instead of the test bench? (Common mistake)
    – JHBonarius
    May 18, 2018 at 10:59
  • 1
    While your code isn't a minimal reproducible example your processes P1 assigns x, y and CS, P2 assigns NS and P3 assigns x,y and rdata. The assignments in two processes will cause multiple drivers where the effective value of x and y are resolved between the two. You could note the resolution function's resolution table found in package std_logic_1164 resolves a 'U' and anything else to a 'U'. Move the assignments to x and y all into the same process. There may be other issues with your code snippets.
    – user1155120
    May 18, 2018 at 11:02
  • I have checked the simulation settings and the sensitivity listing in the processes and still the output appears as "U"
    – Dee
    May 21, 2018 at 10:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.