UART testbench

U

uche

Guest
I am using the following code to test the Ken Chapman's UART. When I
run the following code and see the FIFO data at the 'command'
output,
I do not get 'A' as intended by the design. Instead, I get some other
bit patterns that doesn't make sense. Can anyone see what I am doing
wrong with the testbench. Also, I am assuming that I do not need to
tamper with the underlying Ken Chapman UART!

module behavioural_UART_Tx


#(parameter bit_time = 104000) // nanoseconds @ 9600 bps
(output reg line);


initial
line = 1'b1; // line idles true


task send(input [7:0] data);
reg [9:0] uart_frame;
begin
// construct the whole frame with start and stop bit
// STOP data START
uart_frame = {1'b1, data, 1'b0};
repeat (10) // number of bit-symbols to send
begin
line = uart_frame[0]; // drive line to correct level
uart_frame = uart_frame >> 1; // prepare next bit
#(bit_time); // hold output for one bit time
end
end
endtask


endmodule


module TB;


wire line;
// And any other signals you need for your DUT
// such as clock, reset, data-bus...
reg clk;
reg xreset;
wire buffer_full;
wire present;
wire baud;
wire [7:0] command;


// And any clock generators, etc...
// declared inside RX and TX module
always #3.2 clk = ~clk; //155.52 Mhz input


// Here's the UART signal generator...
behavioural_UART_Tx DUT0(.line(line));


Top_Rx DUT1(
.serial_in(line),
.data_out_rx(command),
.read_buffer_rx(1'b0), //read buffer enabled
.en_16_x_baud(baud),
.clk(clk),
.buffer_present_rx(present),
.buffer_full_rx(buffer_full),
.xreset(xreset));


baud_timer DUT2(
.clk(clk),
.reset(xreset),
.en_16_x_baud(baud));


initial begin: StimGen
// Hang around for a while...
clk = 0;
//reset_buffer = 1;
#50;
xreset = 1;
#50 xreset = 0;


// Use the Tx model to send a few characters to the DUT:
#200000;
DUT0.send("B"); //reset device
// Idle awhile:
#200000;
// Send a newline character (LF = 10)
//tx_model.send(10);
end
endmodule
 
On Tue, 23 Jun 2009 08:22:26 -0700 (PDT), uche wrote:

I am using the following code to test the Ken Chapman's UART. When I
run the following code and see the FIFO data at the 'command'
output,
I do not get 'A' as intended by the design. Instead, I get some other
bit patterns that doesn't make sense. Can anyone see what I am doing
wrong with the testbench. Also, I am assuming that I do not need to
tamper with the underlying Ken Chapman UART!

module behavioural_UART_Tx
I recognize that BFM code... hmmmm.

The testbench looks vaguely OK. Is the reset
really active-high? When you look at waveforms,
do you see something sensible on the serial line?
Are you sure that the baud rate timer is correctly
giving a pulse one clock cycle wide, at a rate
of 16x9600 Hz?

Most of all, if the bit patterns don't make sense
to you, how are they possibly expected to make sense
to us if you don't tell us what they are?!!!

I used the VHDL version of Ken Chapman's UART and it
worked perfectly. Since it's a bunch of instantiated
primitives, I guess the Verilog version would be
equally good.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley@MYCOMPANY.com
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 
On Jun 23, 8:55 am, Jonathan Bromley <jonathan.brom...@MYCOMPANY.com>
wrote:
On Tue, 23 Jun 2009 08:22:26 -0700 (PDT), uche wrote:
I am using the following code to test the Ken Chapman's UART. When I
run the following code and see the FIFO data  at the 'command'
output,
I do not get 'A' as intended by the design. Instead, I get some other
bit patterns that doesn't make sense. Can anyone see what I am doing
wrong with the testbench. Also, I am assuming that I do not need to
tamper with the underlying Ken Chapman UART!

module behavioural_UART_Tx

I recognize that BFM code... hmmmm.

The testbench looks vaguely OK.  Is the reset
really active-high?  When you look at waveforms,
do you see something sensible on the serial line?
Are you sure that the baud rate timer is correctly
giving a pulse one clock cycle wide, at a rate
of 16x9600 Hz?

Most of all, if the bit patterns don't make sense
to you, how are they possibly expected to make sense
to us if you don't tell us what they are?!!!

I used the VHDL version of Ken Chapman's UART and it
worked perfectly.  Since it's a bunch of instantiated
primitives, I guess the Verilog version would be
equally good.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.brom...@MYCOMPANY.comhttp://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
When I input an "A", I get 1110100 at the output. This doesn't make
sense.
 
On Tue, 23 Jun 2009 20:28:32 -0700 (PDT), uche wrote:

[Jonathan Bromley]
The testbench looks vaguely OK.  Is the reset
really active-high?  When you look at waveforms,
do you see something sensible on the serial line?
Are you sure that the baud rate timer is correctly
giving a pulse one clock cycle wide, at a rate
of 16x9600 Hz?
[uche]
When I input an "A", I get 1110100 at the output.
This doesn't make sense.
It might make sense, if your baud rate clock is wrong.
What are the answers to my questions (above)? Generally
I find that debugging proceeds better if I progressively
eliminate possible causes of error. Looking at the final
output and stating that it doesn't make sense is unlikely
to get you closer to a solution.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley@MYCOMPANY.com
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 

Welcome to EDABoard.com

Sponsor

Back
Top