3回答

0收藏

Verilog基础--关于数组初始化

FPGA/DSP FPGA/DSP 17627 人阅读 | 3 人回复 | 2013-04-24

用Verilog写图像处理的算法,很直接的问题是如何将图片的矩阵数据导入,基本思路是用数组
试了一下Verilog下的数组,初始化稍微麻烦些,多次都没有成功,后来放入initial初始化,发现是可以的。
写一个简答的程序,实验好使
  1. module array
  2. (
  3.         CLK,
  4.         RSTn,
  5.         LED
  6. );
  7.         input CLK;
  8.         input RSTn;
  9.        
  10.         output [3:0] LED;
  11.         reg [3:0] memory[0:15];
  12.        
  13.         initial
  14.         begin
  15.                 memory[0] = 4'd0;
  16.                 memory[1] = 4'd1;
  17.                 memory[2] = 4'd2;
  18.                 memory[3] = 4'd3;
  19.                 memory[4] = 4'd4;
  20.                 memory[5] = 4'd5;
  21.                 memory[6] = 4'd6;
  22.                 memory[7] = 4'd7;
  23.                 memory[8] = 4'd8;
  24.                 memory[9] = 4'd9;
  25.                 memory[10] = 4'd10;
  26.                 memory[11] = 4'd11;
  27.                 memory[12] = 4'd12;
  28.                 memory[13] = 4'd13;
  29.                 memory[14] = 4'd14;
  30.                 memory[15] = 4'd15;
  31.         end
  32.        
  33.         parameter  T1s = 32'd50_000_000;
  34.         reg [31:0] count;
  35.         always @(posedge CLK or negedge RSTn)
  36.                 if(!RSTn)
  37.                         count <= 32'd0;
  38.                 else if(count == T1s)
  39.                         count <= 32'd0;
  40.                 else count <= count + 1'd1;
  41.        
  42.         reg [3:0] rLED;
  43.         reg [3:0] index;
  44.         always @(posedge CLK or negedge RSTn)
  45.                 if(!RSTn)
  46.                 begin
  47.                         rLED <= 4'd0;
  48.                         index <= 4'd0;
  49.                 end
  50.                 else if(count == T1s)
  51.                 begin
  52.                         rLED <= memory[index];
  53.                         index <= index + 1'b1;
  54.                 end
  55.         assign LED = rLED;
  56.                        
  57. endmodule
复制代码
tcl文件
  1. #------------------GLOBAL--------------------#
  2. set_global_assignment -name RESERVE_ALL_UNUSED_PINS "AS INPUT TRI-STATED"
  3. set_global_assignment -name ENABLE_INIT_DONE_OUTPUT OFF


  4. set_location_assignment        PIN_M1        -to RSTn


  5. set_location_assignment        PIN_R9        -to CLK


  6. set_location_assignment        PIN_J1        -to LED[0]
  7. set_location_assignment        PIN_J2        -to LED[1]
  8. set_location_assignment        PIN_K1        -to LED[2]
  9. set_location_assignment        PIN_K2        -to LED[3]
复制代码
国内的ubuntu的更新源还是上海交大最给力
分享到:
回复

使用道具 举报

回答|共 3 个

倒序浏览

沙发

libing64

发表于 2013-4-24 20:46:47 | 只看该作者

感觉写代码时稍微注意下缩进,程序就变得好看多了~回头看我之前写的C代码,简直不能读~
国内的ubuntu的更新源还是上海交大最给力
板凳

libing64

发表于 2013-4-24 21:59:20 | 只看该作者

其实使用ROM的话会更加的方便,不过还没看懂,下一步换成ROM试试
国内的ubuntu的更新源还是上海交大最给力
地板

小菜儿

发表于 2013-4-25 09:30:31 | 只看该作者

写程序时候,注意缩进还是蛮有好处的,出问题检查起来也方便一些!
您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /3 下一条