1
\$\begingroup\$

I am trying to add a reset to a counter and I have this code, that syntethize perfectly:

module syncRX(clk, signal, detect);
 input clk, signal;
 output [7:0] detect;
 
 reg [7:0] detect_aux = 8'b0;
 reg rst;
 assign detect = detect_aux & ~rst;
 
 freq_div div(.clk(clk), .clk_1khz(clk_1khz));
 
 always @(posedge signal)
 rst <= 1;
 
 always @(posedge clk_1khz)
 detect_aux <= detect_aux + 1;
 
endmodule // top
module freq_div(input clk, output reg clk_1khz);
 reg [12:0] count = 0;
 always @(posedge clk)
 begin
 if(count == 6000)
 begin
 clk_1khz <= ~clk_1khz;
 count <= 0;
 end
 else
 count <= count + 1;
 end
endmodule

The problem is that

 reg rst;
 assign detect = detect_aux & ~rst;

Seams do nothingh. Is legal that I am trying? Thanks

asked Aug 24, 2020 at 15:27
\$\endgroup\$
3
  • \$\begingroup\$ It does nothing because rst is always 0. \$\endgroup\$ Commented Aug 24, 2020 at 16:20
  • 2
    \$\begingroup\$ Also, given the way you're driving it, rst should be a reg, not a wire. \$\endgroup\$ Commented Aug 24, 2020 at 16:22
  • \$\begingroup\$ Ups! Thanks Dave, you are right, I just fixed! \$\endgroup\$ Commented Aug 24, 2020 at 23:26

2 Answers 2

1
\$\begingroup\$

as already stated, you never change the value from rst to '1'

next, your rst is no reset in terms of chipdesign, but a clear signal, so rename it to clr.

"all" about real resets for modules: http://www.asic-world.com/tidbits/all_reset.html

answered Aug 24, 2020 at 21:03
\$\endgroup\$
3
\$\begingroup\$

As pointed out in comments, in your code rst is always 0, therefore it will never affect the value of detect. If you want the reset to happen, you should make rst an input to your module, and then set it high at some point in your test bench.

But you should also notice that this isn't really a reset behavior. Setting rst high will force the detect output of the module to go to zero, but as soon as rst goes low again detect will return to its previous value as stored in detect_aux. If this were a proper reset, we'd expect the counting to start anew from 0 after rst is released.

answered Aug 24, 2020 at 20:51
\$\endgroup\$
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.