在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 2398|回复: 2

[求助] verilog实现AD采样?

[复制链接]
发表于 2013-7-14 18:32:32 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
AD芯片输出支持SPI接口,现在想让AD芯片接到FPGA,让FPGA获取采样值并进行数据处理,AD芯片的接口如何用verilog来实现啊?有没有例子可以学习一下啊。
发表于 2013-7-15 22:20:48 | 显示全部楼层
FPGA模拟一个接口就可以了
发表于 2013-7-18 11:58:15 | 显示全部楼层
Hi sir

I hope This code will help you





  1. module spi_master_adc(

  2. input SPI_MISO,
  3. input CLKIN,

  4. output reg AD_CONV,
  5. output SPI_SCK,
  6. output reg [27:0] ADC_DIGITAL,
  7. output reg READY
  8. );

  9. parameter idle = 3'b001;
  10. parameter convert = 3'b010;
  11. parameter read = 3'b100;


  12. reg [2:0] state= idle;
  13. reg idle_count = 0;
  14. reg [5:0] count=0;
  15. reg [27:0] data;

  16. initial
  17. AD_CONV = 1;




  18. // the clken signal control the clock signal sent to the adc.
  19. // we want SPI_SCK for 33 clock cycles so we enable clken for only that duration of time.
  20. assign SPI_SCK = CLKIN;

  21. always@(posedge CLKIN)
  22. begin

  23. case(state)
  24. idle : begin

  25. // ready signal si set to zero to indicate output is not ready.
  26. READY <= 0;
  27. if(idle_count == 0) begin
  28. // conversion is disabled
  29. AD_CONV <= 1;
  30. state <= idle;
  31. idle_count <= idle_count + 1;
  32. end
  33. else begin
  34. // reset the counting variable and goes to conversion state after 1 clock cycle
  35. idle_count <= 0;
  36. state <= convert;

  37. end
  38. end

  39. convert: begin

  40. READY <= 0;
  41. // start the conversion process and enable the output clock.
  42. AD_CONV <= 0;
  43. if(count != 33)begin

  44. // read the data only when the input isnot in high impedance state
  45. if((count != 0) | (count != 1) | (count != 17) | (count != 33) ) begin
  46. data <= data << 1;
  47. data[0] <= SPI_MISO;
  48. end

  49. // updates the counter

  50. end
  51. else
  52. begin
  53. // after 33 cycles .. goes to read state
  54. state <= read;
  55. count <= 0;
  56. end
  57. count <= count + 1;
  58. end
  59. read : begin
  60. // stops the output clock . stops the conversion and outputs the digital data.
  61. count <= 0;
  62. AD_CONV <= 0;
  63. ADC_DIGITAL <= data;
  64. READY <= 1;
  65. // goesto idle state to start new conversion process.
  66. state <= idle;
  67. end
  68. endcase

  69. end

  70. endmodule


  71. and 2nd is



  72. `timescale 1ns / 1ps
  73. //////////////////////////////////////////////////////////////////////////////////
  74. // Company:
  75. // Engineer:
  76. //
  77. // Create Date: 11:35:44 05/15/2010
  78. // Design Name:
  79. // Module Name: spi_master_amp
  80. // Project Name:
  81. // Target Devices:
  82. // Tool versions:
  83. // Description:
  84. //
  85. // Dependencies:
  86. //
  87. // Revision:
  88. // Revision 0.01 - File Created
  89. // Additional Comments:
  90. //
  91. //////////////////////////////////////////////////////////////////////////////////
  92. module spi_master_amp(

  93. input CLKIN, // CLOCK SOURCE FROM DCM (DIGITAL CLOCK MANAGER)
  94. input RST,
  95. input [7:0] GAIN_AB, // GAIN OF AMPLIFIER A AND B FROM MICROBLAZE
  96. input ADC_DOUT, // PREVIOUS GAIN SERIAL INPUT FROM AMPIFIER
  97. input WREN, // WRITE ENABLE FOR GAIN FROM MICROBLAZE
  98. output reg AMP_CS, //CONTROL SIGNAL TO AMPLIFIER
  99. output SPI_SCK, // CLOCK SIGNAL TO AMPLIFIER (10MHZ)
  100. output reg SPI_MOSI, //SERIAL INPUT TO AMPLIFIER
  101. output reg AMP_SHDN // RESET SIGNAL FOR AMPIFIER


  102. );

  103. reg [7:0] gain;
  104. reg [3:0] count;
  105. reg done = 0;

  106. assign SPI_SCK = CLKIN;

  107. always@(posedge CLKIN)
  108. begin
  109. if(RST)
  110. AMP_SHDN <= 1;
  111. else
  112. begin
  113. AMP_SHDN <= 0;

  114. if(WREN) begin
  115. gain <= GAIN_AB;
  116. done <= 0;
  117. end
  118. else begin

  119. {SPI_MOSI,gain} <= gain << 1;

  120. if(count == 8) begin
  121. done <= 1;
  122. count <= 0;
  123. end
  124. else
  125. count <= count + 1;


  126. end
  127. end

  128. end

  129. always@(negedge CLKIN)
  130. begin

  131. if(WREN | done)
  132. AMP_CS <= 1;
  133. else
  134. AMP_CS <= 0;


  135. end

  136. endmodule


复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

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


小黑屋| 手机版| 关于我们| 联系我们| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2025-1-11 05:19 , Processed in 0.024717 second(s), 11 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表