I'm implementing a tetris game using basys 3 on 8x8 led matrix.
reg [7:0]redBlock;
reg [7:0]backupRed= 8'b00011000;
reg [7:0]temp;
assign redBlock=(toRight& oe) ? backupRed>> 1 : backupRed;
This code is working the redblock on led matrix goes right when I push button toRight but of couse it goes back to it's initial position since the condition 0 is equal to backupRed
What I really want is
reg [7:0]redBlock = 8'b00011000;;
reg [7:0]backupRed;
reg [7:0]temp;
assign redBlock=(toRight& oe) ? redBlock>> 1 : redBlock;
which should update the previous location of redBlock but it gives error
Variable redBlcok is written by both continuous and procedural assigments
I'm using Vivado for implemantion
Here is 10sec video of what I meant
You are using an continuous assignment
assign
to describe data that you wish to be stored.Continuous assignments are used to describe combinatorical logic, but what you want here is sequential logic, a register (flip-flop).
Something along these lines:
Edit: Some thoughts on what kind of troubles you may run into.
Not sure what kind of signal
toRight
is, assuming thattoRight
is the raw button input:Firstly, you need to synchronize your button input.
If your clock is slow in relation to the duration of
toRight
, you may need to capture the short pulse and generate a clock cycle long pulse.If your clock is fast in relation to the duration of
toRight
, you may need to add a counter which can ensure that a single press of the button doesn't incrementredBlock
too much per press.Furthermore you may need to handle the case where
redBlock
has reached the edge of your display.