VHDL Arithmetik

OP #5621516
Lesenswert?

1
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.numeric_std.all;
4

5
entity dac_dsm2 is
6
  
7
  generic (
8
    nbits : integer := 16);
9

10
  port (
11
    din   : in  signed((nbits-1) downto 0);
12
    dout  : out std_logic;
13
    clk   : in  std_logic;
14
    n_rst : in  std_logic);
15

16
end dac_dsm2;
17

18
architecture beh1 of dac_dsm2 is
19

20
  signal del1, del2, d_q : signed(nbits+2 downto 0) := (others => '0');
21
  constant c1            : signed(nbits+2 downto 0) := to_signed(1, nbits+3);
22
  constant c_1           : signed(nbits+2 downto 0) := to_signed(-1, nbits+3);
23
begin  -- beh1
24

25
  process (clk, n_rst)
26
  begin  -- process
27
    if n_rst = '0' then                 -- asynchronous reset (active low)
28
      del1 <= (others => '0');
29
      del2 <= (others => '0');
30
      dout <= '0';
31
    elsif clk'event and clk = '1' then  -- rising clock edge
32
      del1 <= din - d_q + del1;
33
      del2 <= din - d_q + del1 - d_q + del2;
34
      if din - d_q + del1 - d_q + del2 > 0 then
35
        d_q  <= shift_left(c1, nbits);
36
        dout <= '1';
37
      else
38
        d_q  <= shift_left(c_1, nbits);
39
        dout <= '0';
40
      end if;
41
    end if;
42
  end process;
43
  
44

45
end beh1;
Normalerweise programmiere ich in Verilog. Jetzt will ich den oben 
angegebenen VHDL Code nach Verilog portieren. Da ich mich mit VHDL gar 
nicht auskenne, tauchen natürlich ein paar Fragen auf.

Nehmen wir mal an, der Parameter nbits ist 4.

Ist es dann richtig, dass c1=0000001 ist und c_1=1111111 ?
Ist es dann richtig, dass
shift_left(c1 , nbits) = 0010000 ist und
shift_left(c_1, nbits) = 1110000 ist ?
#5621626
Lesenswert?

Martin O. schrieb:
> Ist es dann richtig, dass c1=0000001 ist und c_1=1111111 ?

Ja, das sehe ich auch so.

> Ist es dann richtig, dass
> shift_left(c1 , nbits) = 0010000 ist und
> shift_left(c_1, nbits) = 1110000 ist ?

Zitat aus der numeric_std.vhdl:
1
-- Id: S.3
2
function SHIFT_LEFT (ARG: SIGNED; COUNT: NATURAL) return SIGNED;
3
-- Result subtype: SIGNED(ARG'LENGTH-1 downto 0)
4
-- Result: Performs a shift-left on a SIGNED vector COUNT times.
5
--         The vacated positions are filled with '0'.
6
--         The COUNT leftmost elements are lost.

Also ja.

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren