From 07cc3c5c788eff68b8d68713204613b07824fae2 Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Sat, 28 Mar 2026 16:35:19 -0700 Subject: Initial Commit --- sequence_generator.v | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 sequence_generator.v (limited to 'sequence_generator.v') diff --git a/sequence_generator.v b/sequence_generator.v new file mode 100644 index 0000000..0bdbd70 --- /dev/null +++ b/sequence_generator.v @@ -0,0 +1,30 @@ +// This module generates the "random" sequences for the simon game. +// This module uses a perpetually running LFSR for seeding the sequence generator. +// If randomize is high this module will use the current LFSR value as the seed. +// Effectively this results in choosing a new random sequence. +// If start_over is high this module moves to the start of the random sequence. +// If next is high this module moves to the next element of the sequence. +// seq outputs the current element of the sequence using a one-hot encoding. +module sequence_generator ( + input clk, + input randomize, + input next, + input start_over, + output [7:0] seq +); + reg [17:0] counter = 18'b100110101011010111; + reg [17:0] seed; + reg [17:0] current; + + assign seq = 8'b1 << current[2:0]; + + always @(posedge clk) begin + counter <= {counter[15:0], counter[17:16] ^ counter[10:9]}; + if (randomize) + seed <= counter; + if (start_over) + current <= seed; + else if (next) + current <= {current[15:0], current[17:16] ^ current[10:9]}; + end +endmodule -- cgit v1.2.1