A rising edge is when a signal changes from low (0) to high (1). It is like a switch turning on.
Click to reveal answer
beginner
How does a falling edge differ from a rising edge?
A falling edge is when a signal changes from high (1) to low (0). It is like a switch turning off.
Click to reveal answer
beginner
What is the purpose of an edge detector in Verilog?
An edge detector finds when a signal changes state, either rising, falling, or both. It helps circuits react only at those moments.
Click to reveal answer
intermediate
Show a simple Verilog code snippet for detecting a rising edge of a signal 'sig'.
always @(posedge clk) begin
prev_sig <= sig;
rising_edge_detected <= sig & ~prev_sig;
end
This code saves the previous signal and checks if current is 1 and previous was 0.
Click to reveal answer
intermediate
How can you detect both rising and falling edges in Verilog?
By comparing the current and previous signal values:
- rising edge: current=1 and previous=0
- falling edge: current=0 and previous=1
Detect both by checking if current != previous.
Click to reveal answer
What does a rising edge detector check for in a signal?
ASignal changes from 1 to 0
BSignal changes from 0 to 1
CSignal stays at 1
DSignal stays at 0
✗ Incorrect
A rising edge means the signal goes from low (0) to high (1).
In Verilog, which keyword is used to trigger code on a rising edge of a clock?
Anegedge
Balways
Cedge
Dposedge
✗ Incorrect
The 'posedge' keyword triggers on the rising edge of a signal.
How do you detect a falling edge in Verilog?
Acurrent=0 and previous=1
Bcurrent=1 and previous=0
Ccurrent=previous
Dcurrent=1 and previous=1
✗ Incorrect
A falling edge is when the signal changes from 1 to 0.
What does the expression 'sig & ~prev_sig' detect?
ARising edge
BBoth edges
CNo change
DFalling edge
✗ Incorrect
It detects when current signal is 1 and previous was 0, a rising edge.
Which condition detects both rising and falling edges?
Acurrent == previous
Bcurrent & previous
Ccurrent != previous
D~current & ~previous
✗ Incorrect
If current and previous differ, an edge occurred (rising or falling).
Explain how to detect a rising edge of a signal in Verilog using a previous value register.
Think about saving the signal value each clock and checking if it changed from 0 to 1.
You got /3 concepts.
Describe how to detect both rising and falling edges of a signal in Verilog.
Any difference between current and previous means an edge happened.
You got /3 concepts.
Practice
(1/5)
1. What does a rising edge detector in Verilog detect? always @(posedge clk) is often used in such detectors.
easy
A. Both 0 to 1 and 1 to 0 changes
B. A change of signal from 1 to 0
C. A change of signal from 0 to 1
D. No change in signal
Solution
Step 1: Understand rising edge meaning
A rising edge means the signal changes from low (0) to high (1).
Step 2: Relate to Verilog edge detection
The posedge keyword triggers on this rising edge.
Final Answer:
A change of signal from 0 to 1 -> Option C
Quick Check:
Rising edge = 0 to 1 transition [OK]
Hint: Rising edge means signal goes from 0 to 1 [OK]
Common Mistakes:
Confusing rising edge with falling edge
Thinking it detects no change
Mixing up posedge and negedge keywords
2. Which of the following Verilog code snippets correctly detects a falling edge of signal sig?
easy
A. always @(negedge sig) begin // detect falling edge end
B. always @(posedge sig) begin // detect falling edge end
C. always @(sig) begin // detect falling edge end
D. always @(posedge clk) if (sig == 1) // detect falling edge
Solution
Step 1: Identify falling edge keyword
Falling edge detection uses negedge in Verilog.
Step 2: Match code to falling edge
always @(negedge sig) begin // detect falling edge end uses always @(negedge sig), which triggers on signal going from 1 to 0.
Final Answer:
always @(negedge sig) begin // detect falling edge end -> Option A
Quick Check:
Falling edge = negedge keyword [OK]
Hint: Use negedge to detect falling edges in Verilog [OK]
Common Mistakes:
Using posedge for falling edge detection
Using level-sensitive sensitivity list
Confusing signal and clock edges
3. Given this Verilog code snippet for detecting both edges of sig:
reg sig_d;
always @(posedge clk) begin
sig_d <= sig;
end
wire edge_detect = sig ^ sig_d;
What is the value of edge_detect when sig changes from 0 to 1?
medium
A. 1
B. 0
C. Undefined (X)
D. Remains previous value
Solution
Step 1: Understand delayed signal sig_d
sig_d holds previous clock cycle's sig value.
Step 2: Calculate XOR for edge detection
When sig changes from 0 to 1, XOR with previous 0 gives 1, indicating an edge.
Final Answer:
1 -> Option A
Quick Check:
sig ^ sig_d = 1 on edge [OK]
Hint: XOR current and delayed signal to detect edges [OK]
Common Mistakes:
Forgetting to delay signal before XOR
Assuming edge_detect stays 0 on change
Confusing XOR with AND or OR
4. Identify the error in this Verilog code intended to detect a rising edge of sig:
reg sig_d;
always @(posedge clk) begin
sig_d <= sig;
end
wire rising_edge = sig & ~sig_d;
medium
A. Using blocking assignment instead of non-blocking
B. Incorrect logic for rising edge detection
C. No sensitivity list for wire rising_edge
D. Missing initial value for sig_d
Solution
Step 1: Analyze rising edge logic
Rising edge is when signal changes from 0 to 1, so previous was 0 and current is 1.
Step 2: Check given logic expression
The expression sig & ~sig_d correctly detects rising edge by current high and previous low.
Step 3: Re-examine for errors
Actually, the logic is correct; the error is elsewhere.
Step 4: Identify actual error
Missing initial value for sig_d can cause unknown behavior at start.
Final Answer:
Missing initial value for sig_d -> Option D
Quick Check:
Initialize delayed signal to avoid unknowns [OK]
Hint: Initialize delayed signals to avoid unknown start values [OK]
Common Mistakes:
Assuming logic expression is wrong
Ignoring initial values for registers
Confusing blocking and non-blocking assignments
5. You want to design a Verilog module that outputs a pulse of 1 clock cycle width whenever sig changes either from 0 to 1 or 1 to 0. Which code snippet correctly implements this?
hard
A. reg sig_d;
always @(posedge clk) sig_d <= sig;
wire edge_pulse = sig & ~sig_d;
B. reg sig_d;
always @(posedge clk) sig_d <= sig;
wire edge_pulse = sig ^ sig_d;
C. wire edge_pulse = (sig == 1) ? 1 : 0;
D. always @(posedge sig) edge_pulse = 1;
Solution
Step 1: Understand requirement for both edges
The pulse should be high for one clock cycle on any signal change (rising or falling).
Step 2: Analyze each option
reg sig_d;
always @(posedge clk) sig_d <= sig;
wire edge_pulse = sig ^ sig_d; uses XOR between current and delayed signal, which is 1 only on change, producing a 1-cycle pulse.
Step 3: Confirm other options
reg sig_d;
always @(posedge clk) sig_d <= sig;
wire edge_pulse = sig & ~sig_d; detects only rising edge; C is level detection; D triggers on posedge of sig, not clock, and lacks pulse width control.
Final Answer:
reg sig_d;
always @(posedge clk) sig_d <= sig;
wire edge_pulse = sig ^ sig_d; -> Option B
Quick Check:
XOR current and delayed signal for both edges pulse [OK]
Hint: XOR current and delayed signals for both edges pulse [OK]
Common Mistakes:
Using only rising edge logic for both edges
Triggering on signal edge instead of clock
Not producing single clock cycle pulse
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.