Hint: Use 'output reg [width] name;' for output registers [OK]
Common Mistakes:
Placing 'reg' after 'output'
Swapping 'output' and 'reg' keywords
Omitting bit width
3. Given the following Verilog snippet inside a UART receiver module:
always @(posedge clk) begin
if (start_bit_detected) begin
bit_count <= 0;
data_reg <= 0;
end else if (bit_sample_enable) begin
data_reg <= {serial_in, data_reg[7:1]};
bit_count <= bit_count + 1;
end
end
What will be the value of data_reg after 3 samples if serial_in was 1, 0, then 1 in consecutive samples?
medium
A. 00000101 (binary)
B. 10100000 (binary)
C. 00000011 (binary)
D. 11100000 (binary)
Solution
Step 1: Understand bit shifting in data_reg
Each sample shifts data_reg right by 1 and inserts serial_in at MSB.
Shift right + insert serial_in MSB = 10100000 [OK]
Hint: Track bit shifts and insertions stepwise [OK]
Common Mistakes:
Confusing MSB and LSB positions
Assuming left shift instead of right
Ignoring initial zero value
4. In a UART receiver module, the following code snippet causes the received data to be incorrect:
always @(posedge clk) begin
if (start_bit_detected) begin
bit_count <= 0;
data_reg <= 0;
end else if (bit_sample_enable) begin
data_reg <= {data_reg[6:0], serial_in};
bit_count <= bit_count + 1;
end
end
What is the likely error in this code?
medium
A. bit_count is not incremented correctly
B. The start bit is not being detected properly
C. Bits are shifted left instead of right, causing wrong bit order
D. serial_in is not sampled at the correct clock edge
Solution
Step 1: Analyze bit shifting direction
The code shifts data_reg left by 1 bit and inserts serial_in at LSB.
Step 2: Understand UART bit order
UART typically receives LSB first, so bits should be shifted right with serial_in at MSB to maintain correct order.
Final Answer:
Bits are shifted left instead of right, causing wrong bit order -> Option C
Quick Check:
Incorrect shift direction = Bits are shifted left instead of right, causing wrong bit order [OK]
Hint: UART bits usually shift right; check shift direction [OK]
Common Mistakes:
Mixing up left and right shifts
Ignoring bit order in UART protocol
Assuming start bit detection error
5. You want to design a UART receiver module that sets a data_ready flag only after receiving all 8 data bits and the stop bit. Which approach correctly implements this behavior?
hard
A. Set data_ready when bit_count == 8 (only data bits)
B. Set data_ready immediately after detecting the start bit
C. Set data_ready after receiving 7 data bits only
D. Set data_ready when bit_count == 9 (8 data bits + 1 stop bit)
Solution
Step 1: Understand UART frame structure
A UART frame has 1 start bit, 8 data bits, and 1 stop bit.
Step 2: Determine when data is fully received
Data is ready only after all 8 data bits and the stop bit are received, so bit_count should reach 9.
Final Answer:
Set data_ready when bit_count == 9 (8 data bits + 1 stop bit) -> Option D
Quick Check:
Data ready after 9 bits = Set data_ready when bit_count == 9 (8 data bits + 1 stop bit) [OK]
Hint: Wait for all bits including stop bit before setting data_ready [OK]
Common Mistakes:
Setting data_ready too early
Ignoring stop bit in count
Confusing start bit with data bits
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.