EmbDev.net

Forum: FPGA, VHDL & Verilog Looking for help in design of 16bit processor (vhdl)


von Sad S. (Company: Trancefamily) (xsound)


Attached files:

Rate this post
useful
not useful
Hi guys, I need some help in simply (for people who know vhdl quite 
well) project of processor. Below I put project assumptions, some of 
them are already done, but highly possible that are wrong wrote in vhdl. 
Please, any kind of help I will never do it myself.

Processor project:
Data bus and address bus are 16 bits.

1) List of commands:
* MOV arg1, arg2 - shift arg2 in arg1 (arg1 - register, arg2 - address 
or register)
* ADD arg, arg2 - addition arg2 to arg1, result in arg1 (arg1 - 
register, arg2 - address or register)
* SUB arg, arg2 - substraction arg2 from arg1 result in arg1 (arg1 - 
register, arg2 - address or register)
* BINtoBCD arg1 (conversion value binary into BCD, result in arg1)
* RDCTRL arg1 (load register marker to arg1 - register or address in 
memory)
* WRCTRL arg1 (record register marker from arg1 - register or address in 
memory)
* ASHL arg1, arg2 (arithmetic shift into left of value in arg1 of 
arg2-bits; arg1 -register, arg2 - register or constant 3-bit, result in 
arg1)
* ASHR arg1, arg2 (arithmetic shift into right of value in arg1 of 
arg2-bits; arg1 -register, arg2 - register or constant 3-bit, result in 
arg1)

IF it is needed, set markers C,Z,S,P.

2)Records (registers)
* ES - register of segment (16 bit register stores the address of the 
block)
* AP1, AP2 - registers address 8 bit for stores address of shift)

3)System of cooperation with memory - way of segmentation
Range segments: 9 bits
Range shifts: 7 bits

I attached files with clear code were received from leader from my 
univesity - everything was done in Quartus12.

I noticed here many people well know vhdl, and I guess for you it's few 
minutes. IF someone could look at code, would be great.
Many thanks in advance.


And below I also attached what is done (but probably wrong - many errors 
while trying to compile code)
ALU:
1
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.numeric_std.all;
4
5
entity ALU is
6
    port ( A : in signed(15 downto 0);
7
        B : in signed(15 downto 0);
8
        Salu : in bit_vector (3 downto 0);
9
        LDF : in bit;
10
        clk : in bit;
11
        Y : out signed (15 downto 0);
12
        C,Z,S : inout std_logic
13
        
14
    );
15
end entity;
16
 
17
function to_bcd ( bin : std_logic_vector(7 downto 0) ) return std_logic_vector is
18
      variable i : integer:=0;
19
      variable bcd : std_logic_vector(11 downto 0) := (others => '0');
20
      variable bint : std_logic_vector(7 downto 0) := bin;
21
22
    begin
23
      for i in 0 to 7 loop  -- repeating 8 times.
24
      bcd(11 downto 1) := bcd(10 downto 0);  --shifting the bits.
25
      bcd(0) := bint(7);
26
      bint(7 downto 1) := bint(6 downto 0);
27
      bint(0) :='0';
28
29
30
    if(i < 7 and bcd(3 downto 0) > "0100") then --add 3 if BCD digit is greater than 4.
31
      bcd(3 downto 0) := bcd(3 downto 0) + "0011";
32
      end if;
33
34
    if(i < 7 and bcd(7 downto 4) > "0100") then --add 3 if BCD digit is greater than 4.
35
      bcd(7 downto 4) := bcd(7 downto 4) + "0011";
36
      end if;
37
38
    if(i < 7 and bcd(11 downto 8) > "0100") then  --add 3 if BCD digit is greater than 4.
39
      bcd(11 downto 8) := bcd(11 downto 8) + "0011";
40
      end if;
41
42
43
      end loop;
44
    return bcd;
45
end to_bcd;
46
 
47
 
48
architecture rtl of ALU is
49
  begin
50
        process (Salu, A, B, clk)
51
        variable res, AA, BB,CC: signed (16 downto 0);
52
        variable CF,ZF,SF : std_logic;
53
        begin
54
        AA(16) := A(15);
55
        AA(15 downto 0) := A;
56
        BB(16) := B(15);
57
        BB(15 downto 0) := B;
58
        CC(0) := CF;
59
        CC(16 downto 1) := "0000000000000000";
60
        case Salu is
61
              when "0000" => res := AA; -- mov
62
              when "0010" => res := AA + BB; --add
63
              when "0011" => res := AA - BB; --sub
64
              when "0001" => res := to_bcd(AA); -- BINtoBCD 
65
              
66
              when "1111" => res(16) := AA(16);
67
              res(15 downto 0) := AA(16 downto 1); --shift (wrong!)
68
        end case;
69
        Y <= res(15 downto 0);
70
        Z <= ZF;
71
        S <= SF;
72
        C <= CF;
73
        if (clk'event and clk='1') then
74
              if (LDF='1') then
75
                    if (res = "00000000000000000") then ZF:='1';
76
                    else ZF:='0';
77
                    end if;
78
              if (res(15)='1') then SF:='1';
79
              else SF:='0'; end if;
80
              CF := res(16) xor res(15);
81
              end if;
82
        end if;
83
      end process;
84
end rtl;

von Onkel Kapotto (Guest)


Rate this post
useful
not useful
Where is the block diagram, where is the testbench, where is the 
simulation output, where are the questions?

von krumeltee (Guest)


Rate this post
useful
not useful
Why rar?!

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


Rate this post
useful
not useful
Its really a horrible bad coding style to implement all of the function 
in 1 monster process, which is halfway combinatorial an halfway clocked. 
Where the heck did you see something like this?

> many errors
And now we must guess which ones? Hmm, lets see... Ah, I have one:
With the numeric_std you cannot add something to a std_logic_vector.
     bcd(3 downto 0) := bcd(3 downto 0) + "0011";

As far as I see you are a software guy doing VHDL. I can see that in the 
extensive use of variables and also a function. A beginners design 
(as yours is) will not need either of them both.


All in all: you are far more away from the solution than you think...

Split your work in smaller steps: first simulate and debug the BCD 
conversion.

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.