汇川低压变频器有个输出霍尔检测,用veriog实现

/* 1、根据汇川变频器的逐波限流保护原理用verilog实现:
   检测下降沿,cnt计数到3就保护输出
   同时计时计数器(cnt2)开始计数,时间到了,就给模3计数器复位
   也就是连续的过流才保护    
    
*/


module oc_protection(clk,rst,data,set_o);
   input   clk ;
   input   rst ;
   input   data;
    output  set_o;
edge_detect e_d(
                .clk (clk),
                     .rst (rst),
                     .data (data) ,
                     .neg_detect (neg_detect) 
                     );
cnt_oc1 c_oc1  (
                .neg_detect(neg_detect) ,
                .rst(set) ,
                     .set(set_o) ,
                     );
cnt_oc2 c_oc2  (
                .clk (clk),
                     .rst (rst),
                     .set(set) ,
                     );
                        
endmodule

/* 2、
 下降沿检测,时钟频率太低可能丢失信号
 */

module edge_detect (
    input clk,
    input rst,
    input data,
    //output wire pose_detect ,
    //output wire dou_detect ,
    output wire neg_detect
);
    reg d1, d2;

  always @(posedge clk or negedge rst) begin
      if(!rst)
        begin
            d1 <= 0;
            d2 <= 0; 
        end
      else begin
            d1 <= data;
            d2 <= d1;
        end
  end

  //assign pose_detect = d1 & (~d2);  //上升
      //下降 
  //assign dou_detect  = d1 ^ d2;     //双沿
    assign neg_detect  = (~d1) & d2;
endmodule
 

/* 3、以带使能的模100异步清零计数器为例
*/
 

module cnt_oc1 (
input neg_detect,
input rst,
output reg set       //如果参数化中COUNT比较大,需要更改out的位宽来适配
    );
  
parameter COUNT=3 ;
reg [1:0]out ;
always@(posedge neg_detect or negedge rst) //异步清零
begin 
if(!rst)
        begin out<=2'd0; set<=1'b0; end
else if(out==COUNT-1)
        begin out<=2'd0; set<=1'b1; end 
else 
          begin  out<=out+1'b1; set<=1'b0; end 
end 
endmodule    

/* 4、以带使能的模100异步清零计数器为例
*/
 

module cnt_oc2 (
input clk,
input rst,
output reg set       //如果参数化中COUNT比较大,需要更改out的位宽来适配
    );
  
parameter COUNT=10 ;
reg [3:0]out ;
always@(posedge clk or negedge rst) //异步清零
begin 
if(!rst)
        begin out<=4'd0; set<=1'b1; end
else if(out==COUNT-1)
        begin out<=4'd0; set<=1'b0; end 
else 
          begin  out<=out+1'b1; set<=1'b1; end 
end 
endmodule    
       /*

01-edge_detect

 


        
           
cnt_oc1   

 

 

 

 cnt_oc2

oc_protection

新手练手的,感谢各位留言

      
          
   
 

       
        
           
   

          
      
          
   
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值