L10. 1. FSM adaptation. External interrupts (INT) [P10] FSM design programming in C. Detecting events (signal edges) using external interrupts. |
[3/12] |
3.5. FSM implementation in C language
3.5.1. Specifications
3.5.1.1. FSM concept adaptation to µC.
Fig. 1 shows Chapter 2 FSM architecture as it was studied and applied in many applications to solve sequential systems.
Fig 1. FSM architecture. |
Now, we propose to adapt the same architecture to software environment as shown in Fig. 2.
Fig 1. FSM adaptation rec: interrupts will allow detection of events (signal edges) and will make it possible to run state diagrams systematically programmed in C, as we did in Chapter 2. |
Current state as RAM memory variable.
3.5.1.2. CLK interface using interrupts
How to detect signal edges.
3.5.2. Planning
3.5.2.1. Hardware-software diagram
3.5.2.2. Interrupts: interrupt service routine ISR(). External event detection (CLK and push-button interface)
The key concept of external interrupt (INT) to the main program. Pay attention to the idea of external interrupt to detect a signal edge at the input pins and how they are handled by the μC in hardware (INT0IF, INT0IE, GIE) and once acknowledged at the ISR() software (Var_CLK_flag). The concept of the interrupt vector to execute the ISR() special function. The concepts of nested interrupts, stack memory and stack overflow.
Enabling and disabling interrupts in init_system().
3.5.2.3. output_logic() and write_outputs().
3.5.2.4. state_logic() and read_imputs()
3.5.3. Development & testing
References:
- Carmely, T., Using finite state machines to design software, EDN, March 30, 2009
- Bergfeld, D., Software design of state machines , Embedded.com, April 16, 2019
Exercise: Detect the duration of an active-low push-buttons PB_L click using two interrupt flags. How to configure int_system(), what is the software flowchart for ISR()? What kind of processing the FSM can do?
|
Questionnaire on P5- P6 - P7 -P8 (30 min.)