RAMILE 发表于 2014-9-24 21:09:54

写了一个单稳态触发电路

本帖最后由 RAMILE 于 2014-9-24 23:23 编辑

单稳态触发计数器,在trig的上升沿开启计数,当计数达到进位时候触发状态翻转,停止计数,等待下一个trig的上升沿到来

这个电路使用两个T flip-flop进行xor计算控制计数器累计,其中一个T flip-flop检测trig,另一个检测count的进位边沿
module monostable
(
        input clk,
        input trig,
        output testout2
);
parameter WIDTH = 10;
reg state_in;
reg state_ref;
reg [(WIDTH-1):0]coutn_out;

wire trig_gate;
wire trig_out;
wire carry;

assign carry = coutn_out;
assign trig_gate = testout2;
assign trig_out = trig & trig_gate;

//assign testout =coutn_out[(WIDTH-1):0];
assign testout2 = ( state_ref == state_in);
       
always @(posedge trig)
        if(testout2)
                state_in = ~state_in;
        else
                state_in =state_in;

always @(posedge clk)begin
        if(state_in != state_ref)
                coutn_out= coutn_out + 1'b1;
        else
                coutn_out = 0;
end               

always @(posedge carry )
        state_ref <= ~state_ref;

endmodule

linbo411 发表于 2015-11-28 17:26:18

你写反了,这里的OUT其实是输入波形,in是要得到的输出波形
页: [1]
查看完整版本: 写了一个单稳态触发电路