// Name: Charles Goodliffe // Student Code: cg829 // This module was produced by only one contributor // last modified: 05/12/2019 // This testbench checks the functionality of the // ProgramCounter module functions: /* *Reset *LoadValue *Offset *Default Incrementation */ module ProgramCounterTestBench(); // These are the signals that connect to // the program counter logic Clock = '0; logic Reset; logic [15:0] LoadValue; logic LoadEnable; logic signed [8:0] Offset; logic OffsetEnable; logic signed [15:0] CounterValue; // instantiation of the program counter ProgramCounter uut( .Clock, .Reset, .LoadValue, .LoadEnable, .Offset, .OffsetEnable, .CounterValue ); default clocking @(posedge Clock); endclocking always #10 Clock++; initial begin // *****INITIALISE INPTUTS***** LoadValue = '0; LoadEnable = 'b0; Offset = '0; OffsetEnable = 'b0; // *****START WITH COUNTERVALUE AT 0***** Reset = 1; ##1; Reset = 0; // *****TESTING INCREMENT FUNCTION***** ##2; // 2 +ve clock edges occur so CounterValue // should increment to decimal 2 // *****TESTING RESET FUNCTION***** Reset = 1; // set reset input and wait for clock to go high for effect to occur ##1; // PC value should reset on this +ve clock edge Reset = 0; // disable reset // *****TESTING LOAD FUNCTION***** ##3; // allow 2 clk cycles to pass, PC value should be decimal 3 after 3rd cycle LoadValue = 16'b1111; // setting load value to decimal 15 ##1; // pass 1 clk cycle, the value of PC should be decimal 4 after this cycle // this is to show that LoadEnable needs to be active for the Load function // to work LoadEnable = 1; // enable Load function ##1; // after this clk cycle the PC value // should be equal to the load value of decimal 15 LoadEnable = 0; // disable load function // *****TESTING OFFSET FUNCTION***** ##5; // allow 5 clk cycles to pass // the PC value should now be decimal 20 Offset = -16'd10; // assign value of decimal -10 to th offset ##1; // allow 1 clk cycle to pass to pass // the PC value should now be decimal 21 // this is to show that the offset function // must be enabled in order to affect the PC value OffsetEnable = 1; // enable offset ##1; // after 1 clk cycle the PC value should now be //decimal 11 (as the offset was -10 from an original // value of 21) OffsetEnable = 0; // *****END OF TESTING***** end endmodule