Skip to end of metadata
Go to start of metadata

1. Summary

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).

2. Tasks

Instructions and corresponding bit codes:

CodeMeaning
000Load "00000000" into the LR
001shift the LR right by one position, fill from the left with a '0'
010shift the LR left by one position, fill from the right with a '0'
011add 1 to the LR
100subtract 1 from the LR
101invert all of the bits of the LR
110rotate the LR right by one position (rightmost bit becomes leftmost bit)
111rotate 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. 

 

lightrom.mp4

The rightmost button is 'reset.'


I modified the lightrom circuit, wrote two other different programs of 16 instructions, and tested them on the board.

lightrom1.mp4

lightrom2.mp4

 

3. Extensions

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:

longer lightrom.mp4


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.

Code

Meaning

0000

Load "00000000" into the LR

0001

shift the LR right by one position, fill from the left with a '0'

0010

shift the LR left by one position, fill from the right with a '0'

0011

add 1 to the LR

0100

subtract 1 from the LR

0101

invert all of the bits of the LR

0110

rotate the LR right by one position (rightmost bit becomes leftmost bit)

0111

rotate the LR left by one position (leftmost bit becomes rightmost bit)

1000

set LR to "10100101"

1001

shift the LR right by two positions, fill from the left with "00"

1010

shift the LR left by two positions, fill from the right with "00"

1011

jump to when PC = "01011"

1100

jump to when PC = "00100"

1101

take 2’s complement of the LR

1110

rotate the LR right by 4 positions

1111

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.

longer lightrom.mp4


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:

hold, speedUp, slowDown.mp4

The 'hold' button is the second from the right(KEY[1]). 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:

hold, speedUp, slowDown.mp4

The leftmost button is 'speedUp' and the second button from the left is 'slowDown.'

4. Reflection

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. 

5. Credit

Ethan Seal

 

Labels