EmbDev.net

Forum: FPGA, VHDL & Verilog Query regarding 32bits ALU design


von NIDHI K. (Company: STUDENT) (n_khanna)


Rate this post
useful
not useful
I want to implement 32bits alu on nexys4 ddr fpga board but there is an 
issue regarding I/O pins number board has total 16 input pins so i was 
tring to write the code as follow- but i am not getting the simulation 
results outputs are coming as unsigned
1
ibrary IEEE;
2
use IEEE.STD_LOGIC_1164.ALL;
3
use IEEE.STD_LOGIC_ARITH.ALL;
4
use IEEE.STD_LOGIC_UNSIGNED.ALL;
5
entity alu_32 is
6
port ( clk,reset : in std_logic;
7
          sel : in std_logic_vector(2 downto 0);
8
       a,b : in std_logic_vector(31 downto 0);
9
       y : out std_logic_vector(31 downto 0) );
10
end alu_32;
11
12
architecture Behavioral of alu_32 is
13
  --signal a : std_logic_vector(31 downto 0) ;
14
  --signal  a,b : std_logic_vector(31 downto 0);
15
  signal count1,count2 : std_logic_vector (1 downto 0);
16
  signal atemp, btemp ,atemp1, btemp1: std_logic_vector(15 downto 0);
17
  signal y1,y2  :std_logic_vector(31 downto 0);
18
  begin
19
process(clk)
20
begin
21
      if (reset='1')then
22
     y<="00000000000000000000000000000000";
23
     end if;
24
    if (rising_edge(clk)) then 
25
      if count1 ="11" then
26
      count1 <= "00";
27
      else 
28
      count1 <= count1 + 1;
29
      end if;
30
    end if;
31
        if  count1 = "00" then
32
       atemp <= y1(31 downto 16);
33
       elsif 
34
       count1 = "01" then
35
       btemp <= y1(15 downto 0);
36
       elsif
37
       count1 ="10" then
38
       a<= atemp & btemp;
39
     end if;
40
     
41
      if  count2 = "00" then
42
       atemp1 <= y2(31 downto 16);
43
       elsif 
44
       count2 = "01" then 
45
       btemp1 <= y2(15 downto 0);
46
       elsif 
47
       count2 ="10" then
48
       b<= atemp1 & btemp1;
49
     end if;   
50
end process;
51
PROCESS (sel)
52
begin
53
 case sel is
54
 when "001" => y <=  (a - b) ;
55
 when "010" => y <=  not (a) ;
56
 when "011" => y <=  (a xor  b) ;
57
 when "100" => y <=  (a + b) ;
58
 when "101" => y <=(a and b) ;
59
 when "110" => y <=  (a or b) ;
60
 when others => y <=  (a nand  b) ;
61
 End case ;
62
 end process ;
63
end Behavioral;
64
----------------------------------------------------------------
65
TESTBENCH 
66
67
68
LIBRARY ieee;
69
USE ieee.std_logic_1164.ALL;
70
USE ieee.std_logic_unsigned.all;
71
USE ieee.numeric_std.ALL;
72
73
ENTITY test32bit_vhd IS
74
END test32bit_vhd;
75
76
ARCHITECTURE behavior OF test32bit_vhd IS 
77
78
  -- Component Declaration for the Unit Under Test (UUT)
79
  COMPONENT alu32
80
  PORT(
81
    clk ,reset: IN std_logic;
82
    sel : IN std_logic_vector(2 downto 0);    
83
    a : INOUT std_logic_vector(31 downto 0);
84
    b : INOUT std_logic_vector(31 downto 0);      
85
    y : OUT std_logic_vector(31 downto 0)
86
    );
87
  END COMPONENT;
88
89
  --Inputs
90
  SIGNAL clk :  std_logic := '0';
91
  SIGNAL reset :  std_logic := '0';
92
  SIGNAL sel :  std_logic_vector(2 downto 0) := (others=>'0');
93
94
  --BiDirs
95
  SIGNAL a :  std_logic_vector(31 downto 0);
96
  SIGNAL b :  std_logic_vector(31 downto 0);
97
98
  --Outputs
99
  SIGNAL y :  std_logic_vector(31 downto 0);
100
  constant clkperiod : time := 100 ns;
101
102
BEGIN
103
104
  -- Instantiate the Unit Under Test (UUT)
105
  uut: alu32 PORT MAP(
106
    clk => clk,
107
    reset => reset,
108
    sel => sel,
109
    a => a,
110
    b => b,
111
    y => y
112
  );
113
114
  clk_process : process
115
116
117
  BEGIN
118
119
clk <= '0';
120
wait for clkperiod/2 ;
121
clk <= '1';
122
wait for clkperiod/2;
123
end process;
124
125
stimproces : process
126
begin 
127
    wait for 100 ns;
128
    wait for 50 ns;
129
    
130
    reset <= '1';
131
    
132
    
133
    wait for 100 ns;
134
    reset <= '0' ;
135
    
136
    wait for 100 ns;
137
    a <= "01011101010100111110000101100010";
138
    b <= "00111100101011111100111001100111";
139
    --enable <= '1';
140
    
141
    sel <= "001";
142
    
143
    wait for 200 ns;
144
    sel <= "010";
145
    
146
    wait for 200 ns;
147
    wait; -- will wait forever
148
  END PROCESS;
149
150
END;

PLZ tell me the mistake i am doing in writing the codes

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


Rate this post
useful
not useful
NIDHI K. wrote:
> i was tring to write the code as follow
Pls read and follow the instructions above every edit box. Here a 
summary:
1
Reply
2
Rules — please read before posting
3
    Post long source code as attachment, not in the text
4
Formatting options
5
    [vhdl]VHDL code[/vhdl]

NIDHI K. wrote:
> PLZ tell me the mistake i am doing in writing the codes
What simulation result do you get and what did you expect?

>    if (reset='1')then
>       y<="00000000000000000000000000000000";
>    end if;
>    if (rising_edge(clk)) then ...
It is not possible to synthesize this, because its some kind of "clock 
sensitive despite reset" construct. I'm pretty sure you will not find 
such a piece of code elsewhere...

> but i am not getting the simulation results outputs are coming as
> unsigned
Do you 1. not get a result or 2. do you get an unsigned result?

> a : INOUT std_logic_vector(31 downto 0);
> b : INOUT std_logic_vector(31 downto 0);
Why the heck an inout here?
The components port must fit the entitys port.

> USE ieee.std_logic_unsigned.all;
> USE ieee.numeric_std.ALL;
Never ever use both of the packages together, because you may encouter 
strange errors due to double type definitions. I urge you to use only 
the numeric_std.

> PROCESS (sel)
> begin
In ths process sensitivity list the signals a and b are missing. That 
means your simulation is 1. wrong and 2. does not match the reality.


>        if  count1 = "00" then
>        atemp <= y1(31 downto 16);
>        elsif
>        count1 = "01" then
>        btemp <= y1(15 downto 0);
>        elsif
>        count1 ="10" then
>        a <= atemp & btemp;
This is kind of nonsense: splitting up a vector y1 and then 
concatenating it in three steps to the previous value. What is it good 
for?

> entity alu_32 is
> port ( clk,reset : in std_logic;
An Arithmetic Logic Unit usually does NOT have or need a clock. Why does 
yours?

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.