EmbDev.net

Forum: FPGA, VHDL & Verilog Multiple Driver Nets _segmento{OBUF[0]


Author: ricardo (Guest)
Posted on:

Rate this post
0 useful
not useful
Help me .... I do not know where this error is.
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
use ieee.numeric_std.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

entity colculadora_4bits is
Port(chaves_a, chaves_b: in std_logic_vector(3 downto 0);
         led: inout bit;
        led_1: inout bit;
        segmento: out bit_VECTOR(0 TO 6);
        chave_sinal: inout std_logic;
        clk: in std_logic;
        display: out bit_VECTOR(7 DOWNTO 0);
         x: inout integer;
        subtracao, soma: inout integer);
end colculadora_4bits;

architecture Behavioral of colculadora_4bits is

begin

process(chaves_a, chaves_b, chave_sinal)
begin

    if (chave_sinal = '0') then
        subtracao <= 0;
        soma <= conv_integer(chaves_a) + conv_integer(chaves_b);
    elsif(chave_sinal = '1') then
        soma <= 0;
        subtracao <= conv_integer(chaves_a) - conv_integer(chaves_b);
    END IF;
end process;


PROCESS(subtracao)
begin
        if (subtracao < 0) then
            led_1 <= '1';
            led <= '0';
        elsif(subtracao >= 0) then
            led <= '1';
            led_1 <= '0';
        end
    if;
end process;


PROCESS(x, soma, subtracao, chave_sinal, clk)
BEGIN

        if (subtracao <= 0) then
            x <= subtracao + (subtracao * (-2));
         else 
          x<= subtracao;
        end if;
        
        if (chave_sinal = '1') then
            if (x = 0) then
                if (clk 'event and clk='1') then
                
                    display <="11111110";  
                   segmento <= "0000001";  
                end if; 
             if (clk'event and clk = '0') then
                display <= "11111101";
               segmento <= "0000001";
            end if;
            
            elsif(x = 1) then
            if (clk 'event and clk = '1') then 
            
                display <="11111110";  
                segmento <= "1001111";
           end if;
        if (clk'event and clk = '0') then
                display <= "11111101";
                segmento <= "0000001";
        end if;
        
        elsif(x = 2) then
        if (clk 'event and clk='1') then 
            display <="11111110";  
            segmento <= "0010010";
            end if;
        if (clk'event and clk = '0') then
            display <= "11111101";
            segmento <= "0000001";
            end if;
            
        elsif(x = 3) then
        if (clk 'event and clk='1') then 
        display <="11111110"; 
        segmento <= "0000110"; 
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "0000001";
        end if;
        
        elsif(x = 4) then
        if (clk 'event and clk='1') then 
        display <="11111110"; 
        segmento <= "1001100";
        end if;
            if (clk'event and clk = '0') then
            display <= "11111101";
           segmento <= "0000001";
            end if;
            
            
        elsif(x = 5) then
        if (clk 'event and clk='1') then 
        display <="11111110";
        segmento <= "0100100";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "0000001";
        end if;
        
        elsif(x = 6) then
       if (clk 'event and clk='1') then 
        display <="11111110";
        segmento <= "0100000";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "0000001";
        end if;
        
        elsif(x = 7) then
        if (clk 'event and clk='1') then 
        display <="11111110";
        segmento <= "0001111";
        end if;
        if (clk'        event and clk = '0') then
        display <= "11111101";
        segmento <= "0000001";
        end if;
        
        elsif(x = 8) then
        if (clk 'event and clk='1') then 
        display <="11111110";
        segmento <= "1111111";
        end if;
        if (clk'        event and clk = '0') then
        display <= "11111101";
        segmento <= "0000001";
        end if;
        
        elsif(x = 9) then
        if (clk 'event and clk='1') then 
        display <="11111110";
        segmento <= "0000100";
        end if;
        if (clk'        event and clk = '0') then
        display <= "11111101";
        segmento <= "0000001";
        end if;
        
        elsif(x = 10) then
        if (clk 'event and clk='1') then 
        display <="11111110";
        segmento <= "0000001";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "1001111";
        end if;
        
        elsif(x = 11) then
        if (clk 'event and clk='1') then 
        display <="11111110";
        segmento <= "1001111";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "1001111";
        end if;
        
        elsif(x = 12) then
        if (clk 'event and clk='1') then  
        display <="11111110";  
        segmento <= "0010010";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "1001111";
        end if;
        
        elsif(x = 13) then
        if (clk 'event and clk='1') then  
        display <="11111110"; 
        segmento <= "0000110";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "1001111";
        end if;
        
        elsif(x = 14) then
        if (clk 'event and clk='1') then  
        display <="11111110"; 
        segmento <= "1001100";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "1001111";
        end if;
        
        elsif(x = 15) then
        if (clk 'event and clk='1') then  
        display <="11111110";
        segmento <= "0100100";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "1001111";
        end if;
  end if;
end if;


  if (chave_sinal = '0') then
    
    if (soma = 0) then
        if (clk'event and clk='1') then  
        display <="11111110";  
        segmento <= "0000001";   
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101" after 5ns;
        segmento <= "0000001" after 5ns;
        end if;
        
        elsif(soma = 1) then
        if (clk'event and clk='1') then  
        display <="11111110";  
        segmento <= "1001111";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "0000001";
        end if;
        
        elsif(soma = 2) then
       if (clk'event and clk='1') then
        display <="11111110";  
        segmento <= "0010010";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "0000001";
        end if;
        
        elsif(soma = 3) then
        if (clk'event and clk='1') then
        display <="11111110"; 
        segmento <= "0000110"; 
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "0000001";
        end if;
        
        elsif(soma = 4) then
        if (clk'event and clk='1') then  
        display <="11111110"; 
        segmento <= "1001100";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "0000001";
        end if;
        
        elsif(soma = 5) then
        if (clk'event and clk='1') then  
        display <="11111110";
        segmento <= "0100100";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "0000001";
        end if;
        
        elsif(soma = 6) then
        if (clk'event and clk='1') then  
        display <="11111110";
        segmento <= "0100000";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "0000001";
        end if;
        
        elsif(soma = 7) then
        if (clk'event and clk='1') then  
        display <="11111110";
        segmento <= "0001111";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "0000001";
        end if;
        
        elsif(soma = 8) then
        if (clk'event and clk='1') then 
        display <="11111110";
        segmento <= "1111111";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "0000001";
        end if;
        
        elsif(soma = 9) then
        if (clk'event and clk='1') then  
        display <="11111110";
        segmento <= "0000100";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "0000001";
        end if;
        
        elsif(soma = 10) then
        if (clk'event and clk='1') then  
        display <="11111110";
        segmento <= "0000001";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "1001111";
        end if;
        
        elsif(soma = 11) then
        if (clk'event and clk='1') then  
        display <="11111110";
        segmento <= "1001111";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "1001111";
        end if;
        
        elsif(soma = 12) then
        if (clk'event and clk='1') then  
        display <="11111110";  
        segmento <= "0010010";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "1001111";
        end if;
        
        elsif(soma = 13) then
        if (clk'event and clk='1') then  
        display <="11111110"; 
        segmento <= "0000110";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "1001111";
         end if;
        
        elsif(soma = 14) then
        if (clk'event and clk='1') then  
        display <="11111110"; 
        segmento <= "1001100";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "1001111";
        end if;
        
        elsif(soma = 15) then
        if (clk'event and clk='1') then  
        display <="11111110";
        segmento <= "0100100";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "1001111";
        end if;
        
        elsif(soma = 16) then
        if (clk'event and clk='1') then  
        display <="11111110";
        segmento <= "0100000";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "1001111";
        end if;
        
        elsif(soma = 17) then
        if (clk'event and clk='1') then 
        display <="11111110";
        segmento <= "0001111";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "1001111";
        end if;
        
        elsif(soma = 18) then
        if (clk'event and clk='1') then  
        display <="11111110";
        segmento <= "1111111";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "1001111";
        end if;
        
        elsif(soma = 19) then
        if (clk'event and clk='1') then  
        display <="11111110";
        segmento <= "0000100";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "1001111";
        end if;
        
        elsif(soma = 20) then
        if (clk'event and clk='1') then  
        display <="11111110";  
        segmento <= "0000001";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "0010010";
        end if;
        
        elsif(soma = 21) then
        if (clk'event and clk='1') then  
        display <="11111110";
        segmento <= "1001111";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "0010010";
        end if;
        
        elsif(soma = 22) then
        if (clk'event and clk='1') then  
        display <="11111110";  
        segmento <= "0010010";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "0010010";
        end if;
        
        elsif(soma = 23) then
        if (clk'event and clk='1') then  
        display <="11111110"; 
        segmento <= "0000110";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "0010010";
        end if;
        
        elsif(soma = 24) then
        if (clk'event and clk='1') then  
        display <="11111110"; 
        segmento <= "1001100";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "0010010";
        end if;
        
        elsif(soma = 25) then
        if (clk'event and clk='1') then  
        display <="11111110";
        segmento <= "0100100";
        end if;
        if (clk'event and clk = '0') then
        display <= "11111101";
        segmento <= "0010010";
        end if;
        
        elsif(soma = 26) then
        if (clk'event and clk='1') then  
         display <="11111110";
        segmento <= "0000110";
        end if;
        if (clk'event and clk='0') then
        display <="11111101"; 
        segmento <= "0010010";
        end if;
        
        elsif (soma = 27) then
        if (clk'event and clk = '1') then
        display <= "11111110";
        segmento <= "0001111";
        end if;        
        if (clk'event and clk='0') then
        display <="11111101"; 
        segmento <= "0010010";
        end if;
        
        elsif (soma = 28) then
        if (clk'event and clk = '1') then
        display <= "11111110";
        segmento <= "1111111";
        end if;
        if (clk'event and clk='0') then
        display <="11111101"; 
        segmento <= "0010010";
        end if;
        
        elsif (soma = 29) then
        if (clk'event and clk = '1') then
        display <= "11111110";
        segmento <= "0000100";
        end if;        
        if (clk'event and clk='0') then
        display <="11111101"; 
        segmento <= "0010010";
        end if;
        
        elsif (soma = 30) then
        if (clk'event and clk = '1') then
        display <= "11111110";
        segmento <= "0000001";
        end if;        
       if (clk'event and clk='0') then
        display <="11111101"; 
        segmento <= "0000110";
        end if; 
        
                                                                                  
end if;    
  end if;      
end process;
end Behavioral;

: Edited by Moderator
Author: Klakx (Guest)
Posted on:

Rate this post
0 useful
not useful
normally this error occurs if you drive "segmento" from more than one 
process. But I think you have a real bigger problem with your clock 
description.
PROCESS(x, soma, subtracao, chave_sinal, clk)
 shows one problem. There should be a single asynchronous reset like
PROCESS(a_reset_n,clk)
 or only synchronous reset and signals. Then your sensitivity list is 
very clear:
PROCESS(clk)

The 2nd pitfall in coding metholodgy is the multiple use of the 
rising_edge(clk) (or clk'event ..). Your process should only have one 
use of this like
[vhdl]
process(clk)
begin
   if rising_edge(clk) then
      if (chave_sinal = '1') then
            if (x = 0) then
                if (clk 'event and clk='1') then
                   display <="11111110";
                   segmento <= "0000001";
                end if;
            end if; -- <-- this was also missing?
            else
               display <= "11111101";
               segmento <= "0000001";
            end if;
         [..]
   end if;

of course you have take a 2nd look of your cycle timing after rework
end process;

Author: Lothar Miller (lkmiller) (Moderator)
Posted on:

Rate this post
0 useful
not useful
ricardo wrote:
> I do not know where this error is.
The error itself is that you have multiple clocks in one megamonster 
process. Where did you learn this crude design mixed muddled practice? 
It must be your own idea, because I never saw anything roughly similar 
like that..

OK, having cleared that, one question: did you ever do a smaller design 
like a flashing LED or a chasing light?

> use ieee.numeric_std.all;
> use ieee.std_logic_unsigned.all;
> use ieee.std_logic_arith.all;
Never ever use the numeric_std together with the std_logic_arith libs. 
You will encounter some very weird error messages...

ricardo wrote:
> ... I do not know where this error is.
What do you try with that curious piece of code?
Is it some kind of counter on a 7 segment display?

Author: ricardo (Guest)
Posted on:

Rate this post
0 useful
not useful
I have to do sum and subtraction operations using 8 keys, for each 4bit 
binary number and the result appears on the decimal display. The LED 
indicates whether the result is negative or not

Author: ricardo (Guest)
Posted on:

Rate this post
0 useful
not useful
Sorry if my code is extensive but I'm new to vhdl and I do not have much 
idea how to do it

Thank you for your help

Author: Lothar Miller (lkmiller) (Moderator)
Posted on:

Rate this post
0 useful
not useful
ricardo wrote:
> Port(chaves_a, chaves_b: in std_logic_vector(3 downto 0);
>          led: inout bit;
>         led_1: inout bit;
>         segmento: out bit_VECTOR(0 TO 6);
>         chave_sinal: inout std_logic;
>         clk: in std_logic;
>         display: out bit_VECTOR(7 DOWNTO 0);
>          x: inout integer;
>         subtracao, soma: inout integer);
So, for that exercise for sure you will not need that much ports (BTW: 
using inout ports just for laziness eg. "easy way to read an output 
port" is a reason for being fired...). Simply 2x4 inputs for the 
switches, 7 outputs for the seven segment display, one output for the 
sign led, and one input for the operation (add/subtract). Am I missing 
one?
I don't think so.
You will need no clock because the whole design is completely 
combinatorial.

All in all it could be implemented in a lookup table with 9 inputs and 8 
outputs. So the implementation in a 512x8 RAM would be the most 
efficient way to solve the problem...

: Edited by Moderator
Author: Lothar Miller (lkmiller) (Moderator)
Posted on:
Attached files:

Rate this post
0 useful
not useful
The other way will be the more traditional one:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
use ieee.numeric_std.all;

entity colculadora_4bits is
Port(chaves_a, chaves_b: in std_logic_vector(3 downto 0);
     signled           : out std_logic;
     segmento          : out std_logic_vector(6 downto 0); -- Bit 6..0: segment F..A
     operation         : in std_logic                      -- 0 = add, 1 = subtract
     );
end colculadora_4bits;

architecture Behavioral of colculadora_4bits is
signal sresult : signed (3 downto 0);
signal uresult : unsigned (3 downto 0);
begin
   -- calculate the result (range -8 to +7)
   sresult <= signed(chaves_a) + signed(chaves_b) when operation='0' else
              signed(chaves_a) + signed(chaves_b);

   -- display the sign             
   signled <= sresult(3);

   -- make the remaining number unsigned (range 0 to +8) --> less definitions for display
   uresult <= unsigned(sresult) when sresult>0 else
              unsigned(-sresult);
   
   -- display the unsigned number 
   with uresult select segmento <= 
      "0111111" when "0000",    -- 0
      "0000110" when "0001",    -- 1
      "1011011" when "0010",
      "1001111" when "0011",
      "1100110" when "0100",
      "1101101" when "0101",
      "1111101" when "0110",
      "0000111" when "0111",
      "1111111" when others;    -- 8
   
end Behavioral;

And voila: according to the waveform in the testbench its running very 
fine... ;-)

: Edited by Moderator
Author: Andreas Schweigstill (Company: Schweigstill IT) (schweigstill)
Posted on:

Rate this post
0 useful
not useful
Lothar M. wrote:
>    sresult <= signed(chaves_a) + signed(chaves_b) when operation='0' else
>               signed(chaves_a) + signed(chaves_b);

> And voila: according to the waveform in the testbench its running very
> fine... ;-)

Are you sure? ;-)

Author: Lothar Miller (lkmiller) (Moderator)
Posted on:
Attached files:

Rate this post
0 useful
not useful
Andreas S. wrote:
> Are you sure? ;-)
Oooops, you are right.
With a '-' its working better. Let me say it was a little test...  ;-)

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig