这个程序的寄存器读取时和STM32通讯的,之前有一个是和AVR通讯的,这个程序已经调试通过,原理比较简单,相信认真看的都能够明白。

因为ADS8364为差分AD,所以其输出为补码形式,按照2.5V的参考电压源输出的数据范围为-32768~+32768,如果AIN- 连到VREF(2.5V),那么当AIN+ 输入为0时 输出的数据为0x8000,如果AIN+ 输入为2.5V则输出数据为0x0000,AIN+ 输入为5V时输出数据位0x7F。程序如下:

  1 --最后修改2011.3.26
  2
  3 --最后测试功能:
  4
  5 --利用第一块板子测试ADS8364
  6
  7 library ieee;
  8
  9 use ieee.std_logic_1164.all;
 10
 11 use ieee.std_logic_unsigned.all;
 12
 13 --------------------------------------------------------------------------------------
 14
 15 --此段定义系统的各信号线
 16
 17 --------------------------------------------------------------------------------------
 18
 19 entity ad is
 20
 21 port(
 22
 23 -- 系统信号线
 24
 25     clk:         in      std_logic;
 26
 27 led:outstd_logic;
 28
 29     rst:       in      std_logic;
 30
 31 -- arm相连的信号线
 32
 33     adr_l:       in      std_logic_vector(7 downto 0); --a7...a0,只使用了低八位地址线
 34
 35     data:        inout   std_logic_vector(7 downto 0); --只使用了低八位数据线
 36
 37     fsmc_ne4:    in      std_logic;
 38
 39     fsmc_noe:    in      std_logic;
 40
 41     fsmc_nwe:    in      std_logic;
 42
 43 --ad8364信号线
 44
 45 adc_d:       in    std_logic_vector(15 downto 0);
 46
 47 adc_a0,adc_a1,adc_a2:       out   std_logic;
 48
 49 adc_reset:   out   std_logic;
 50
 51 adc_cs:      out   std_logic;
 52
 53 adc_wr:      out   std_logic;
 54
 55 adc_rd:      out   std_logic;
 56
 57 adc_holda,adc_holdb,adc_holdc:outstd_logic;
 58
 59 adc_eoc:     in    std_logic;
 60
 61 adcclk_out:out   std_logic
 62
 63
 64
 65 );
 66
 67 end entity;
 68
 69
 70
 71 --统一编址,地址线数据线为八位,每个地址数据宽度8位
 72
 73 --"00000001" ad0_h_data0x01
 74
 75 --"00000010" ad0_l_data0x02
 76
 77 --"00000011" ad1_h_data0x03
 78
 79 --"00000100" ad1_l_data0x04
 80
 81 --"00000101" led_ctrl0x05
 82
 83
 84
 85 architecture art of ad is
 86
 87 --------------------------------------------------------------------------------------
 88
 89 --此段定义内部相应的寄存器和相应变量
 90
 91 --------------------------------------------------------------------------------------
 92
 93
 94
 95 --stm32读写相关信号
 96
 97
 98
 99 --设置存储数据的寄存器
100
101 signal ad0_h_data,ad0_l_data,ad1_h_data,ad1_l_data,led_ctrl:  std_logic_vector(7 downto 0);
102
103 --数据缓冲寄存器
104
105 signal data_buf: std_logic_vector(7 downto 0);
106
107 --数据输出控制
108
109 signal data_outctl: std_logic;
110
111
112
113 --时钟分频相关变量
114
115 signal clkcnt:std_logic_vector(16 downto 0);
116
117 signal adc_clk:std_logic;--adc时钟信号
118
119 signal adc_data_buf:std_logic_vector(15 downto 0);
120
121
122
123 --定义读取过程的各个状态
124
125 --13位控制分别为 hold adc_a rd 状态机状态5位     hhhabcr
126
127 ---------------------------------------------------98365
128
129 constant st0:std_logic_vector(11 downto 0):="000000100000";--启动转换
130
131 constant st1:std_logic_vector(11 downto 0):="111000100001";--进入17个周期等待转换结束,不检测EOC
132
133 constant st2:std_logic_vector(11 downto 0):="111000100010";
134
135 constant st3:std_logic_vector(11 downto 0):="111000100011";
136
137 constant st4:std_logic_vector(11 downto 0):="111000100100";
138
139 constant st5:std_logic_vector(11 downto 0):="111000100101";
140
141 constant st6:std_logic_vector(11 downto 0):="111000100110";
142
143 constant st7:std_logic_vector(11 downto 0):="111000100111";
144
145 constant st8:std_logic_vector(11 downto 0):="111000101000";
146
147 constant st9:std_logic_vector(11 downto 0):="111000101001";
148
149 constant st10:std_logic_vector(11 downto 0):="111000101010";
150
151 constant st11:std_logic_vector(11 downto 0):="111000101011";
152
153 constant st12:std_logic_vector(11 downto 0):="111000101100";
154
155 constant st13:std_logic_vector(11 downto 0):="111000101101";
156
157 constant st14:std_logic_vector(11 downto 0):="111000101110";
158
159 constant st15:std_logic_vector(11 downto 0):="111000101111";
160
161 constant st16:std_logic_vector(11 downto 0):="111000110000";
162
163 constant st17:std_logic_vector(11 downto 0):="111000110001";
164
165 constant st18:std_logic_vector(11 downto 0):="111000110010";
166
167 constant st19:std_logic_vector(11 downto 0):="111000010011";--读ch1数据
168
169 constant st20:std_logic_vector(11 downto 0):="111001110100";
170
171 constant st21:std_logic_vector(11 downto 0):="111001010101";--读ch2数据
172
173 constant st22:std_logic_vector(11 downto 0):="111001110110";
174
175
176
177 signal state:std_logic_vector(11 downto 0);--用于状态跳转
178
179 signal readst:std_logic_vector(3 downto 0);--adc_a,在另一个进程中根据此信号 选择输出的数据
180
181
182
183 begin
184
185 ------------------------------------------------时钟分频-------------------------------------------------------------------
186
187 process(rst,clk) is
188
189 begin
190
191 if rst='0' then
192
193 clkcnt <= "00000000000000000";
194
195 elsif(clk'event and clk = '1') then
196
197 if(clkcnt = "11111111111111111") then
198
199 clkcnt<= "00000000000000000";
200
201 else
202
203 clkcnt <= clkcnt+1;
204
205 end if;
206
207 end if;
208
209 end process;
210
211 --pwm_clk <= clkcnt(7);--分频pwm时钟
212
213 --led_clk <= clkcnt(16);--分频led时钟
214
215
216
217 led <= clkcnt(16);--分频led时钟
218
219 adc_clk <= clkcnt(3);
220
221 adcclk_out <= clkcnt(3);
222
223
224
225
226
227
228
229 --------------------------------------------------------------------------------------
230
231 --stm32读写程序
232
233 --根据stm32读写时序图和信号线设计,实际上并没有使用全部信号线
234
235 --------------------------------------------------------------------------------------
236
237
238
239 --当读取cpld数据时用来判断何时向总线上输出数据
240
241 data_outctl <= (not  fsmc_ne4) and (not fsmc_noe) and (fsmc_nwe);
242
243 data <=  data_buf when (data_outctl='1') else "ZZZZZZZZ";--向数据线输出数据,否则保持为高阻态
244
245
246
247 -- 写操作,模式1,时序图在数据手册p331
248
249 process(rst,fsmc_ne4,fsmc_nwe,adr_l,fsmc_noe) is
250
251 begin
252
253 if rst='0' then
254
255
256
257 elsif(fsmc_nwe'event and fsmc_nwe='1') then
258
259 if((fsmc_noe and (not fsmc_ne4))='1') then
260
261 case (adr_l) is
262
263 when "00000001" =>--对应的地址
264
265
266
267 when "00000010" =>
268
269
270
271 when "00000011" =>
272
273
274
275 when "00000100" =>
276
277
278
279 when "00000101" =>
280
281
282
283 when others =>
284
285
286
287 end case;
288
289 end if;
290
291 end if;
292
293 end process;
294
295
296
297 --读操作,模式1,p331
298
299 process(rst,fsmc_ne4,fsmc_nwe,adr_l,fsmc_noe) is
300
301 begin
302
303 if rst= '0' then
304
305 data_buf<="00000000";
306
307 elsif(fsmc_noe='0' and fsmc_noe'event) then --直接在noe的下降沿更新数据
308
309 case (adr_l) is
310
311 when "00000001" =>
312
313 data_buf <= ad0_h_data; --0x01
314
315 when "00000010" =>
316
317 data_buf <= ad0_l_data; --0x02
318
319 when "00000011" =>
320
321 data_buf <= ad1_h_data; --0x03
322
323 when "00000100" =>
324
325 data_buf <= ad1_l_data; --0x04
326
327 when "00000101" =>
328
329 data_buf <= "11001100"; --0x05
330
331 when others =>  data_buf <= "ZZZZZZZZ";
332
333 end case;
334
335 end if;
336
337 end process;
338
339 --------------------------------------ads8364------------------------------------
340
341 --ads8364控制,默认byte=0,add=0
342
343 adc_cs <= '0'; --片选一直选中
344
345 adc_wr <= '1';
346
347 --ads状态转移
348
349 process(adc_clk,rst)
350
351 begin
352
353 if(rst='0') then
354
355 state<=st0;
356
357 adc_reset<='0';
358
359 adc_holda<='1';
360
361 adc_holdb<='1';
362
363 adc_holdc<='1';
364
365 elsif(adc_clk'event and adc_clk='1') then
366
367 adc_reset<='1';
368
369 case state is
370
371 when st0=> state<=st1;
372
373 when st1=> state<=st2;
374
375 when st2=> state<=st3;
376
377 when st3=> state<=st4;
378
379 when st4=> state<=st5;
380
381 when st5=> state<=st6;
382
383 when st6=> state<=st7;
384
385 when st7=> state<=st8;
386
387 when st8=> state<=st9;
388
389 when st9=> state<=st10;
390
391 when st10=> state<=st11;
392
393 when st11=> state<=st12;
394
395 when st12=> state<=st13;
396
397 when st13=> state<=st14;
398
399 when st14=> state<=st15;
400
401 when st15=> state<=st16;
402
403 when st16=> state<=st17;
404
405 when st17=> state<=st18;
406
407 when st18=> state<=st19;
408
409 when st19=> state<=st20;
410
411 when st20=> state<=st21;
412
413 when st21=> state<=st22;
414
415 when st22=> state<=st0;
416
417 when others=> state<=st0;
418
419 end case;
420
421 end if;
422
423 readst<=state(8 downto 5);
424
425 adc_holdc<=state(11);
426
427 adc_holdb<=state(10);
428
429 adc_holda<=state(9);
430
431 adc_a2<=state(8);
432
433 adc_a1<=state(7);
434
435 adc_a0<=state(6);
436
437 adc_rd<=state(5);
438
439 end process;
440
441
442
443 process(clk,adc_d)
444
445 begin
446
447 if(clk'event and clk='0')then
448
449 adc_data_buf(14 downto 0) <= adc_d(14 downto 0);
450
451 adc_data_buf(15) <= not adc_d(15);
452
453 if readst="0000" then
454
455 ad0_h_data <= adc_data_buf(15 downto 8);
456
457 ad0_l_data <= adc_data_buf(7 downto 0);
458
459 elsif readst="0010" then
460
461 ad1_h_data <= adc_data_buf(15 downto 8);
462
463 ad1_l_data <= adc_data_buf(7 downto 0);
464
465 end if;
466
467 end if;
468
469 end process;
470
471 end;
472
473
474
475
476
477  

ADS8364 VHDL程序正式版相关推荐

  1. window10怎么卸载php,window_win10怎么卸载程序?win10卸载程序教程,当win10正式版发布以后,不少 - phpStudy...

    win10怎么卸载程序?win10卸载程序教程 当win10正式版发布以后,不少用户将电脑升级为Windows10系统后,不知道该如何卸载程序,本篇将为大家带来win10卸载程序教程,希望能够帮助到大 ...

  2. 小程序二维码需要发布正式版后才能获取到_IOS14.3正式版发布时间12月15日:苹果ios14.3正式版内容一览[多图]-游戏产业...

    正式版发布时间是什么时候?苹果正式版什么时候发布?就在广大果粉还没有起床打工的时候.苹果的正式版已经开启了.大家打开自己的手机就可以看到正式版的更新内容了.下面就来为大家详细的介绍一下这次更新内容. ...

  3. 小程序二维码需要发布正式版后才能获取到_很意外!iOS 14.1正式版已出,修复多处问题...

    在2020年10月21日凌晨时段,苹果正式推出了 iOS 14.1 正式版 和 iOS 14.2 beta 4 内测版,建议普通用户升级(不追求越狱),爱折腾不追求越狱,可升级 iOS 14.2 be ...

  4. 区分微信小程序版本(开发工具中、开发版、体验版、正式版)的方法?

    平凡也就两个字: 懒和惰; 成功也就两个字: 苦和勤; 优秀也就两个字: 你和我. 跟着我从0学习JAVA.spring全家桶和linux运维等知识,带你从懵懂少年走向人生巅峰,迎娶白富美! 关注微信 ...

  5. 【小程序“600002“】现象:小程序测试版能正常的进行页面跳转,正式版不能进行页面跳转

    记录:(in promise) MiniProgramError {"errno":600002,"errMsg":"request:fail url ...

  6. Q新闻丨Java 9正式版恐再延期;顺丰菜鸟口水战涉及阿里云;编程语言排行榜Python第四;盲人程序员背百万字符,用耳朵编程...

    编辑|小智 本周要闻:Java 9 正式版有可能被推迟到 9 月 21 号发布:顺丰.菜鸟口水战始末,或涉及阿里云:Node.js 发布 v8.0.0:Visual Studio for Mac 版本 ...

  7. 微信小程序 界面禁止下拉 左右滑动_手机 QQ v8.0 正式版上线,新界面,新功能...

    本文授权转自艾橙互动公众号. 经过一段时间内测,QQ手机版8.0 版本正式上线了. 目前iOS 版本已经更新,iOS 用户可以通过在App Store 进行更新体验,目前版本为v8.0.0.472. ...

  8. 小程序的版本(正式版、体验版、开发版)

    通过__wxConfig.envVersion获取当前小程序的版本(正式版.体验版.开发版) let miniVersion = __wxConfig.envVersion; let miniVers ...

  9. 苹果最新 Mac OS X El Capitan 正式版系统 dmg 镜像下载 / 升级安装程序

    自从 WWDC 2015 大会发布之后,经过一段时间的内部测试,苹果最新的 iOS 9 以及 Mac 操作系统 OS X El Capitan (酋长石) 终于提供下载并正式与大众见面了. 这次 OS ...

  10. 最新Delphi XE2 正式版破解程序

    http://download.csdn.net/detail/pjdelphi/3641710 Delphi XE2 正式版的破解程序,有效哦. Delphi XE2 官方完整 delphicbui ...

最新文章

  1. 用matlab绘制一个时钟
  2. Yammer Metrics,一种监视应用程序的新方法
  3. python数据类型所占字节数_python标准数据类型 Bytes
  4. TIDB报错statement count 5001 exceeds the transaction limitation, autocommit = false问题解决
  5. Page.RegisterClientScriptBlock和Page.RegisterStartupScript有何区别
  6. html的document操作
  7. 为什么突然变乱码_9102年了,还不知道Android为什么卡?
  8. python爬取小说网站资源_利用python的requests和BeautifulSoup库爬取小说网站内容
  9. linux监听端口丢失,查看 linux 端口 监听
  10. Windows批处理BAT脚本
  11. 为什么有人把《海贼王》当作人生信条
  12. 解压.tar.bz2文件命令
  13. Autodesk 3ds Max 渲染之后保存页面卡死问题
  14. 3D线激光成像数学模型简析
  15. MySQL中对索引的理解 特点 优势_深入理解MySQL索引和优化
  16. 修复iPhone系统白苹果问题
  17. 脚上有一个很灵的止咳穴位
  18. Linux 操作rar压缩包
  19. mybatis官网文档mybatis_doc
  20. .rvm/gems/ruby-2.4.1@global/gems/cocoapods-1.5.0/lib/cocoapods/executable.rb:89: warning: Insecure

热门文章

  1. FreeBSD 8.0候选版本RC2发布
  2. MySQL 中while loop repeat 的基本用法
  3. Google Kickstart Round.B C. Diverse Subarray
  4. Lasso估计学习笔记(二)
  5. html页面简单访问限制
  6. python全栈-Day 6
  7. 实验一: 网络侦查与网络扫描
  8. Angular2开发拙见——组件规划篇
  9. Django进阶之CSRF
  10. K3CLOUD表关联