Baud Rate Pulse Generator
A UART should pace its bits with an enable pulse on the system clock, not with a divided-down clock that would create a second clock domain.
The solution module takes a 16-bit baud_limit input representing the number of system clock cycles per baud period. It counts system clock cycles internally. When the internal counter reaches baud_limit - 1, it asserts the tick output for exactly one clock cycle and resets the counter to zero on the next clock edge.
Clock edge and reset rules:
- Clock edge: posedge
clk - Reset type: asynchronous
- Reset polarity: active-low
rst_n - Output values on reset:
tickis0, and the internal counter resets to0
Worked trace for baud_limit = 3:
Cycle 1: rst_n=0, baud_limit=3 → count=0, tick=0
Cycle 2: rst_n=1, posedge clk → count=1, tick=0
Cycle 3: rst_n=1, posedge clk → count=2, tick=1
Cycle 4: rst_n=1, posedge clk → count=0, tick=0
Cycle 5: rst_n=1, posedge clk → count=1, tick=0
Cycle 6: rst_n=1, posedge clk → count=2, tick=1
{ "signal": [
{ "name": "clk", "wave": "p......" },
{ "name": "rst_n", "wave": "01....." },
{ "name": "baud_limit", "wave": "2......", "data": ["3"] },
{},
{ "name": "count (internal)", "wave": "222222.", "data": ["0","1","2","0","1","2"] },
{ "name": "tick", "wave": "001001." }
], "head": { "text": "Baud tick generation for baud_limit = 3." } }
| Signal | Direction | Width | Description |
|---|---|---|---|
clk |
input | 1 | Positive-edge triggered system clock |
rst_n |
input | 1 | Asynchronous active-low reset; counter and tick go to 0 |
baud_limit |
input | 16 | Number of clock cycles per baud period (always ≥ 2) |
tick |
output | 1 | Single-cycle pulse asserted when counter reaches baud_limit - 1 |
Constraints
- The
clkinput is positive-edge triggered andrst_nis asynchronous active-low. - The
tickoutput must be0whenrst_nis asserted. - The internal counter must be 16 bits wide to support large
baud_limitvalues up to16'hFFFF. - The
baud_limitinput is guaranteed to be stable and ≥ 2 during operation. - The
tickoutput is a combinational signal that evaluates to1during the clock cycle where the internal counter equalsbaud_limit - 1.
Topics
Solve this problem
Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against the problem's testbench. You get the waveform back, not a stored answer.
This problem is part of Codiode Pro. The statement above is free to read.
The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.
Part of Interfaces and Protocols
Problem 9 of 19 in the Interfaces and Protocols track.
Related problems
Browse all problems · Verilog practice problems · Learning tracks