找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1263|回复: 0
打印 上一主题 下一主题
收起左侧

有那个大佬帮忙说一下仿真testbench里Trig信号怎么设置吗?

[复制链接]
跳转到指定楼层
楼主
ID:525536 发表于 2019-5-1 21:21 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
module  SRF_Control(sys_clk,sys_rst_n,echo,Distance,Trig):
                input                       sys_clk;
                input                       sys_rst_n;
                input                       echo;
                output[13:0]                Distance;
                output                      Trig;
      
      
      
      reg                         Trig;
                reg[31:0]                   Distance_r;
                assign                      Distance = Distance_r/2941;//calculate and output ultrasonic obstacle distance value
                reg[3:0]                    State;
                reg[31:0]                   Trig_cnt;
                reg[31:0]                   Timeout_cnt;
                reg[31:0]                   echo_cnt;
                reg                         echo_r;
               
                always@(posedge sys_clk or negedge sys_rst_n)
                begin
                         if(!sys_rst_n)
                                           echo_r <= 1'b0;
                         else
                                           echo_r <= echo;
                end

                always@(posedge sys_clk or negedge sys_rst_n)
                begin
                if(!sys_rst_n)
                         begin
                         State        <= 4'd0 ;
                         Trig          <= 1'b0;
                         Trig_cnt    <= 32'd0 ;
                         echo_cnt   <= 32'd0 ;
                         Distance_r <= 32'd0 ;
                         Timeout_cnt   <= 32'd0;
                         end
                else
                         begin
                         case(State)
                         4'd0:        begin
                                         Trig          <= 1'b0;
                                         Trig_cnt    <= 32'd0;
                                         echo_cnt   <= 32'd0;
                                         Timeout_cnt   <= 32'd0;
                                         State          <= 4'd1;
                                         end
                         4'd1:        begin
                                         Trig          <= 1'b1;
                                         if(Trig_cnt==32'd500000)begin
                                                         Trig_cnt <= 32'd0;
                                                         State <= 4'd2;
                                                         end
                                         else begin
                                                         Trig_cnt <= Trig_cnt+1;
                                                         State <= 4'd1;
                              end
              end
                        4'd2:         begin
                                         Trig    <= 1'b0;
                                         if(Trig_cnt == 32'd500)begin
                                                          Trig_cnt <= 32'd0;
                                                          State      <= 4'd3;
                                                          end
                                         else begin
                                                          Trig_cnt <= Trig_cnt+1;
                                                          State     <= 4'd2;
                                                          end
                                         end            
                        4'd3:         begin              
                                         if(!echo_r)      
                                                          State <= 4'd4;
                                         else            
                                                          State <= 4'd3;
                                         end
                        4'd4:         begin
                                         if(!echo_r)  State <= 4'd5;
                                         else if(Timeout_cnt == 32'd50000000)begin
                                                           Timeout_cnt <= 0;
                                                           State   <=   4'd0;  end
                                         else begin
                                                           Timeout_cnt <= Timeout_cnt+1;
                                                           State    <=   4'd4;  end
                                         end            
                        4'd5:         begin         
                                         if(!echo_r)  State    <=   4'd6;
                                         else begin  
                                                           echo_cnt <= echo_cnt+1;
                                                           State    <=   4'd5;
                                                end      
                                         end            
                        4'd6:         begin           
                                         Distance_r <= echo_cnt;
                                         if(Timeout_cnt == 32'd50000000) begin
                                                           Timeout_cnt <= 0;
                                                           State   <=   4'd0;   end
                                         else begin  Timeout_cnt <= Timeout_cnt+1;
                                                           State   <=   4'd6;   end
                                         State   <=   4'd0;
                                         end
                        default:     State   <=   4'd0;
                        endcase
                        end
               end
endmodule      
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表