完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
在这A/D转换程序里面的wire变量:wire ready_done; //cs_n拉低(大于1.4us)后的标志;wire rec_done; //数据读取完毕的标志;wire conv_done; //数据转换完毕的标志。它们三个变量是从 何处得到的?还有它们是如何发生变化的?
希望大侠们给予指点,谢谢 /*--------------------------------------------------------------------------------------- -- Filename ﹕ adc.v -- Author ﹕ZRtech -- Description ﹕TLC549状态机控制 -- Called by ﹕Top module -- Revision History ﹕10-5-20 -- Revision 1.0 -- Company ﹕ ZRtech Technology .Inc -- Copyright(c) 2010, ZRtech Technology Inc, All right reserved -----------------------------------------------------------------------------------------*/ module adc(clock,reset,enable,sdat_in,adc_clk,cs_n,data_ready,data_out); //I/O口声明 input clock; //系统时钟 input reset; //复位,高电平有效 input enable; //转换使能 input sdat_in; //TLC549串行数据输入 output adc_clk; //TLC549 I/O时钟 output cs_n; //TLC549 片选控制 output data_ready; //指示有新的数据输出 output[7:0] data_out; //AD转换数据输出 //I/O寄存器 reg adc_clk_r; reg cs_n_r; reg data_ready_r; reg[7:0] data_out_r; //AD转换数据输出 reg sdat_in_r; //数据输出锁存 //内部寄存器 reg[7:0]q; //移位寄存器,用于接收或发送数据 reg[2:0]adc_state; //状态机ADC reg[2:0]adc_next_state; reg[5:0]bit_count; //移位计数器 reg bit_count_rst; //ADC时钟计数器全能控制 reg div_clk; reg[CLK_DIV_BITS-1:0] clk_count;//时钟分频计数器 reg buf1,buf2; //内部信号 wire ready_done; //cs_n拉低(大于1.4us)后的标志 wire rec_done; //数据读取完毕的标志 wire conv_done; //数据转换完毕的标志 //计时器参数 //以下参数值按48MHz时钟计算 parameter CLK_DIV_VALUE = 31; //ADC时钟计数器(大于404nS)计数值 parameter CLK_DIV_BITS = 5; //ADC时钟计数器位宽 //状态机M1状态参数表 parameter idle = 3'b000, adc_ready = 3'b001, adc_receive = 3'b011, adc_conversion = 3'b010, adc_data_load = 3'b110; //********************************************************** //I/O寄存器输出 assign adc_clk = adc_clk_r; assign cs_n = cs_n_r; assign data_out = data_out_r; assign data_ready = data_ready_r; //同步输入数据信号 always @(posedge clock) begin sdat_in_r <= sdat_in; end //********************************************************** //时钟分频计数器 always @(posedge clock) begin if (reset == 1'b1) clk_count <= 5'd0; else begin if (clk_count < CLK_DIV_VALUE) begin clk_count <= clk_count + 1'b1; div_clk <= 1'b0; end else begin clk_count <= 5'd0; div_clk <= 1'b1; end end end //********************************************************** //状态机ADC always @(posedge clock) begin if (reset == 1'b1) adc_state <= idle; else adc_state <= adc_next_state; end //ADC状态机转换逻辑 always @(adc_state or ready_done or rec_done or conv_done or enable) begin cs_n_r <= 1'b0; bit_count_rst <= 1'b0; data_ready_r <= 1'b0; case (adc_state) idle: //初始状态 begin cs_n_r <= 1'b1; bit_count_rst <= 1'b1; //复位移位计数器 if (enable == 1'b1) adc_next_state <= adc_ready; else adc_next_state <= idle; end adc_ready: //准备接收 begin if(ready_done == 1'b1) adc_next_state <= adc_receive; else adc_next_state <= adc_ready; end adc_receive: //接收数据 begin if(rec_done == 1'b1) adc_next_state <= adc_conversion; else adc_next_state <= adc_receive; end adc_conversion: //转换前的采样的数据 begin cs_n_r <= 1'b1; if(conv_done == 1'b1) adc_next_state <= adc_data_load; else adc_next_state <= adc_conversion; end adc_data_load: begin data_ready_r <= 1'b1; //数据输出标志 adc_next_state <= idle; end default : adc_next_state <= idle; endcase end //********************************************************** //位移位计数器 always @(posedge clock) begin if (reset == 1'b1) bit_count <= 6'd0; else if (bit_count_rst == 1'b1) bit_count <= 6'd0; else if (div_clk == 1'b1) bit_count <= bit_count + 1'b1; end assign ready_done = (bit_count == 6'd4); //准备读取数据 assign rec_done = (bit_count == 6'd19); //接收数据完毕 assign conv_done = (bit_count == 6'd63); //ADC转换完毕 //在接收位计数器4-20间8个adc clk always @(bit_count) begin if ((bit_count < 6'd20) && (bit_count >= 6'd4)) adc_clk_r <= ~bit_count[0]; else adc_clk_r <= 1'b0; end always @(posedge clock) begin buf1 <= adc_clk_r; buf2 <= buf1; end //读取数据 always @(posedge clock) begin if(buf1 && ~buf2) //ADC时钟上升沿 q <= {q[6:0],sdat_in_r}; else if(data_ready_r == 1'b1) //输出读取的数据 data_out_r <= q; end endmodule |
|
相关推荐
1个回答
|
|
assign ready_done = (bit_count == 6'd4); //准备读取数据
assign rec_done = (bit_count == 6'd19); //接收数据完毕 assign conv_done = (bit_count == 6'd63); //ADC转换完毕 |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1278 浏览 1 评论
助力AIoT应用:在米尔FPGA开发板上实现Tiny YOLO V4
1033 浏览 0 评论
2349 浏览 1 评论
2060 浏览 0 评论
矩阵4x4个按键,如何把识别结果按编号01-16(十进制)显示在两个七段数码管上?
2317 浏览 0 评论
1847 浏览 48 评论
6003 浏览 113 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-20 12:13 , Processed in 0.658367 second(s), Total 72, Slave 54 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号