Tutorial: Finite State Machine programming

Tutorial: Finite State Machine Programming

Introduction

We will learn how to design a logic with FSM and implement it in C-programming.

Example 1

Description

When the button is pressed, (input X=HIGH)

  • Turn ON the LED.

Wait for 1 sec.

Button is released during the wait time.

When the button is pressed again, (input X=HIGH)

  • Turn OFF the LED.

INPUT:

  • X: Button Pressed {0, 1}

OUTPUT:

  • LED {ON, OFF}

STATE:

  • S0: FAN OFF State

  • S1: FAN ON State

Moore FSM Table

Example Code: Moore FSM

Mealy FSM Table

Example Code: Mealy FSM

Example 2

Description

When the button is pressed, (input X=HIGH)

  • Turn ON the LED and Turn ON the fan motor.

Wait for 1 sec.

Button is released during the wait time.

When the button is pressed again, (input X=HIGH)

  • Turn OFF the LED and Turn OFF the fan motor.

Moore FSM Table

image

Example Code: Moore FSM

Mealy FSM Table

image

Example Code: Mearly FSM

Last updated

Was this helpful?