module Controller_TB; reg iG$MasterClock; reg iG$MasterReset; reg iS$KeyIsPressed; reg iS$IntervalIsComplete; reg iS$SumIsCorrect; reg iS$KeyPressingIsFinished; wire oC$InitializeTimer; wire oC$EnableTimer; wire oC$AddKey; wire oC$ClearSum; wire oE$ActivatePassLED; wire oE$ActivateFailLED; wire oE$ActivateSolenoid; // Waveform documentation parameter MaxChars = 21; reg [8*MaxChars-1 : 0] TestMode; reg [8*12-1 : 0] KeyPadStatus; parameter pQ$Initialize = 7'b0000001; parameter pQ$WaitForKeyPress = 7'b0000010; parameter pQ$AddToKeysum = 7'b0000100; parameter pQ$WaitForKeyRelease = 7'b0001000; parameter pQ$SequenceFailed = 7'b0010000; parameter pQ$SequencePassed = 7'b0100000; parameter pQ$ErrorTrap = 7'b1000000; parameter Initialize = "Initialize"; parameter WaitForKeyPress = "WaitForKeyPress"; parameter AddToKeysum = "AddToKeysum"; parameter WaitForKeyRelease= "WaitForKeyRelease"; parameter SequenceFailed = "SequenceFailed"; parameter SequencePassed = "SequencePassed"; parameter ErrorTrap = "ErrorTrap"; reg [8*17-1 : 0] StateName; Controller DUT ( .iG$MasterClock (iG$MasterClock), .iG$MasterReset (iG$MasterReset), .iS$KeyIsPressed (iS$KeyIsPressed), .iS$IntervalIsComplete (iS$IntervalIsComplete), .iS$SumIsCorrect (iS$SumIsCorrect), .iS$KeyPressingIsFinished (iS$KeyPressingIsFinished), .oC$InitializeTimer (oC$InitializeTimer), .oC$EnableTimer (oC$EnableTimer), .oC$AddKey (oC$AddKey), .oC$ClearSum (oC$ClearSum), .oE$ActivatePassLED (oE$ActivatePassLED), .oE$ActivateFailLED (oE$ActivateFailLED), .oE$ActivateSolenoid (oE$ActivateSolenoid) ); initial begin TestMode = "Reset"; KeyPadStatus = "Key released"; iG$MasterClock = 0; iG$MasterReset = 1; iS$KeyIsPressed = 0; iS$IntervalIsComplete = 0; iS$SumIsCorrect = 0; iS$KeyPressingIsFinished = 0; // Take out of reset #10 iG$MasterReset = 0; // Wait for a few cycles to ensure controller waits for keypress, // then indicate keypress TestMode = "Single keypress"; #30 ; KeyPress; // Indicate that key pressing is finished, then do another keypress. // Controller should eventually enter "fail" state. TestMode = "Go through FAIL state"; #10 iS$KeyPressingIsFinished = 1; KeyPress; // Indicate that timer interval is done #50 iS$IntervalIsComplete = 1; #10 iS$IntervalIsComplete = 0; // Indicate valid sum and key pressing is finished, then do one keypress. // Controller should eventually enter "pass" state. TestMode = "Go through PASS state"; #10 iS$SumIsCorrect = 1; KeyPress; // Indicate that timer interval is done #50 iS$IntervalIsComplete = 1; #10 iS$IntervalIsComplete = 0; #50 $finish; end // Master clock always #5 iG$MasterClock = ~iG$MasterClock; // State label always @ (Controller.r$State) case (Controller.r$State) pQ$Initialize : StateName = "Initialize"; pQ$WaitForKeyPress : StateName = "WaitForKeyPress"; pQ$AddToKeysum : StateName = "AddToKeysum"; pQ$WaitForKeyRelease : StateName = "WaitForKeyRelease"; pQ$SequenceFailed : StateName = "SequenceFailed"; pQ$SequencePassed : StateName = "SequencePassed"; pQ$ErrorTrap : StateName = "ErrorTrap"; default: StateName = "UNKNOWN"; endcase // Tasks task KeyPress; begin iS$KeyIsPressed = 1; KeyPadStatus = "Key pressed"; #50 iS$KeyIsPressed = 0; KeyPadStatus = "Key released"; end endtask endmodule