Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to detect a rising edge on signal sig.
Verilog
wire rising_edge = sig & ~[1];Attempts:
3 left
💡 Hint
Common Mistakes
Using the current signal instead of the delayed signal for comparison.
Confusing rising edge with falling edge logic.
✗ Incorrect
To detect a rising edge, we compare the current signal
sig with its delayed version sig_d. The rising edge occurs when sig is high and sig_d is low.2fill in blank
mediumComplete the code to detect a falling edge on signal sig.
Verilog
wire falling_edge = ~sig & [1];Attempts:
3 left
💡 Hint
Common Mistakes
Using the current signal twice instead of using the delayed signal.
Mixing up the logic for rising and falling edges.
✗ Incorrect
A falling edge is detected when the current signal
sig is low and the delayed signal sig_d is high.3fill in blank
hardFix the error in the always block that updates the delayed signal sig_d.
Verilog
always @(posedge clk or posedge rst) begin if (rst) sig_d <= 1'b0; else sig_d <= [1]; end
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning
sig_d to itself causing no update.Assigning
sig_d to clock or reset signals.✗ Incorrect
The delayed signal
sig_d should be updated with the current value of sig on each clock cycle.4fill in blank
hardFill both blanks to create a module that detects both rising and falling edges of sig.
Verilog
module edge_detector( input wire clk, input wire rst, input wire sig, output wire rising, output wire falling ); reg [1]; always @(posedge clk or posedge rst) begin if (rst) [2] <= 1'b0; else [2] <= sig; end assign rising = sig & ~sig_d; assign falling = ~sig & sig_d; endmodule
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for declaration and assignment.
Not declaring the delayed signal as a register.
✗ Incorrect
The delayed signal
sig_d is declared as a register and updated inside the always block to hold the previous value of sig.5fill in blank
hardFill all three blanks to complete the module that outputs a signal edge_detected which is high on any edge (rising or falling) of sig.
Verilog
module edge_detector( input wire clk, input wire rst, input wire sig, output wire edge_detected ); reg [1]; always @(posedge clk or posedge rst) begin if (rst) [2] <= 1'b0; else [2] <= sig; end assign edge_detected = sig ^ [3]; endmodule
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for delayed signal in declaration and assignment.
Using wrong signals in the XOR operation.
✗ Incorrect
The delayed signal
sig_d is declared and updated to hold the previous value of sig. The XOR operation between sig and sig_d detects any edge.