OpenCores
URL https://opencores.org/ocsvn/q_rotary_enc/q_rotary_enc/trunk

Subversion Repositories q_rotary_enc

[/] [q_rotary_enc/] [lpf_cap.sv] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 Papayaved
/*
2
Simple low-pass filter. Digital capacity
3
*/
4
 
5
`ifndef _lpf_cap_
6
`define _lpf_cap_
7
 
8
module lpf_cap #(parameter FILTER_WIDTH = 7)( // about half bit
9
        input clock, sclr,
10
        input in,
11
        output out,
12
        output init
13
);
14
 
15
reg [FILTER_WIDTH-1:0] cnt = {1'b1, {(FILTER_WIDTH-2){1'b0}}};
16
always_ff @(posedge clock)
17
        if (sclr)
18
                cnt <= {1'b1, {(FILTER_WIDTH-2){1'b0}}}; // middle value
19
        else if (in == 1'b1 && cnt != '1)
20
                cnt <= cnt + 1'b1; // charging
21
        else if (in == 1'b0 && cnt != '0)
22
                cnt <= cnt - 1'b1; // discharging
23
 
24
reg out_reg = 1'b0;
25
always_ff @(posedge clock)
26
        if (sclr)
27
                out_reg <= 1'b0;
28
        else if (cnt == '1) // full
29
                out_reg <= 1'b1;
30
        else if (cnt == '0) // empty
31
                out_reg <= 1'b0;
32
 
33
assign out = out_reg;
34
 
35
reg init_reg = 1'b1;
36
always_ff @(posedge clock)
37
        if (sclr)
38
                init_reg <= 1'b1;
39
        else if (cnt == '1 || cnt == '0)
40
                init_reg <= 1'b0;
41
 
42
assign init = init_reg;
43
 
44
endmodule :lpf_cap
45
 
46
`endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.