|
Laboratory 5 Buttons, keyboards, events and interrupts. FSM structure and CLK synchronisation. |
[24/3] |
1. Specifications
(1) Enhance the FSM architecture with external interrupt handling. Modify the previous FSM tutorial in Lab4 adding a button ST. The FSMI is kept idle until ST is clicked two consecutive times, and it works continuously until another click is detected.
(2) Add a flag variable to write ASCII messages to the serial port, so that it can be used for monitoring FSM operations.
|
Fig. 1. Basic application FSMI enhanced with external interrupt detection. |
We will add hardware components and modify the state diagram so that the application will work as specified.
|
Fig. 2. Proposed modifications in the state diagram. |
2. Planning
Our goal is organise application software as a finite state machine (FSM) taking advantage of that we already learned in LAB4. The state diagram will be sensitive to the detection of external interrupts events.
Hardware mains using one of the external interrupts, so that switches can be connected to other unused pins.
|
Fig. 3. Hardware circuit built around the Arduino board (picture ref..) |
Software will be upgraded to consider external interrupt acknowledgement. The interrupt service routine will be installed dynamically in setup() function as recommended in the reference manual.
![]() |
Fig. 4. Software implies the idea of jumping to the interrupt service routine exactly when the event, this time an external button click, happens. |
Project location:
C:\EMC\LAB5\FSMI\(files)
![]() |
Fig. 5. Hardware-software diagram introducing the extra function to attend interrupts. |
RAM variables and the structure and organisation of the remaining functions are inherited from Lab4.
3. Development & 4. Testing
We can inherit all previous Lab4 project and rename it. This is the FSMI.zip file containing the hardware and software project files. Open Proteus and run the application.
|
Fig. 6. Proteus captured circuit running interactively while watching variables. |
While debugging, we can use "Ctrl+F10" to stop the code execution exactly in the interrupt service routine to check that this jumping mechanism works correctly.
|
Fig. 7. Stopping the execution at a given line of code. |
Bouncing and noisy signal associated to mechanical buttons. Measure and characterise this event using the VB8012 instrument. We need to experiment with the prototype to visualise waveforms on the oscilloscope and check if button click events are correctly sampled.
Find examples on debouncing circuits. What is the typical button debouncing hardware and software solution found in books and examples?
5. Prototyping
We use the previous circuit and solder a button ST_L to connect it to the Arduino pin 2 (INT0). We upload the executable file (hex) to the platform using Proteus or Arduino IDE.
|
Fig. 8. FSMI running. |
The prototype allow us to perform several measurements and observe the behaviour when clicking push button. For instance, Fig. 9 shows the acquired analogue and digital signal for a short click event.
|
Fig. 9. Short click event about 200 ms |
As shown in Fig. 10, many times and randomly, digital noise or glitches are generated when clicking, and they can make the FSM to malfunction.
|
Fig. 10. Signal bouncing for 30 us on the ST_L button falling edge when clicking. |
How to generate clean digital signals and filter out all electrical noise?
We can use the previous LAB4 template and add the new elements, basically the push-button, rearranging some inputs to be able to connect INT0 to the ST_L button. This is the FSMI-PCB.zip containing the project files.
![]() |
Fig. 11. Example of schematic in Multisim. |
You can complete the PCB represented in Fig. 12.
![]() |
Fig. 12. Example of component placement and some traced routes in Ultiboard. |
5. Reporting applying this tutorial to a new project
Study the materials presented in this LAB5 on the FMS with interrupts. We propose a new project to introduce the CLK signal concept for synchronising FSM state transitions as in a conventional sequential circuit. The design is represented in Fig. 13: a 1-digit BCD counter synchronised with an external 10 Hz signal, with reversibility (UD_L), count enable (CE) and terminal count detection (TC10). Propose the state diagram for this application. CE and UD_L are switches, CLK is a button. TC10 and output vector Q(3..0) are connected to LEDs.
Project location:
C:\EMC\LAB5\Counter_BCD_1digit\(files)
![]() |
Fig. 13. Symbol and chip functionality described using the function table. Design step #1 --> only UP counting to make it even simpler. UD_L input is not required. Design step #2 -- > counting UP and DOWN. Add input UD_L and modify the project conveniently. |
![]() |
To complete the circuit specifications we need to draw the state diagram and an example of timing diagram. Fig. 14 is an example of state diagram inherited from CSD LAB10. The advantage is that software functions are identical, and hardware-related functions interface the Arduino microcontroller instead of the PIC18F4520.
|
Fig. 14. Example of state diagram representing design step #1 considering up counting. |
Fig. 15 shows an example of hardware schematic for implementing the Counter_BCD_1digit.
|
Fig. 15. Circuit running in Proteus. We can drive the CLK signal clicking a button or connecting an oscillator. |