Scratch VHDL

Logo

The purpose of "Scratch VHDL" is to make reprogrammable logic design into child's play. Sounds ambitious.

View the Project on GitHub house-of-abbey/scratch_vhdl

Dimmer Control

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.

Dimmer Controller Sequence

Choose two buttons for up and down functions to manually advance through states. This example has two immediately obvious implementations.

  1. Use an integer counter in the range 0 to 4 and add or subtract 1 for each change. Make sure the actions on values of 0 and 4 are constrained.
  2. Use a state machine like the following to explicitly enumerate each state.
stateDiagram-v2 [*] --> 0 0 --> 1 : up = '1' and incr = '1' 1 --> 0 : down = '1' and incr = '1' 1 --> 2 : up = '1' and incr = '1' 2 --> 1 : down = '1' and incr = '1' 2 --> 3 : up = '1' and incr = '1' 3 --> 2 : down = '1' and incr = '1' 3 --> 4 : up = '1' and incr = '1' 4 --> 3 : down = '1' and incr = '1'

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”

Non-Finite State Machine

An implementation using a two-way shift register. The FSM implementation is perhaps more descriptive and hence easier to understand.