当前位置:   article > 正文

ad7606驱动及仿真_ad7606 verilog仿真

ad7606 verilog仿真


  1. `timescale 1ns / 1ns
  2. //
  3. // Module Name: ad7606
  4. //
  5. module ad7606(
  6. input clk, //50mhz
  7. input rst_n,
  8. input [15:0] ad_data, //ad7606 采样数据
  9. input ad_busy, //ad7606 忙标志位
  10. input first_data, //ad7606 第一个数据标志位
  11. output [2:0] ad_os, //ad7606 过采样倍率选择
  12. output reg ad_cs, //ad7606 AD cs
  13. output reg ad_rd, //ad7606 AD data read
  14. output reg ad_reset, //ad7606 AD reset
  15. output reg ad_convstab, //ad7606 AD convert start
  16. output reg [15:0] ad_ch1, //AD第1通道的数据
  17. output reg [15:0] ad_ch2, //AD第2通道的数据
  18. output reg [15:0] ad_ch3, //AD第3通道的数据
  19. output reg [15:0] ad_ch4, //AD第4通道的数据
  20. output reg [15:0] ad_ch5, //AD第5通道的数据
  21. output reg [15:0] ad_ch6, //AD第6通道的数据
  22. output reg [15:0] ad_ch7, //AD第7通道的数据
  23. output reg [15:0] ad_ch8, //AD第8通道的数据
  24. output reg [3:0] state
  25. //output reg [3:0] cnt
  26. );
  27. reg [7:0] cnt = 0 ;
  28. reg [15:0] cnt50us = 0;
  29. reg [5:0] i;
  30. //reg [3:0] state;
  31. parameter IDLE=4'd0;
  32. parameter AD_CONV=4'd1;
  33. parameter Wait_1=4'd2;
  34. parameter Wait_busy=4'd3;
  35. parameter READ_CH1=4'd4;
  36. parameter READ_CH2=4'd5;
  37. parameter READ_CH3=4'd6;
  38. parameter READ_CH4=4'd7;
  39. parameter READ_CH5=4'd8;
  40. parameter READ_CH6=4'd9;
  41. parameter READ_CH7=4'd10;
  42. parameter READ_CH8=4'd11;
  43. parameter READ_DONE=4'd12;
  44. //parameter display=4'd13;
  45. assign ad_os=3'b000; //无过采样
  46. //ad复位
  47. always@(posedge clk)
  48. begin
  49. if(cnt<8'hff) begin
  50. cnt<=cnt+1;
  51. ad_reset<=1'b1;
  52. end
  53. else
  54. ad_reset<=1'b0; //计数器达到ff后停止,ad_reset恒为零
  55. end
  56. //使用定时器来设置采样频率
  57. always @(posedge clk or negedge rst_n) //50us读取一次数据,ad的采样率为20K
  58. begin
  59. if(rst_n == 0)
  60. cnt50us <= 0;
  61. else begin
  62. if(cnt50us < 16'd2499)
  63. begin
  64. cnt50us <= cnt50us + 1;
  65. end
  66. else
  67. cnt50us <= 0;
  68. end
  69. end
  70. always @(posedge clk)
  71. begin
  72. if (ad_reset==1'b1) begin //初始化ad
  73. state<=IDLE;
  74. ad_ch1<=0;
  75. ad_ch2<=0;
  76. ad_ch3<=0;
  77. ad_ch4<=0;
  78. ad_ch5<=0;
  79. ad_ch6<=0;
  80. ad_ch7<=0;
  81. ad_ch8<=0;
  82. ad_cs<=1'b1;
  83. ad_rd<=1'b1;
  84. ad_convstab<=1'b1; //8通道同步采样
  85. i<=0;
  86. end
  87. else begin
  88. case(state) //need time:(20+2+5+1+3*8+1)*20ns=1060ns, fmax=1/1060ns=1MHZ
  89. IDLE: begin
  90. ad_cs<=1'b1;
  91. ad_rd<=1'b1;
  92. ad_convstab<=1'b1;
  93. if(i==20) begin //延时20个时钟后开始转换
  94. i<=0;
  95. state<=AD_CONV;
  96. end
  97. else
  98. i<=i+1'b1;
  99. end
  100. AD_CONV: begin
  101. if(i==2) begin //等待2个lock,convstab的下降沿最少为25ns,故至少需要两个时钟
  102. i<=0;
  103. state<=Wait_1;
  104. ad_convstab<=1'b1;
  105. end
  106. else begin
  107. i<=i+1'b1;
  108. ad_convstab<=1'b0; //启动AD转换
  109. end
  110. end
  111. Wait_1: begin
  112. if(i==5) begin //等待5个clock, 等待busy信号为高(tconv)
  113. i<=0;
  114. state<=Wait_busy;
  115. end
  116. else
  117. i<=i+1'b1;
  118. end
  119. Wait_busy: begin
  120. if(ad_busy==1'b0) begin //等待busy为低电平 即转换之后读取模式
  121. i<=0;
  122. state<=READ_CH1;
  123. end
  124. end
  125. READ_CH1: begin
  126. ad_cs<=1'b0; //cs信号有效 直到读取8通道结束
  127. if(i==3) begin // 低电平持续3个时钟,完成通道1的读入
  128. ad_rd<=1'b1;
  129. i<=0;
  130. ad_ch1<=ad_data; //CH1
  131. state<=READ_CH2;
  132. end
  133. else begin
  134. ad_rd<=1'b0;
  135. i<=i+1'b1;
  136. end
  137. end
  138. READ_CH2: begin
  139. if(i==3) begin
  140. ad_rd<=1'b1;
  141. i<=0;
  142. ad_ch2<=ad_data; //读CH2
  143. state<=READ_CH3;
  144. end
  145. else begin
  146. ad_rd<=1'b0;
  147. i<=i+1'b1;
  148. end
  149. end
  150. READ_CH3: begin
  151. if(i==3) begin
  152. ad_rd<=1'b1;
  153. i<=0;
  154. ad_ch3<=ad_data; //CH3
  155. state<=READ_CH4;
  156. end
  157. else begin
  158. ad_rd<=1'b0;
  159. i<=i+1'b1;
  160. end
  161. end
  162. READ_CH4: begin
  163. if(i==3) begin
  164. ad_rd<=1'b1;
  165. i<=0;
  166. ad_ch4<=ad_data; //读CH4
  167. state<=READ_CH5;
  168. end
  169. else begin
  170. ad_rd<=1'b0;
  171. i<=i+1'b1;
  172. end
  173. end
  174. READ_CH5: begin
  175. if(i==3) begin
  176. ad_rd<=1'b1;
  177. i<=0;
  178. ad_ch5<=ad_data; //CH5
  179. state<=READ_CH6;
  180. end
  181. else begin
  182. ad_rd<=1'b0;
  183. i<=i+1'b1;
  184. end
  185. end
  186. READ_CH6: begin
  187. if(i==3) begin
  188. ad_rd<=1'b1;
  189. i<=0;
  190. ad_ch6<=ad_data; //读CH6
  191. state<=READ_CH7;
  192. end
  193. else begin
  194. ad_rd<=1'b0;
  195. i<=i+1'b1;
  196. end
  197. end
  198. READ_CH7: begin
  199. if(i==3) begin
  200. ad_rd<=1'b1;
  201. i<=0;
  202. ad_ch7<=ad_data; //CH7
  203. state<=READ_CH8;
  204. end
  205. else begin
  206. ad_rd<=1'b0;
  207. i<=i+1'b1;
  208. end
  209. end
  210. READ_CH8: begin
  211. if(i==3) begin
  212. ad_rd<=1'b1;
  213. i<=0;
  214. ad_ch8<=ad_data; //读CH8
  215. state<=READ_DONE;
  216. end
  217. else begin
  218. ad_rd<=1'b0;
  219. i<=i+1'b1;
  220. end
  221. end
  222. READ_DONE:begin //完成读,回到idle状态
  223. ad_rd<=1'b1;
  224. ad_cs<=1'b1;
  225. if(cnt50us == 16'd2499) //不加此条件,则ad完成一次读取需1280ns,采样频率781.25K,但需注意ad每通道的追高采样只能为200K
  226. state<=IDLE;
  227. else
  228. state<=READ_DONE;
  229. end
  230. default: state<=IDLE;
  231. endcase
  232. end
  233. end
  234. endmodule

仿真测试程序如下:

  1. `timescale 1 ns/ 1 ns
  2. module ad7606_vlg_tst();
  3. // constants
  4. // general purpose registers
  5. // test vector input registers
  6. reg ad_busy;
  7. reg [15:0] ad_data;
  8. reg clk;
  9. reg first_data;
  10. reg rst_n;
  11. // wires
  12. wire [15:0] ad_ch1;
  13. wire [15:0] ad_ch2;
  14. wire [15:0] ad_ch3;
  15. wire [15:0] ad_ch4;
  16. wire [15:0] ad_ch5;
  17. wire [15:0] ad_ch6;
  18. wire [15:0] ad_ch7;
  19. wire [15:0] ad_ch8;
  20. wire ad_convstab;
  21. wire ad_cs;
  22. wire [2:0] ad_os;
  23. wire ad_rd;
  24. wire ad_reset;
  25. wire [3:0] state;
  26. // assign statements (if any)
  27. ad7606 i1 (
  28. // port map - connection between master ports and signals/registers
  29. .ad_busy(ad_busy),
  30. .ad_ch1(ad_ch1),
  31. .ad_ch2(ad_ch2),
  32. .ad_ch3(ad_ch3),
  33. .ad_ch4(ad_ch4),
  34. .ad_ch5(ad_ch5),
  35. .ad_ch6(ad_ch6),
  36. .ad_ch7(ad_ch7),
  37. .ad_ch8(ad_ch8),
  38. .ad_convstab(ad_convstab),
  39. .ad_cs(ad_cs),
  40. .ad_data(ad_data),
  41. .ad_os(ad_os),
  42. .ad_rd(ad_rd),
  43. .ad_reset(ad_reset),
  44. .clk(clk),
  45. .first_data(first_data),
  46. .rst_n(rst_n),
  47. .state(state)
  48. //.cnt(cnt)
  49. );
  50. initial
  51. begin
  52. ad_busy = 0;
  53. first_data = 0;
  54. clk = 0;
  55. forever //50MHz
  56. #10
  57. clk = ~clk;
  58. $display("Running testbench");
  59. end
  60. initial
  61. begin
  62. rst_n = 1;
  63. #10;
  64. rst_n = 0;
  65. #20;
  66. rst_n = 1;
  67. end
  68. always@(posedge clk)
  69. begin
  70. ad_data <= $random; //使用随机数模拟采样信号
  71. end
  72. endmodule

仿真结果如下: 
仿真结果,每5000ns读取一次数据


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/正经夜光杯/article/detail/829481
推荐阅读
相关标签
  

闽ICP备14008679号