In this project, I built a simple programmable light display using a state machine and an instruction set.
The control circuit has an Instruction Register(IR), a Program Counter(PC), and a Light Register(LR).
Instructions and corresponding bit codes:
|000||Load "00000000" into the LR|
|001||shift the LR right by one position, fill from the left with a '0'|
|010||shift the LR left by one position, fill from the right with a '0'|
|011||add 1 to the LR|
|100||subtract 1 from the LR|
|101||invert all of the bits of the LR|
|110||rotate the LR right by one position (rightmost bit becomes leftmost bit)|
|111||rotate the LR left by one position (leftmost bit becomes rightmost bit)|
I created a ROM--lightrom--to hold the program. The lightrom takes one input signal addr(a 4-bit std_logic_vector) which is the address of the instruction to return. Each address stores a 3-bit value that composes the program. The output signal data(a 3-bit std_logic_vector) is the instruction to be executed.
I then created a VHDL file lights to execute the program in which I implemented a state machine that has two states--sFetch and sExecute.
The sFetch state assigns ROMvalue to the IR, adds one to the PC and then sets the state to sExecute. The sExecute state uses a case statement on the value of the IR and executes the proper action given the machine instruction table above.
Testing using GTKWave:
To test my circuit on the board, I slowed down the circuit using a slowclock that runs 32 million times slower than the clock.
The rightmost button is 'reset.'
I modified the lightrom circuit, wrote two other different programs of 16 instructions, and tested them on the board.
1) Make longer programs.
I doubled the length of the original program using a 5-bit address instead of 4-bit in my lightromLonger.vhd.
I also speeded up the slow clock by changing the assigned bits since the program was longer.
Displaying the program on the board:
2) Add instructions to the system. Make branch instructions, for example.
To add more instructions, I changed the output data, signals IR, IRView, and ROMvalue to 4-bit values so that I could make 2^4=16 instructions.
I added 8 more instructions, including three branch instructions for jumps that can loop over part of my program depending on which address it jumps to.
Load "00000000" into the LR
shift the LR right by one position, fill from the left with a '0'
shift the LR left by one position, fill from the right with a '0'
add 1 to the LR
subtract 1 from the LR
invert all of the bits of the LR
rotate the LR right by one position (rightmost bit becomes leftmost bit)
rotate the LR left by one position (leftmost bit becomes rightmost bit)
set LR to "10100101"
shift the LR right by two positions, fill from the left with "00"
shift the LR left by two positions, fill from the right with "00"
jump to when PC = "01011"
jump to when PC = "00100"
take 2’s complement of the LR
rotate the LR right by 4 positions
jump to when PC = "01111"
In the process under the architecture of my lightsPlus, I added case statements to execute the proper action given the instruction table above.
The display is the same as above.
3) Add a hold/free button to the display.
In my lights, I added an input hold that could freeze the program. I used an if statement in the process where the counter gets incremented only when the 'hold' button is not pressed(which is 1).
Testing using the board:
The 'hold' button is the second from the right(KEY). When I pressed it, the counter paused and the lights stayed unchanged.
4) Add a button that lets you speed up or slow down the display.
I added two buttons to speed up and slow down the display.
Firstly, I added inputs speedUp and slowDown in my lights.
Next, I assigned different bits of the counter to the slowclock based on which button is pressed.
Testing using the board:
The leftmost button is 'speedUp' and the second button from the left is 'slowDown.'
I learned to directly write VHDL files to build circuits. It was important to understand which signals to connect and how to execute the instructions. I also became more familiar with state machines, case statements, and if statements.