The purpose of "Scratch VHDL" is to make reprogrammable logic design into child's play. Sounds ambitious.
Consider a room light dimmer control that can be incremented and decremented in brightness of the main light. This is a digital version of the classic analogue dimmer that you rotate.
Choose two buttons for up
and down
functions to manually advance through states. This example has two immediately obvious implementations.
Now we just need to add the output assignments, e.g. using a case
statement, to decode the state (integer) value to a 4-bit vector assignment to leds(3:0)
.
state | leds(3:0) |
---|---|
0 | “0000” |
1 | “1000” |
2 | “1100” |
3 | “1110” |
4 | “1111” |
An implementation using a two-way shift register. The FSM implementation is perhaps more descriptive and hence easier to understand.