SCLA076 December 2024 TPLD1202 , TPLD1202-Q1
A state machine can be used to detect inputs from a single button to perform different actions. A design like this can be used as the primary controller in many simple systems, or alternately can be used to offload some complexity for the firmware development to an external TPLD device when using a microcontroller.
In Figure 4-1 you can see a state machine that is designed to sort the inputs from a single button into 4 different common input formats. Those options are a single press, 1s hold, 2s hold, and double press. This state machine can be utilized in the TPLD as shown in Figure 4-2. The outputs of the state machine are driving the timers for the double press timing, and some LED's on our EVM board to show the device transitioning into different states.
Whenever the RST pin from the design in Figure 4-2 is low the device resets into an idle state this is also the default startup state of the device. Whenever the RST pin is high (button on the EVM is pressed) the SM is active and watching for inputs albeit still in the idle state. Assume for the rest of this section the RST is being held high. A single click of the button triggers the double timer block, and transitions our SM to the Single state. The duration of this timer can be configured by increasing or decreasing the control data of the "Double timer" block. If the button is pressed again before the timer runs out the SM transitions from Single to Double. The outputs of Single and Double state are simply fed into a DFF CLK input thus transitioning the associated LED from ON to OFF or OFF to ON. If the button is pressed and remains pressed for the duration of the 1s Timer block the SM transitions from Idle to Hold 1s. This does a similar toggling as the Single and Double states, but also triggers a second 1s Timer block. The reason the Hold 1s state does not retrigger the same block is because this SM is asynchronous and we want to prevent any accidental skips by connecting the input to two consecutive states to the same trigger. If the button remains held for another second the oneshot0 enables cnt0 to flash the DFF thus resulting in a flashing LED. The behavior of this design can be observed in Figure 4-3, and Figure 4-4.
The functionality of this circuit is just to highlight the SM, so the surrounding functionality while necessary to accomplish this task is largely simplified versus a final design.