//----- Testbench -----
// Timescale: one time unit = 1ns (e.g., delay specification of #42 means 42ns of time), and
// simulator resolution is 0.1 ns
`timescale 1ns / 100ps
module MathLock_TESTBENCH;
// Input stimulus:
reg iG$Oscillator;
reg iG$PowerOnReset;
reg [9:0] iD$Keypad;
// Output connections:
wire oE$ActivatePassLED;
wire oE$ActivateFailLED;
wire oE$OpenLock;
// Waveform documentation
parameter MaxChars = 21;
reg [8*MaxChars-1 : 0] TestMode;
reg [3 : 0] Key;
//Instantiate the DUT (device under test):
MathLock DUT (
// Inputs:
.iG$Oscillator ( iG$Oscillator ), // Master
.iG$PowerOnReset ( iG$PowerOnReset ), // Power-on
.iD$Keypad ( iD$Keypad ), // Numerical
// Outputs:
.oE$ActivatePassLED ( oE$ActivatePassLED ), // Pass
.oE$ActivateFailLED ( oE$ActivateFailLED ), // Fail
.oE$OpenLock ( oE$OpenLock ) // Open
);
// Specify input stimulus:
initial begin
// Initial values for input stimulus:
TestMode = "Reset";
iG$Oscillator = 0;
iG$PowerOnReset = 1;
iD$Keypad = 0;
// Take out of reset
#10 iG$PowerOnReset = 0;
// Apply an invalid sequence
TestMode = "Invalid Sequence";
KeypadSequence(0,1,2,3,4,5);
// Wait for FAIL LED to extinguish, then apply a valid sequence
wait (oE$ActivateFailLED == 1) ;
wait (oE$ActivateFailLED == 0) ;
TestMode = "Valid Sequence";
KeypadSequence(9,4,6,8,7,8);
// Wait for PASS LED to extinguish, then finish simulation
wait (oE$ActivatePassLED == 1) ;
wait (oE$ActivatePassLED == 0) ;
$finish;
end
// Template for master clock. Uncomment and modify signal name as needed.
// Remember to set the initial value of 'Clock' in the 'initial' block above.
always #5 iG$Oscillator = ~iG$Oscillator;
task KeypadSequence;
input [3:0] A,B,C,D,E,F;
begin
// Apply keypresses with variations in timing to
// simulate human operator
iD$Keypad = 1 << A; Key = A;
#43 iD$Keypad = 0;
#24 iD$Keypad = 1 << B; Key = B;
#72 iD$Keypad = 0;
#58 iD$Keypad = 1 << C; Key = C;
#99 iD$Keypad = 0;
#56 iD$Keypad = 1 << D; Key = D;
#34 iD$Keypad = 0;
#44 iD$Keypad = 1 << E; Key = E;
#67 iD$Keypad = 0;
#79 iD$Keypad = 1 << F; Key = F;
#98 iD$Keypad = 0;
end
endtask
endmodule
This page: |
Created: | Thu Jan 16 14:38:01 2003 |
|
From: |
mathlock_TB.v |