Skip to content

Commit

Permalink
add testbench for oled module
Browse files Browse the repository at this point in the history
fix a few bugs in the oled module's startup sequence
  • Loading branch information
trun committed Apr 30, 2012
1 parent 5cb8dab commit 55f3204
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 8 deletions.
22 changes: 14 additions & 8 deletions oled_spi.v
Expand Up @@ -6,18 +6,15 @@ module oled_spi(
input wire reset, input wire reset,
input wire shutdown, input wire shutdown,


output reg cs, output wire cs,
output reg sdin, output reg sdin,
output reg sclk, output wire sclk,
output reg dc, output reg dc,
output reg res, output reg res,
output reg vbatc, output reg vbatc,
output reg vddc output reg vddc
); );


assign cs = 0;
assign sclk = !clock;

parameter WAIT = 1; parameter WAIT = 1;
parameter SEND = 2; // send 1 byte parameter SEND = 2; // send 1 byte
parameter SEND2 = 3; // send 2 bytes parameter SEND2 = 3; // send 2 bytes
Expand Down Expand Up @@ -61,6 +58,12 @@ module oled_spi(
wait_max <= 32'b0; wait_max <= 32'b0;
state <= STARTUP_1; state <= STARTUP_1;
next_state <= 1'b0; next_state <= 1'b0;

sdin <= 1'b0;
dc <= 1'b0;
res <= 1'b1;
vddc <= 1'b1;
vbatc <= 1'b1;
end end


// SHUTDOWN // SHUTDOWN
Expand Down Expand Up @@ -130,20 +133,20 @@ module oled_spi(
else if (state == STARTUP_2) begin else if (state == STARTUP_2) begin
send_buf <= 8'hAE; send_buf <= 8'hAE;
state <= SEND; state <= SEND;
next_state <= STARTUP_2; next_state <= STARTUP_3;
end end


// STARTUP_3 -- clear screen // STARTUP_3 -- clear screen
else if (state == STARTUP_3) begin else if (state == STARTUP_3) begin
rst <= 0; res <= 0;
wait_max <= 5000; // 1ms wait_max <= 5000; // 1ms
state <= WAIT; state <= WAIT;
next_state <= STARTUP_4; next_state <= STARTUP_4;
end end


// STARTUP_4 -- set charge pump // STARTUP_4 -- set charge pump
else if (state == STARTUP_4) begin else if (state == STARTUP_4) begin
rst <= 1; res <= 1;
send_buf <= 16'h148D; send_buf <= 16'h148D;
state <= SEND2; state <= SEND2;
next_state <= STARTUP_5; next_state <= STARTUP_5;
Expand Down Expand Up @@ -207,5 +210,8 @@ module oled_spi(
end end
end end
end end

assign cs = 0;
assign sclk = !clock;


endmodule endmodule
49 changes: 49 additions & 0 deletions oled_spi_tb.v
@@ -0,0 +1,49 @@
`default_nettype none
`timescale 1ns / 1ps

module oled_spi_tb;

// Inputs
reg clock;
reg reset;
reg shutdown;

// Outputs
wire cs;
wire sdin;
wire sclk;
wire dc;
wire res;
wire vbatc;
wire vddc;

// Instantiate the Unit Under Test (UUT)
oled_spi uut (
.clock(clock),
.reset(reset),
.shutdown(shutdown),
.cs(cs),
.sdin(sdin),
.sclk(sclk),
.dc(dc),
.res(res),
.vbatc(vbatc),
.vddc(vddc)
);

initial begin
// Initialize Inputs
clock = 0;
reset = 1;
shutdown = 0;

// Wait 100 ns for global reset to finish
#100 reset = 0;
end

always begin
#10 clock = !clock;
end

endmodule

0 comments on commit 55f3204

Please sign in to comment.