Chip123 科技應用創新平台

 找回密碼
 申請會員

QQ登錄

只需一步,快速開始

Login

用FB帳號登入

搜索
1 2 3 4
查看: 9617|回復: 6
打印 上一主題 下一主題

[問題求助] VHDL转verilog问题

[複製鏈接]
跳轉到指定樓層
1#
發表於 2008-12-29 14:16:18 | 顯示全部樓層 回帖獎勵 |倒序瀏覽 |閱讀模式
手里面有个VHDL写的FIFO,现在想转换成VERILOG的
5 y$ i2 M( ~- ~1 q原代码如下

  1. ( k; B( Z6 Y1 g7 z+ Y
  2. , D  `: W/ K/ r/ O+ r% @
  3. CNT: process(CLR, WR_PTR, RD_PTR)0 s1 Y0 F- |: V6 w$ L
  4.   variable change : integer;  : `2 z3 X4 ~# N2 N2 Z  Q* x! \5 V
  5. begin  7 L1 {/ c/ G# b5 Q
  6.   if CLR = '1' then! w+ X, J7 v$ ]: T* h. g: a
  7.    count <= 0;" A  ?6 d0 W7 E' L4 R
  8.    change := 0;
    . J6 {, F" w5 I0 r
  9.   else+ O: w( \0 G; j' l1 v  [  r3 S9 c
  10.    change := 0;
    8 K- }2 Q. D+ m- K- O
  11.    if WR_PTR'event then! h4 O; K: y- X& f, C- O5 ]0 g) R0 z
  12.     change := 1;  t2 b+ f% k' Y7 O" N- W8 h
  13.    end if;) s3 r) a; w- }) R2 V+ s& d& ?
  14.    if RD_PTR'event then9 o# l$ C9 H2 S# Z; X
  15.     change := change - 1;
    1 Q. _! C1 N7 F5 J
  16.    end if;
      h, ]7 m7 i/ p" l, W# R/ j
  17.    count <= count + change;6 U: V; T3 c, T) k) x  M
  18.   end if;
    6 A, I. v2 z: m9 W
  19. end process;
複製代碼
不知道改为Verilog该怎么写红色部分。# e4 b( O0 k* g9 W
我想是用always@( WR_PTR)
; L& _8 f, f, g/ p0 {% k0 W2 _但是process(CLR, WR_PTR, RD_PTR)这一句已经用了always了,没办法,刚接触verilog,请大家帮帮忙
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 頂 踩 分享分享
2#
 樓主| 發表於 2009-1-6 16:31:33 | 顯示全部樓層
这个FIFO程式有CLK的,我这里只是一部分代码,没有将所有代码贴出来,只是希望大家告诉我该怎么写if WR_PTR'event then
3#
 樓主| 發表於 2009-1-10 22:11:05 | 顯示全部樓層
  1. ------------------------------------------------------------------------------------& Z  ~" h" s  R% ]$ h9 X
  2. library IEEE;. U& O3 i( \6 P) a6 S& g9 U3 V6 c9 T$ W
  3. use IEEE.std_logic_1164.all;0 C6 y1 r5 u& ^/ c* o8 s
  4. entity fifo is; Z' i$ Q7 m, |% R
  5.         generic (
    8 ~. t/ l9 g7 k0 d5 i( o$ O
  6.                 depth : positive := 16
    & N( Z, ~( D' B7 \* G. s0 w
  7.                 );        ( M, k: E4 n' O; D1 j2 o
  8.         port(
    4 z: I) N1 ~4 W
  9.                 CLR   : in  std_logic;% u$ B7 a4 ]$ Q" e& D" o+ e' B2 |
  10.                 WCLK  : in  std_logic;! c1 p9 A6 c5 e3 k2 K
  11.                 WE    : in  std_logic;/ {% v( v4 T  a# r! W
  12.                 RCLK  : in  std_logic;+ h+ R1 Q0 d6 W4 i5 U9 d9 q5 n6 b
  13.                 RE    : in  std_logic;
    ' O. H" [* w& N/ s. w4 H; ~
  14.                 DATA  : in  std_logic_vector(7 downto 0);
    5 [, Q& c8 u4 N. _
  15.                 EMPTY : out std_logic;! v/ m; k- g0 M2 [2 M
  16.                 FULL  : out std_logic;  U% {. x, C/ M- p& v
  17.                 Q     : out std_logic_vector(7 downto 0)& I4 g. W( Q. ?" J  B
  18.         );# s( ~6 l6 p) l  U4 D
  19. end entity;% }" D+ O+ n: x! a& V
  20. library IEEE;
    2 K  {9 f+ T5 o& X, B
  21. use IEEE.std_logic_unsigned.all;
    & A8 Y' q& ^( C2 n0 b5 k
  22. architecture behavior of fifo is
    ) @9 V: @: q% _* e$ u6 R/ y9 S" y: Y
  23.         constant fmax : positive := depth-1;       
    - G, j( Q: q* z: B4 g2 s1 V
  24.         type fifo_array_type is array (fmax downto 0) of std_logic_vector(7 downto 0);/ |+ z% O$ f3 G+ i; S; y
  25.         signal fifo_array : fifo_array_type;
    9 v( p! {2 W( m6 Y9 l
  26.         signal WR_PTR : INTEGER range 0 to fmax;! e$ {$ D5 ^* i* @& G
  27.         signal RD_PTR : INTEGER range 0 to fmax;6 F- t2 m) w3 @" H1 k0 a+ ]: ^
  28.         signal count  : INTEGER range 0 to depth;
    3 z0 m! i6 ?' K- _) m
  29. begin  S2 \, _$ A: M  W' {0 t4 |! ?) j
  30.         CNT: process(CLR, WR_PTR, RD_PTR)
    ' d3 _9 @0 w) Y. j
  31.                 variable change : integer;               
    5 L0 H7 g% v) I1 g
  32.         begin  
    ' m0 [$ w$ l& C
  33.                 if CLR = '1' then
    9 j& S/ c8 j' F, }7 L# E
  34.                         count <= 0;" G  q5 b" ~& I, P1 `
  35.                         change := 0;+ l& X2 ]2 P6 A/ U9 n5 X
  36.                 else
    $ x4 \4 X2 T" J) n$ a
  37.                         change := 0;
    3 ]) u6 p  G5 Z" d: u
  38.                         if WR_PTR'event then
    ' x& R0 j  i7 [8 K9 |' W
  39.                                 change := 1;
    & S5 s$ K, j% R7 H' n% H
  40.                         end if;
    5 F4 j) G) S% s( p3 }# q: H$ F
  41.                         if RD_PTR'event then
    + x0 Y) n# n5 }  o% W# p% V. s
  42.                                 change := change - 1;9 s. _$ ~+ ?. J2 K' p
  43.                         end if;
    2 o' z  w0 U  C" {, ^) o7 \
  44.                         count <= count + change;
    8 I8 _* R6 `+ W
  45.                 end if;
    * B# B  |' N# b, S3 J- @' y$ X% `
  46.         end process;       
    & n6 f9 W: H! O2 E* }
  47.         STATUS: process(count)& u1 R5 _6 L3 l, u2 `
  48.         begin  $ V- b3 f) [8 r5 w! X, |0 R
  49.                 if count=0 then
    8 O$ R+ z: k: O% d
  50.                         FULL   <= '0';9 R% _' z! p) L
  51.                         EMPTY  <= '1';
    7 n& m" i4 P0 a, w" I' a" I/ Y+ @
  52.                 elsif count=depth  then; Y  W6 e3 ]- X2 E/ L$ t2 F7 w
  53.                         FULL   <= '1';
      ?% ]) Z7 f1 Y9 J, m' y: _9 w
  54.                         EMPTY  <= '0'; 8 B& [8 s5 r) Y) d+ m
  55.                 else       
    # q4 ^8 Y( ^) @3 H
  56.                         FULL   <= '0';
    - b# K  X6 Y) d
  57.                         EMPTY  <= '0';
    6 k# E/ t1 L% E0 A4 E/ L+ l! c
  58.                 end if;                        ) F2 d9 J1 D- e
  59.         end process;       
複製代碼
4#
 樓主| 發表於 2009-1-10 22:13:00 | 顯示全部樓層
  1.         FWRITE: process (CLR, WCLK)7 Z1 E5 v1 `9 ?/ ?7 A6 V) c
  2.         begin
    7 Z7 N( v5 t" I: F1 d- q
  3.                 if CLR = '1' then4 N7 V" T0 w& Q  M+ [+ Y  ~
  4.                         for INDEX in fmax downto 0 loop
    9 E0 j( F" J3 h3 F/ V
  5.                                 fifo_array(INDEX) <= (others => '0');( z  [1 p6 h' v$ H
  6.                         end loop;1 Q* `5 t+ U# J* w
  7.                         WR_PTR <= 0;2 U9 V* x7 p: w& n: a
  8.                 elsif rising_edge(WCLK) then
    7 v& _2 ?) f5 R: w4 i0 n: q
  9.                         if WE = '1' and count<depth then, n2 N( h4 g/ }" Z: \& y
  10.                                 fifo_array(WR_PTR) <= DATA;8 |! w' B% r$ F- y+ c) H- u; z
  11.                                 -- move pointer
    ) t& U) V, c* p* ^! u/ j( f& z
  12.                                 if WR_PTR=fmax then
    2 b1 e% N4 [: b: V, K- ~  {* x; m
  13.                                         WR_PTR <= 0; ! a8 _+ I  F9 \+ j2 e2 ]
  14.                                 else WR_PTR <= WR_PTR + 1;
    & r# j6 S4 D8 i  R: f! @
  15.                                 end if;
    ; w8 p, R7 j/ \( I" ]
  16.                         end if;+ C% ^9 w9 ~2 M0 U
  17.                 end if;$ E, c7 }+ B3 S2 L1 j8 B
  18.         end process;
    3 y1 f: N; L) g2 E1 c7 J: o/ s
  19.         FREAD: process (CLR, RCLK)! \3 D: L* Y9 r
  20.         begin
    7 D' [; F' a' W8 f6 u) \0 O) |
  21.                 if CLR = '1' then
    * J# F% a7 v! I6 {4 n7 Q# F7 O
  22.                         RD_PTR <= 0;
    ' V' _5 A" R3 t) {3 b
  23.                 elsif falling_edge(RCLK) then
    1 i0 i0 O: G2 O
  24.                         if RE = '1' and count>0 then9 n- M7 c1 B* V/ X0 K) u
  25.                                 Q <= fifo_array(RD_PTR);; E9 y( C$ j/ d$ m& }) q
  26.                                 -- move pointer % W9 p1 _4 N; @4 s
  27.                                 if RD_PTR=fmax then ! T3 O$ ^: Z) R0 S& t4 E+ M, Y
  28.                                         RD_PTR <= 0;
    * B" w7 g# L/ I1 g, Q( d
  29.                                 else RD_PTR <= RD_PTR + 1;+ Y  C+ ]+ t! u- `
  30.                                 end if;
    ( [' v$ v/ V+ O7 y' q& _2 Q
  31.                         end if;
    1 t* s! N/ f6 c; ]2 C5 M
  32.                 end if;+ ^6 [; {! u# @: X3 R/ G. K4 G" A
  33.         end process;9 j7 v6 A. r1 X1 E* U! q
  34. end architecture;
複製代碼
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

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

GMT+8, 2024-6-2 06:28 AM , Processed in 0.112514 second(s), 17 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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