|
42 | 42 | localparam LOWER_THRESHOLD_LOW_PHASE = 4; |
43 | 43 | localparam FINAL_STATE = 5; |
44 | 44 |
|
| 45 | + localparam PAUSE_DURATION = 4; |
| 46 | + |
45 | 47 | reg enable; |
46 | 48 | reg[7:0] clk_counter; |
47 | 49 | reg[7:0] impulse_counter; |
48 | 50 | reg[7:0] total_impulse_counter; |
| 51 | + reg impulse_rejected; |
| 52 | + //reg[7:0] selected_impulse_counter; |
49 | 53 | reg[2:0] state; |
50 | 54 | reg impulse_selected; |
51 | 55 |
|
|
56 | 60 | clk_counter <= 0; |
57 | 61 | impulse_counter <= 0; |
58 | 62 | total_impulse_counter <= 0; |
59 | | - impulse_selected <= 0; |
| 63 | + // impulse_selected <= 0; |
60 | 64 | state <= INITIAL_STATE; |
61 | 65 | lower_threshold <= 0; |
62 | 66 | upper_threshold <= 0; |
63 | 67 | enable <= 1; |
| 68 | + impulse_rejected <= 1; |
64 | 69 | end |
65 | 70 | else |
66 | 71 | begin |
|
72 | 77 | begin |
73 | 78 | clk_counter <= 0; |
74 | 79 | state <= LOWER_THRESHOLD_HIGH_PHASE; |
| 80 | + impulse_rejected <= 0; |
75 | 81 | end |
76 | 82 | LOWER_THRESHOLD_HIGH_PHASE: |
77 | 83 | begin |
78 | 84 | lower_threshold <= 1; |
79 | | - clk_counter <= 0; |
80 | | - //if((impulse_selected == 0 || impulse_counter == 0) && impulse_counter <= IMPULSES_FOR_SELECTION) |
81 | | - if(impulse_selected == 0 && impulse_counter <= IMPULSES_FOR_SELECTION) |
| 85 | + if(clk_counter == 1) |
| 86 | + begin |
| 87 | + // check should we generate upper |
| 88 | + if(impulse_counter <= IMPULSES_FOR_SELECTION) |
| 89 | + state <= LOWER_THRESHOLD_LOW_PHASE; |
| 90 | + else state <= UPPER_THRESHOLD_HIGH_PHASE;; |
| 91 | + end |
| 92 | + //clk_counter <= 0; |
| 93 | + /*if(impulse_counter <= IMPULSES_FOR_SELECTION) |
82 | 94 | begin |
83 | 95 | state <= LOWER_THRESHOLD_LOW_PHASE; |
84 | | - impulse_selected <= 1; |
| 96 | + // impulse_selected <= 1; |
85 | 97 | impulse_counter <= impulse_counter + 1; |
86 | 98 | end |
87 | | - else state <= UPPER_THRESHOLD_HIGH_PHASE; |
| 99 | + else |
| 100 | + begin |
| 101 | + state <= FINAL_STATE; //UPPER_THRESHOLD_HIGH_PHASE; |
| 102 | + end*/ |
88 | 103 | end |
89 | 104 | UPPER_THRESHOLD_HIGH_PHASE: |
90 | 105 | begin |
91 | | - impulse_selected <= 0; |
| 106 | + impulse_rejected <= 1; |
92 | 107 | upper_threshold <= 1; |
93 | | - if(clk_counter == UPPER_THRESHOLD_DURATION) |
| 108 | + if(clk_counter == UPPER_THRESHOLD_DURATION + 1) |
94 | 109 | state <= UPPER_THRESHOLD_LOW_PHASE; |
95 | 110 | end |
96 | 111 | UPPER_THRESHOLD_LOW_PHASE: |
|
100 | 115 | end |
101 | 116 | LOWER_THRESHOLD_LOW_PHASE: |
102 | 117 | begin |
103 | | - lower_threshold <= 0; |
104 | | - if(clk_counter == LOWER_THRESHOLD_DURATION) |
105 | | - begin |
| 118 | + lower_threshold <= 0; |
| 119 | + if(clk_counter >= LOWER_THRESHOLD_DURATION) |
| 120 | + begin |
| 121 | + if(impulse_rejected == 0) |
| 122 | + impulse_counter <= impulse_counter + 1; |
106 | 123 | total_impulse_counter <= total_impulse_counter + 1; |
107 | 124 | if(total_impulse_counter == IMPULSES_PER_CHANNEL) |
108 | 125 | state <= FINAL_STATE; |
|
112 | 129 | FINAL_STATE: |
113 | 130 | begin |
114 | 131 | state <= INITIAL_STATE; |
| 132 | + //impulse_selected <= 0; |
| 133 | + impulse_counter <= 0; |
| 134 | + total_impulse_counter <= 0; |
| 135 | + //impulse_selected <= 0; |
115 | 136 | end |
116 | 137 | default: |
117 | 138 | begin |
|
120 | 141 | end |
121 | 142 | else |
122 | 143 | begin |
123 | | - impulse_selected <= 0; |
| 144 | + //impulse_selected <= 0; |
124 | 145 | total_impulse_counter <= 0; |
125 | | - impulse_selected <= 0; |
| 146 | + //impulse_selected <= 0; |
126 | 147 | end |
127 | 148 | end |
128 | 149 | end |
|
0 commit comments