Rev | Line | |
---|
[28] | 1 | /* translation of counter.smv to verilog |
---|
| 2 | |
---|
| 3 | Sriram Krishnan 7/93. |
---|
| 4 | |
---|
| 5 | |
---|
| 6 | |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | |
---|
| 11 | module counter(clk); |
---|
| 12 | input clk; |
---|
| 13 | |
---|
| 14 | wire out0, out1, out2; |
---|
| 15 | |
---|
| 16 | counter_cell bit0 (clk, 1, out0); |
---|
| 17 | counter_cell bit1 (clk, out0, out1); |
---|
| 18 | counter_cell bit2 (clk, out1, out2); |
---|
| 19 | endmodule |
---|
| 20 | |
---|
| 21 | module counter_cell(clk, carry_in, carry_out); |
---|
| 22 | input clk; |
---|
| 23 | input carry_in; |
---|
| 24 | output carry_out; |
---|
| 25 | reg value; |
---|
| 26 | |
---|
| 27 | assign carry_out = value & carry_in; |
---|
| 28 | |
---|
| 29 | initial value = 0; |
---|
| 30 | |
---|
| 31 | always @(posedge clk) begin |
---|
| 32 | // value = (value + carry_in) % 2; |
---|
| 33 | case(value) |
---|
| 34 | 0: value = carry_in; |
---|
| 35 | 1: if (carry_in ==0) |
---|
| 36 | value = 1; |
---|
| 37 | else value = 0; |
---|
| 38 | endcase |
---|
| 39 | end |
---|
| 40 | endmodule |
---|
| 41 | |
---|
Note: See
TracBrowser
for help on using the repository browser.