From 0ee7abe61cf8fba5aaea56c3bccb038144f52cc9 Mon Sep 17 00:00:00 2001 From: Elizabeth Esparza Date: Fri, 17 Jan 2025 12:07:37 -0600 Subject: [PATCH] feat: debug UART timing --- test/tb.v | 6 +++--- test/test.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/test/tb.v b/test/tb.v index fe60ddf..e169a14 100644 --- a/test/tb.v +++ b/test/tb.v @@ -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; @@ -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) ); @@ -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 @@ -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 diff --git a/test/test.py b/test/test.py index 8441262..b032d34 100644 --- a/test/test.py +++ b/test/test.py @@ -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") @@ -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()) @@ -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"