// // Crystal oscillator stabilise start-up delay test. // Designed to work with start-up clock which may be 'bad' // Version for xtal_startup2 (only change is instance name) // // This is not yet self-verifying code. // (Which means you have to look at the waveform) // // // // Design by G.J. van Loo, FenLogic Ltd, 15-January-2017. // // This program is free software. It comes without any guarantees or // warranty to the extent permitted by applicable law. Although the // author has attempted to find and correct any bugs in this free software // program, the author is not responsible for any damage or losses of any // kind caused by the use or misuse of the program. You can redistribute // the program and or modify it in any form without obligations, but the // author would appreciated if the credits stays in. // module xtal_startup2_test; localparam XTAL_PERIOD = 80, BADTIME = 500; reg xtal,xtal_bad,bad_time; wire xtal_raw; reg reset_n_raw; wire xtal_ok; time t; reg [31:0] r; // positive integer prob; assign xtal_raw = xtal & ~xtal_bad; initial begin prob = BADTIME; reset_n_raw = 1'b0; bad_time = 1'b1; #100; reset_n_raw = 1'b1; #(500*XTAL_PERIOD) ; // Make SURE signal is clean after a while bad_time = 1'b0; #(700*XTAL_PERIOD) ; $stop; end // Clean XTAL signal initial begin xtal= 1'b0; forever #(XTAL_PERIOD/2) xtal<= ~xtal; end // Disturb XTAL clock // Distrub less after time initial begin while (bad_time) begin r = $random % BADTIME; if (!r[31] && r <= prob) begin t = ($random & 32'h03F)*XTAL_PERIOD/10; #t xtal_bad=1'b1; end t = ($random & 32'h03F)*XTAL_PERIOD/10; #t xtal_bad=1'b0; if (prob>0) prob = prob-1; end end always @(posedge xtal_raw) begin if (prob>0) prob = prob-1; end xtal_startup2 #(.STAGES(10)) xtal_startup2_0 ( .xtal_raw (xtal_raw), // signal from crystal oscillator pad .reset_n_raw(reset_n_raw), // signal direct from reset-pad .xtal_ok (xtal_ok) // stabilised clock from crystal ); endmodule // xtal_startup2_test