Skip to content

Commit

Permalink
feat: debug UART timing
Browse files Browse the repository at this point in the history
  • Loading branch information
Elizabeth-0 committed Jan 17, 2025
1 parent d63cc83 commit 0ee7abe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions test/tb.v
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module tb;
reg clk;
reg rst_n;
reg rx;
wire [7:0] uo_out;
wire [2:0] wave_select;
wire white_noise_en;

Expand All @@ -13,7 +12,6 @@ module tb;
.clk(clk),
.rst_n(rst_n),
.rx(rx),
.uo_out(uo_out),
.wave_select(wave_select),
.white_noise_en(white_noise_en)
);
Expand All @@ -37,7 +35,7 @@ module tb;
integer i;
begin
rx = 1; // Idle state
#(104167); // One bit time at 9600 baud
#(104167); // Wait for idle time
rx = 0; // Start bit
#(104167);
for (i = 0; i < 8; i = i + 1) begin
Expand All @@ -55,8 +53,10 @@ module tb;
#200; // Wait for reset
send_uart_byte(8'h54); // 'T' - Triangle wave
#200;
$display("Wave Select: %b, White Noise Enable: %b", wave_select, white_noise_en);
send_uart_byte(8'h53); // 'S' - Sawtooth wave
#200;
$display("Wave Select: %b, White Noise Enable: %b", wave_select, white_noise_en);
$finish;
end
endmodule
10 changes: 10 additions & 0 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from cocotb.triggers import Timer

async def send_uart_byte(dut, byte):
"""Send a single UART byte."""
# Start bit
dut.rx.value = 0
await Timer(104167, units="ns")
Expand All @@ -16,6 +17,7 @@ async def send_uart_byte(dut, byte):

@cocotb.test()
async def test_uart_wave_selection(dut):
"""Test UART commands for wave selection."""
# Clock generation
clock = Clock(dut.clk, 40, units="ns") # 25 MHz
cocotb.start_soon(clock.start())
Expand All @@ -33,3 +35,11 @@ async def test_uart_wave_selection(dut):
await send_uart_byte(dut, 0x53) # 'S' - Sawtooth wave
await Timer(100, units="ns")
assert dut.wave_select.value == 0b001, "Sawtooth wave selection failed"

await send_uart_byte(dut, 0x4E) # 'N' - Enable white noise
await Timer(100, units="ns")
assert dut.white_noise_en.value == 1, "White noise enable failed"

await send_uart_byte(dut, 0x46) # 'F' - Disable white noise
await Timer(100, units="ns")
assert dut.white_noise_en.value == 0, "White noise disable failed"

0 comments on commit 0ee7abe

Please sign in to comment.