完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
module encode_rx_data( input sys_clk, //50MH input sys_rst, // input rx_bit, //input bit pin output ssi_clk, // 提供SSI接收器专用时钟 output reg [16:0] CPR_data, //output data output data_ready, output data_end ); reg data_end_flag; assign data_end = data_end_flag; reg [4:0] count_ssi_bits_count; //???????ssi bit?????17??????????16????????? reg [5:0] SSI_freq_cnt; reg [5:0] ssi_neg_count; reg [5:0] SSI_clock_cnt; parameter SSI_freq = 6'd50;//??????1/T?0.5M~2.5M???????1M???????????1M??,50M/1M=48 parameter SSI_bit = 5'd17;//??????1/T?0.5M~2.5M???????1M???????????1M??,50M/1M=48 reg [16:0] CPR_data_bits; reg [2:0] Current_STATE; reg [2:0] NEXT__STATE ; parameter [2:0] IDLE = 3'd0, RECEIVE = 3'd1, STOP = 3'd2; reg SSI_CLOCK_flag; assign ssi_clk = SSI_CLOCK_flag; reg [16:0] Monoflop_time_cnt ; parameter Monoflop_time = 1500; wire Monoflop_END; reg [5:0] SSI_STOP_cnt ; wire SSI_STOP_end ; reg data_over ; always@(posedge sys_clk or negedge sys_rst) begin if(sys_rst== 1'b0) Current_STATE<=IDLE; else Current_STATE<=NEXT__STATE; end //数据准备 always@(*) begin if(sys_rst== 1'b0) NEXT__STATE<=IDLE; else begin case(Current_STATE) IDLE : if(Monoflop_END) NEXT__STATE <= RECEIVE; else NEXT__STATE <= IDLE; RECEIVE : if(count_ssi_bits_count==SSI_bit&&SSI_freq_cnt==SSI_freq/2) NEXT__STATE <= STOP; else NEXT__STATE <= RECEIVE; STOP : if(SSI_STOP_end == 1) NEXT__STATE <= IDLE; else NEXT__STATE <= STOP; default : NEXT__STATE<=IDLE; endcase end end always@(posedge sys_clk or negedge sys_rst) begin if(sys_rst== 1'b0) begin Monoflop_time_cnt <= 0 ; end else if(Current_STATE==IDLE) begin if(Monoflop_time_cnt==(Monoflop_time-1)) begin Monoflop_time_cnt <= 0 ; end else begin Monoflop_time_cnt <= Monoflop_time_cnt+1'd1; end end end assign Monoflop_END=(Monoflop_time_cnt==(Monoflop_time-1))?1:0; always@(posedge sys_clk or negedge sys_rst) begin if(sys_rst== 1'b0) begin count_ssi_bits_count <= 5'd0; SSI_freq_cnt<=0; end else if(Current_STATE==RECEIVE) begin if(SSI_freq_cnt==SSI_freq-1) begin if( count_ssi_bits_count==(SSI_bit)&&SSI_freq_cnt==SSI_freq-1) begin count_ssi_bits_count <= 0; SSI_freq_cnt<=0; end else begin SSI_freq_cnt<=0; count_ssi_bits_count <= count_ssi_bits_count + 5'd1; end end else begin SSI_freq_cnt <= SSI_freq_cnt+1; end end end always@(posedge sys_clk or negedge sys_rst) begin if(sys_rst== 1'b0) begin ssi_neg_count <= 5'd0; SSI_clock_cnt<=0; end else if(Current_STATE==RECEIVE) begin if(SSI_clock_cnt==SSI_freq/2-1) begin if( ssi_neg_count==(2*SSI_bit+1)&&SSI_clock_cnt==SSI_freq/2-1) ssi_neg_count <= 0; else begin SSI_clock_cnt<=0; ssi_neg_count <= ssi_neg_count + 5'd1; end SSI_clock_cnt <= 0; end else begin SSI_clock_cnt <= SSI_clock_cnt+1; end end end always@(*) begin if(sys_rst== 1'b0) SSI_CLOCK_flag<=1; else if(Current_STATE==RECEIVE) begin case(ssi_neg_count) 0 : SSI_CLOCK_flag<=0; 1 : SSI_CLOCK_flag<=1; 2 : SSI_CLOCK_flag<=0; 3 : SSI_CLOCK_flag<=1; 4 : SSI_CLOCK_flag<=0; 5 : SSI_CLOCK_flag<=1; 6 : SSI_CLOCK_flag<=0; 7 : SSI_CLOCK_flag<=1; 8 : SSI_CLOCK_flag<=0; 9 : SSI_CLOCK_flag<=1; 10 : SSI_CLOCK_flag<=0; 11 : SSI_CLOCK_flag<=1; 12 : SSI_CLOCK_flag<=0; 13 : SSI_CLOCK_flag<=1; 14 : SSI_CLOCK_flag<=0; 15 : SSI_CLOCK_flag<=1; 16 : SSI_CLOCK_flag<=0; 17 : SSI_CLOCK_flag<=1; 18 : SSI_CLOCK_flag<=0; 19 : SSI_CLOCK_flag<=1; 20 : SSI_CLOCK_flag<=0; 21 : SSI_CLOCK_flag<=1; 22 : SSI_CLOCK_flag<=0; 23 : SSI_CLOCK_flag<=1; 24 : SSI_CLOCK_flag<=0; 25 : SSI_CLOCK_flag<=1; 26 : SSI_CLOCK_flag<=0; 27 : SSI_CLOCK_flag<=1; 28 : SSI_CLOCK_flag<=0; 29 : SSI_CLOCK_flag<=1; 30 : SSI_CLOCK_flag<=0; 31 : SSI_CLOCK_flag<=1; 32 : SSI_CLOCK_flag<=0; 33 : SSI_CLOCK_flag<=1; 34 : SSI_CLOCK_flag<=0; 35 : SSI_CLOCK_flag<=1; default : SSI_CLOCK_flag<=1; endcase end end always@(posedge sys_clk or negedge sys_rst) begin if(sys_rst== 1'b0) begin SSI_STOP_cnt <= 0 ; end else if(Current_STATE==STOP) begin if(SSI_STOP_cnt==SSI_freq/2-1) begin SSI_STOP_cnt <= 0 ; end else begin SSI_STOP_cnt <= SSI_STOP_cnt+1'd1; CPR_data <= CPR_data_bits; data_end_flag<=1; end end end assign SSI_STOP_end=(SSI_STOP_cnt==SSI_freq/2-1)? 1:0; //接收串行数据位数据 always@(posedge sys_clk or negedge sys_rst) begin if(sys_rst== 1'b0) CPR_data_bits <= 17'b0; else if(Current_STATE == RECEIVE &&SSI_freq_cnt==SSI_freq-1&&NEXT__STATE!=STOP) CPR_data_bits[SSI_bit-count_ssi_bits_count-1] <= rx_bit; //SSI_bit == 17 else CPR_data_bits <= CPR_data_bits; end endmodule 测试代码 `timescale 1 ns/ 1 psmodule encode_rx_data_test(); reg rx_bit; reg sys_clk; reg sys_rst; wire [16:0] CPR_data; wire data_end; wire data_ready; wire ssi_clk; encode_rx_data u_encode_rx_data( .CPR_data(CPR_data), .data_end(data_end), .data_ready(data_ready), .rx_bit(rx_bit), .ssi_clk(ssi_clk), .sys_clk(sys_clk), .sys_rst(sys_rst) ); initial begin sys_clk = 1'b0; sys_rst = 1'b0; #200 sys_rst = 1'b1; end always #10 sys_clk = ~sys_clk; endmodule// |
|
相关推荐
1 条评论
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1421 浏览 1 评论
1215 浏览 0 评论
矩阵4x4个按键,如何把识别结果按编号01-16(十进制)显示在两个七段数码管上?
1426 浏览 0 评论
913 浏览 0 评论
2229 浏览 0 评论
1432 浏览 35 评论
5616 浏览 113 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 18:41 , Processed in 0.684079 second(s), Total 82, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号