Chip123 科技應用創新平台

 找回密碼
 申請會員

QQ登錄

只需一步,快速開始

Login

用FB帳號登入

搜索
1 2 3 4
查看: 9585|回復: 6

[問題求助] VHDL转verilog问题

[複製鏈接]
發表於 2008-12-29 14:16:18 | 顯示全部樓層 |閱讀模式
手里面有个VHDL写的FIFO,现在想转换成VERILOG的
3 n6 S% S6 q. N; `3 E' ]- Z$ Q原代码如下

  1. ) p+ l6 u/ Q2 {) |) U

  2. - ~2 N5 V  T  o
  3. CNT: process(CLR, WR_PTR, RD_PTR)
    - j# p; ]0 K+ U# y
  4.   variable change : integer;  4 q5 }/ a# q3 W. j( C
  5. begin  
    5 [8 ^; y. B3 Z+ j
  6.   if CLR = '1' then
    3 \' c' m. Z- J7 ~
  7.    count <= 0;
    6 _2 O0 [* ]$ Y, E! {% Y4 O7 |
  8.    change := 0;+ ]6 @. o& P3 |0 C& T1 K3 C- m3 n8 @
  9.   else+ K8 p- F  L' U+ |
  10.    change := 0;
    6 ]4 S3 O2 z# D+ r
  11.    if WR_PTR'event then
    + B( J! N( R  f. x" V
  12.     change := 1;
    4 S$ K/ }  s. C) A1 V
  13.    end if;
    . G, h3 |$ l! J3 Y! X( e$ a. U5 F3 L
  14.    if RD_PTR'event then
    % l  A# o( Y0 w) e2 L
  15.     change := change - 1;& M2 @" C$ W. B1 F0 U% }4 ~
  16.    end if;
    / R1 X) Q+ |" K  |. N' h
  17.    count <= count + change;& T  K4 D. S; C2 S7 z
  18.   end if;+ d# ]: W( u' o. a- }
  19. end process;
複製代碼
不知道改为Verilog该怎么写红色部分。
; M( i1 _8 @. p# U* s/ [: S( p. y我想是用always@( WR_PTR)8 X8 d1 h9 ?0 }7 F7 p8 a
但是process(CLR, WR_PTR, RD_PTR)这一句已经用了always了,没办法,刚接触verilog,请大家帮帮忙
發表於 2009-1-5 12:41:03 | 顯示全部樓層
這個fifo程式有問題喔,沒有clock訊號,很奇怪.
 樓主| 發表於 2009-1-6 16:31:33 | 顯示全部樓層
这个FIFO程式有CLK的,我这里只是一部分代码,没有将所有代码贴出来,只是希望大家告诉我该怎么写if WR_PTR'event then
發表於 2009-1-7 11:42:34 | 顯示全部樓層
1. VHDL clock 語法好像不太對,應該是 if WR_PTR'event and WR_PRT='1' then
$ b! e% T+ |& O  x' R" R1 }2. count 沒有clock!你可能需要把全部貼出來,看是不是漏掉了?6 t/ a; H1 \  ]1 h
3. 一個process有兩個clock,一般不會這樣寫的。
 樓主| 發表於 2009-1-10 22:11:05 | 顯示全部樓層
  1. ------------------------------------------------------------------------------------
    8 w  O: m3 N0 p: F- g- y
  2. library IEEE;. h3 `0 Y1 i, U1 C# D
  3. use IEEE.std_logic_1164.all;) O9 z+ j9 m& `1 R
  4. entity fifo is7 n$ P- l* U6 b3 B  q# C1 S. R% `3 K( R, o
  5.         generic (
    . _4 a7 ~2 k1 y* R" d6 @: y
  6.                 depth : positive := 164 M! S8 ]4 f# O$ U5 {
  7.                 );       
    7 h5 [5 y/ X8 R$ }
  8.         port(
    + b8 N( \  ]7 L
  9.                 CLR   : in  std_logic;
    0 R& r# Z  ]# z: u
  10.                 WCLK  : in  std_logic;
    7 d1 i7 x- n& o0 r. z  P4 A5 |$ G
  11.                 WE    : in  std_logic;9 v* j& n  P! y, @0 X" U2 O
  12.                 RCLK  : in  std_logic;
    ; a4 X% F: _: e0 J9 H
  13.                 RE    : in  std_logic;
    5 e6 H/ C1 Y& R$ M
  14.                 DATA  : in  std_logic_vector(7 downto 0);
      F3 r+ O( D- O( f# o: R4 F$ C+ V& t
  15.                 EMPTY : out std_logic;/ P6 ]; F# C& I4 s, R
  16.                 FULL  : out std_logic;# U( s+ I% _+ ^9 P" Y  i7 @
  17.                 Q     : out std_logic_vector(7 downto 0)' \! W7 a4 k; X6 q! v  \; F- ]
  18.         );
    / H5 K% L" B, j& x+ |1 q
  19. end entity;2 ~4 z* S) v( X  D  \+ @3 z
  20. library IEEE;
    " l& A  X6 u7 Z+ f+ g0 |& k0 [" q1 v
  21. use IEEE.std_logic_unsigned.all;
    1 m7 y$ ]/ |% Y- [" k1 G4 A+ W
  22. architecture behavior of fifo is
    0 s& |* _8 ?1 @% B
  23.         constant fmax : positive := depth-1;       
    / }1 b% ]! Q7 W
  24.         type fifo_array_type is array (fmax downto 0) of std_logic_vector(7 downto 0);
      v6 K. F3 W: j3 @  H* a  I7 ?
  25.         signal fifo_array : fifo_array_type;
    2 O4 x4 P, S& S- W; K% C/ ^. ?: {
  26.         signal WR_PTR : INTEGER range 0 to fmax;' C) k/ D, P5 p$ l1 `) R
  27.         signal RD_PTR : INTEGER range 0 to fmax;9 A3 \. Y3 F- H9 b8 O
  28.         signal count  : INTEGER range 0 to depth;& M$ M9 S+ M, D2 \2 O
  29. begin) b' P" @+ C& Y. ]6 P
  30.         CNT: process(CLR, WR_PTR, RD_PTR)
    ' m' P9 e7 w& H) e; R7 r
  31.                 variable change : integer;               
      |: t( j6 E# Q# l% Q4 c$ i
  32.         begin  
    9 a9 G$ }* f- ^# c6 m3 Q- M% n
  33.                 if CLR = '1' then
    6 p5 o; v, c& p7 s/ A
  34.                         count <= 0;
    2 A8 v0 X6 A; r! W# R8 j9 y
  35.                         change := 0;
    : b% `4 x1 X7 T) ^. p6 G0 G# K3 `
  36.                 else8 Y' y) L- V9 D" w
  37.                         change := 0;
    6 n% f: l$ u7 i  m4 P
  38.                         if WR_PTR'event then9 Y# G$ B% E. s* `
  39.                                 change := 1;2 v& G  a0 b: |. ~* y. u
  40.                         end if;9 H0 _$ u4 w, {5 V
  41.                         if RD_PTR'event then' t7 @3 ^( w! ~+ G" A3 P0 L: _
  42.                                 change := change - 1;6 O5 [, V+ p; H% e
  43.                         end if;6 Q. H7 W& g& ]1 W; W% R& M9 f  J
  44.                         count <= count + change;3 g: ^9 p1 R) C: l! N- u$ R
  45.                 end if;# s0 w! g9 `/ |9 P% J2 E
  46.         end process;        ! J) i! s0 z% ~* X- J
  47.         STATUS: process(count)
    3 `; s1 v5 N( v) b) U
  48.         begin  
    6 P$ Q9 Q& E( d
  49.                 if count=0 then
    4 w" a/ }* b" v+ Z" x( C2 j* B/ t, n
  50.                         FULL   <= '0';% L( D! l1 D% j% M4 V9 `- w
  51.                         EMPTY  <= '1';/ k* k( j1 @* J1 x$ A" N: \
  52.                 elsif count=depth  then4 Z) q1 U% h: I% _3 \2 {
  53.                         FULL   <= '1';
    # M2 w  X! r, }- [' M6 G/ |2 O; y
  54.                         EMPTY  <= '0'; & ~# i. ~* _8 P$ t' M
  55.                 else       
    ) `" _  N% I! I% N
  56.                         FULL   <= '0'; - o1 f% c; {0 D! U+ T
  57.                         EMPTY  <= '0'; * C3 Q6 U2 h7 ^4 ?- R7 E, B
  58.                 end if;                       
      j8 @& m5 f/ ~0 R2 n
  59.         end process;       
複製代碼
 樓主| 發表於 2009-1-10 22:13:00 | 顯示全部樓層
  1.         FWRITE: process (CLR, WCLK)
      S9 {! z; Y; u. `: y
  2.         begin
    : L9 H) H5 H* u; E, |: A& v) x0 i
  3.                 if CLR = '1' then& D. ^! `) Z- H2 J
  4.                         for INDEX in fmax downto 0 loop
    + u7 Y7 w& c1 U9 D
  5.                                 fifo_array(INDEX) <= (others => '0');
    % q1 x1 V9 s& I# r4 n& Y. y  Q
  6.                         end loop;
    ' P% q2 ^$ |( T
  7.                         WR_PTR <= 0;
    ! _" |) c' a7 v* ?8 }
  8.                 elsif rising_edge(WCLK) then& w/ }+ |. h4 @; ~3 A8 q
  9.                         if WE = '1' and count<depth then5 q" @9 Q, e, {" }  ~7 v
  10.                                 fifo_array(WR_PTR) <= DATA;. d' s+ n  L/ }5 f  P, S
  11.                                 -- move pointer
    " l6 A# e* z+ `3 F6 }
  12.                                 if WR_PTR=fmax then
    2 @# t  o$ i, u/ W; o
  13.                                         WR_PTR <= 0; 5 c/ n8 p! c1 h' X
  14.                                 else WR_PTR <= WR_PTR + 1;! Z- F) b# f! T1 E! X7 S- B! z
  15.                                 end if;
    6 E/ `* g) m5 @& N
  16.                         end if;! x; b6 O$ B, m. X7 Y- f8 x7 M
  17.                 end if;( f5 O" J3 q7 k( [. G
  18.         end process;
    ) p. \+ Y/ I  V$ j3 \8 }* H
  19.         FREAD: process (CLR, RCLK)
    % O: O* R% ]9 s( x
  20.         begin9 J& y$ E9 X$ V
  21.                 if CLR = '1' then* L# Q. O, D+ E5 m1 Q& U$ n
  22.                         RD_PTR <= 0;
    9 _0 p* E0 G, h7 O, F& v# Z& [" S
  23.                 elsif falling_edge(RCLK) then! j8 i& x6 \% [
  24.                         if RE = '1' and count>0 then
    ( p. u7 d* ~+ A
  25.                                 Q <= fifo_array(RD_PTR);
    . o( e& B  k( I2 C2 |- Q
  26.                                 -- move pointer
    6 Q2 Y8 h! S7 Y; h! `6 I# @7 E7 z
  27.                                 if RD_PTR=fmax then ) r. V; D* P# C+ _+ G5 a
  28.                                         RD_PTR <= 0; ) e8 T! B/ r9 j, L0 ?9 M/ U( i8 F
  29.                                 else RD_PTR <= RD_PTR + 1;* f8 ~% @" p3 p
  30.                                 end if;
    4 Z- m. o3 c/ i2 }
  31.                         end if;3 r! O+ S6 x: `9 o) g- s+ T0 n( l
  32.                 end if;- b* e3 d; p* h$ K( q/ g  a4 p
  33.         end process;
      W( d8 ~( g0 L5 a
  34. end architecture;
複製代碼
發表於 2009-7-4 00:42:31 | 顯示全部樓層
印象中有个工具可以转vhdl 为 verilog,可以看看,或许有用
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

首頁|手機版|Chip123 科技應用創新平台 |新契機國際商機整合股份有限公司

GMT+8, 2024-4-18 07:42 PM , Processed in 0.121007 second(s), 19 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表