EmbDev.net

Forum: FPGA, VHDL & Verilog Multiplexer Help


von john Wilson (Guest)


Rate this post
useful
not useful
Hi,
Im trying to implement a generic Mux on the spartan 3e using Xilinx ISE.
I am having issues with this,
I have an input, call it INPUT_A that can be Q bits wide and a select, 
SEL_B that is R bits wide. output is 3 bits
In the entity its like this:
generic R=2, Q=3
INPUT_A is a std_logic_vector (2**R)*Q downto 0);
SEL_B std_logic_vector (R-1 down to 0);
output std_logic_vector(Q downto 0);

I have the entity OK, but just cant get the device itself.
i have something like this for the actual device in one line:
output<INPUT_A((conv_integer(SEL_B)+1)*Q-1 downto conv_integer(SEL_B)*Q)

Can anyone give any ideas on this?
Thank you

von P. K. (pek)


Rate this post
useful
not useful
john Wilson wrote:
> output<INPUT_A((conv_integer(SEL_B)+1)*Q-1 downto conv_integer(SEL_B)*Q)

What is exatly your problem? This does not look so bad. Use correct 
assignments and type castings. The following line works perfectly for me 
(and may suit as  a starting point to you):
1
library ieee;
2
use ieee.STD_LOGIC_1164.all;
3
use ieee.numeric_std.all;
4
5
...
6
7
OutxD <= InxDI(10*pNr+ 9 downto 10*pNr);

where pNr is an integer, range limited to InxDI, all others are of type 
unsigned.

: Edited by User
von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
P. K. wrote:
> Use correct assignments and type castings.
And pls. do not use those use IEEE.STD_LOGIC_ARITH and 
IEEE.STD_LOGIC_UNSIGNED from the last millenium.

Use the numeric_std instead. It is straightforward and simple. Try that 
with Google translator (its German):
http://www.lothar-miller.de/s9y/categories/16-Numeric_Std

: Edited by Moderator
von John Wilson (Guest)


Rate this post
useful
not useful
Hi guys,
thanks for your replies.
Ive begun writing a test bench to test this.
Just a standard testbench without any error outputs to check the 
waveform when I simulate.
I'm having trouble trying to implement a testbench however.
I'm thinking I need two loops to test all possible inputs as the output 
relies on select?
any ideas on how to generic testbench this?
thanks guys

von John Wilson (Guest)


Rate this post
useful
not useful
Hi,

I wanted to know if anyone had some experience designing a testbench, 
for a generic multiplexer.

Select is M

the input is generic N

Im more concerned with the loop to make the testbench UUT go through all 
the possible combinations to confirm the correct otuputs?

any help guys

thanks

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
John Wilson wrote:
> Select is M
> the input is generic N
How do they relate to each other?
Show the code or at least the port definition of that multiplexer. There 
must be at least 3 signals to see: input(s), select and output


And pls: do not start every other day an new thread for the very same 
question! I concatenated them as they relate the same topic...

: Edited by Moderator
von John Wilson (Guest)


Rate this post
useful
not useful
Hi Lothar,
Thanks for the reply,
The code for the implementation is below, the synthesizer gives a 
warning for the implementation but its not the main issues. Its just im 
not sure how to do the testbench for a generic mux?
1
entity MUX is
2
GENERIC(N: INTEGER := 3;
3
        M: INTEGER := 2);
4
5
    Port ( myin : in  STD_LOGIC_VECTOR((2**M)*N-1 downto 0);
6
           myout : out  STD_LOGIC_VECTOR(N-1 downto 0);
7
           sel : in  STD_LOGIC_VECTOR (M-1 downto 0));
8
end MUX;
9
10
architecture Behavioral of MUX is
11
begin
12
--mux_proc:process(myin,sel)
13
--variable intnewsel:= conv_integer(sel);
14
--begin
15
myout<=myin((conv_integer(sel)+1)*N-1 downto conv_integer(sel)*N);
16
--end process;
17
end Behavioral;
18
19
20
21
22
23
24
25
26
27
28
ENTITY GENERIC_MUX_UUT IS
29
END GENERIC_MUX_UUT;
30
 
31
ARCHITECTURE behavior OF GENERIC_MUX_UUT IS 
32
 
33
    -- Component Declaration for the Unit Under Test (UUT)
34
 
35
    COMPONENT MUX
36
    PORT(
37
         myin : IN  std_logic_vector((2**M)*N-1 downto 0);
38
         myout : OUT  std_logic_vector(N-1 downto 0);
39
         sel : IN  std_logic_vector(M-1 downto 0)
40
        );
41
    END COMPONENT;
42
    
43
44
   --Inputs
45
   signal TX_in : std_logic_vector((2**M)*N-1 downto 0) := (others => '0');
46
   signal TX_sel : std_logic_vector(M-1 downto 0) := (others => '0');
47
48
   --Outputs
49
   signal TX_out : std_logic_vector(N-1 downto 0);
50
51
 
52
53
 
54
BEGIN
55
 
56
  -- Instantiate the Unit Under Test (UUT)
57
   uut: MUX PORT MAP (
58
          myin => TX_in,
59
          myout => TX_out,
60
          sel => TX_sel
61
        );
62
63
   -- Clock process definitions
64
65
66
   -- Stimulus process
67
   MUX_UUT: process
68
  variable vmyout:std_logic_vector (N-1 downto 0);
69
   begin    
70
   for i in 0 to 2**M LOOP
71
    vmyout := Tx_in(i);
72
    wait for 100 ns;  
73
74
End Loop;   
75
    -- hold reset state for 100 ns.
76
     
77
78
79
      -- insert stimulus here 
80
81
      wait;
82
   end process;
83
myout<=vmyout;
84
END;

: Edited by Moderator
von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Attached files:

Rate this post
useful
not useful
First: READ THE MANUAL.
And the manual for the editbox here ist just a few lines above:
1
Rules — please read before posting
2
    :
3
Formatting options
4
    :
5
    [vhdl]VHDL code[/vhdl]


John Wilson wrote:
> The code for the implementation is below ...
> entity MUX is
Did you know: each VHDL code sarts well before the keyword "entity".
All of mine start with "library"...

> conv_integer
A lttle reminder: https://embdev.net/topic/377905?goto=4300680#4292803

> myout <= vmyout;
You cannot assign a value to an output. Have a closer look to the 
signals direction, it was you giving them that names...

> variable vmyout:std_logic_vector (N-1 downto 0);
> vmyout := Tx_in(i);
> myout <= vmyout;
A little poking around in the dark?
1. You do not need a variable here...
2. Why do you read a value from a port, where you should hand over a 
input value, and write it to a port, where an output is assigned by 
the UUT?

To keep things subtantially short: have a very close look at my 
design...

: Edited by Moderator
von John Wilson (Guest)


Rate this post
useful
not useful
Hi Lothar,
Thank you very much for your help, I really appreciate it.
I was as you rightly guessed poking in the dark  in some places.
Ive looked over your code and it makes a lot of sense.
i did try running  a simulation, it passes the behavioral check without 
issues, the muxout however doesn't generate the result you got from your 
simulation.
thank you

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
John Wilson wrote:
> the muxout however doesn't generate the result you got from your
> simulation.
What instead?
Did you use exactly my code?
Can you show a screenshot of your simulations waveform?
What simulator did you use? (Mine was ISIM from ISE14.2)

von Rukhsana (Guest)


Rate this post
useful
not useful
Oi murilo, em geral he1 2  cinomhas  pra seguir na busca por reduzir o 
espae7o ocupado pelo cf3digo no FPGA:1) Regular as configurae7f5es da 
tua ferramenta de sedntese (ISE, Quartus, etc). Vocea pode tentar 
aumentar o nedvel de otimizae7e3o pra espae7o (vai aumentar bastante seu 
tempo de sedntese), pode tentar mudar a codificae7e3o das suas me1quinas 
de estados (usar menos bits), ou ente3o pode tentar colocar o 
armazenamento em BRAMs ao inve9s de em flip-flops (tem uma 
configurae7e3o no ISE pra isso, mas eu ne3o me lembro onde).2) Diminuir 
o paralelismo no seu design: Essa alternativa je1 e9 mais difedcil, mas 
vai resultar numa mudane7a maior no espae7o ocupado no FPGA. O objetivo 
e9 vocea tentar localizar blocos no seu cf3digo VHDL em que operae7f5es 
se3o feitas em paralelo, ou seja, em que he1 replicae7e3o de hardware. 
Daed vocea deve tentar serializar essas operae7f5es, usando por exemplo 
uma me1quina de estados para controlar a sequeancia.  No exemplo do 
somador do post, a gente poderia ter usado apenas UM FULL-ADDER de 1 
bit, ao inve9s de N. Isso iria diminuir o espae7o ocupado na FPGA.Espero 
ter te ajudado um pouco, e ne3o confundido mais :)

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.