Week - 4
Aim:-To implement control logic of a “washing machine” using Stateflow as per given sequence and to make a Simulink chart for the “Gear shift” logic as per given condition.
Objectives:-
1 . Implement control logic of a “washing machine” using Stateflow as per given sequence:
- If the power supply is available, the system gets activated
- If the Water supply is not available, stop the process & indicate through LED
- Soaking time should be 200s followed by Washing time of 100s.
- Then rinsing happens for next 20s & dryer runs for 50s
After all the processes have completed turn on the finished LED
2 . Make a Simulink chart for the “Gear shift” logic as per below conditions:
Speed Range(kmph) Gear
0 to 15 1
16 to 25 2
26 to 40 3
41 to 60 4
Above 61 5
Give speed input while the simulation is running & display the gear number.
1 . Implement control logic of a “washing machine” using Stateflow as per given sequence:
Model:-

- When the power and water are OFF

Stateflow:-

Symbol pane:-

Power and Water are given as input data.
D,R,S,W and E are given as output data.
Blocks Used
1 . Slider switch
The Slider Switch block toggles the value of the connected block parameter between two values during simulation. For example, you can connect the Slider Switch block to a Switch block in your model and change its state during simulation.Use the Slider Switch block with other Dashboard blocks to create an interactive dashboard for your model.
2 . Chart
A finite state machine is a representation of an event-driven (reactive) system. In an event-driven system, the system responds to an event by making a transition from one state (mode) to another. This transition occurs if the condition defining the change is true.

3 . Display
The Display block shows the value of the input data. You can specify the frequency of the display. For numeric input data, you can also specify the format of thedisplay.
4 . Constant
The Constant block generates a real or complex constant value signal. Use this block to provide a constant signal input.
5 . Lamp
The Lamp block displays a color indicating the value of the input signal. You can use the Lamp block with other Dashboard blocks to build an interactive dashboard of controls and indicators for your model. You can specify pairs of input values and colors to provide the information you want during the simulation.
Description:-
- Power and Switch inputs were controlled by the Switch block. These two inputs were directed to the Chart block.
- State blocks were used inside charts to create a stateflow according to the given criteria.
- The POWER input is get as input in the chart and directed to the POWER State from there, if Power==1(Which is power supply in ON), it is directed to the next WATER block. or if Power==0(Power supply is OFF), it directed to the junction.
- Next state is WATER and from that if Water==1(Water supply is ON) it moves to the next stage or if Water==0(Water supply is OFF) then it is directed to the junction.
- Next to water is SOAKING state, entry is given as 0, while exit is LED is made to glow which is connected to this state.
- After 200 sec, it is directed to Washing state, and after 100sec it is directed to Rinsing state and after 20sec, to Drying state and after 50sec, it is ended to End state.
If power supply is on, the system gets activated. If the Water supply is not available, stop the process & indicate through LED.

Power supply is given 1, and LED denoting power is glowing Green which shows the system is activated. and Water is off with help of Slider switch and the LED is denoting Red which indicates the off state of water supply.

2 . Make a Simulink chart for the “Gear shift” logic as per given conditions:
Model:-

Stateflow:-

Symbol pane

Gear as input and G1,G2,G3 and G4 are output.
Blocks used
1 . Rocker switch
The Rocker Switch block toggles the value of the connected block parameter between two values during simulation. For example, you can connect the Rocker Switch block to a Switch block in your model and change its state during simulation. Use the Rocker Switch block with other Dashboard blocks to create an interactive dashboard for your model.
2 . Chart
A finite state machine is a representation of an event-driven (reactive) system. In an event-driven system, the system responds to an event by making a transition from one state (mode) to another. This transition occurs if the condition defining the change is true.
3 . Display
The Display block shows the value of the input data. You can specify the frequency of the display. For numeric input data, you can also specify the format of the display.
4 . Constant
The Constant block generates a real or complex constant value signal. Use this block to provide a constant signal input.
5 . Lamp
The Lamp block displays a color indicating the value of the input signal. You can use the Lamp block with other Dashboard blocks to build an interactive dashboard of controls and indicators for your model. You can specify pairs of input values and colors to provide the information you want during the simulation.
Description:-
- In the above control logic , first Engine is started from input switch ignition=0/1 through Rocker switch which is power switch to make engine ON.Then next Gear_Shift_logic implemented through following states.
- Five Gear State is created with state condition of gear (G) 1,2,3,4and 5 respectively and their transition is connected with speed range condition as shown.
- The transitions condition for the gear shift is decided as, Speed>15 shift to G=2, Speed>25 shift to G=3, Speed >40 shift to G=4, Speed>60 shift to G=5 when the speed is increasing from 0-60 kmph
- similarly in reverse direction , Speed<60 shift to G=4, Speed<40 shift to G=3, Speed<25 shift to G=2, Speed<15 shift to G=1 when the speed is decreasing from 60-0 Kmph
While simulating Gear_Shift_logic , ignition==1 condition given with various speed change values.
1st Gear:-

2nd Gear:-
As speed input is above 15,it shifts to the second gear and the lamp for 2nd gear is on and 1st gear lamp goes off

3rd Gear:-
As speed increases more than 25,it shifts to 3rd gear

4th Gear:-
As speed increases more than 40,it shifts to 4th gear.

5th Gear:-
As speed increases more than 60,it shifts to 5th Gear.

CONCLUSION:-
- Thus, all the objectives were achieved successfully.
- Similar concepts and approach can be used to create stateflow for other systems.
Simulink model link:-
1. https://drive.google.com/file/d/18koVxLnHJQMAK2wcqHPMmxLXltkBxUrP/view?usp=sharing
2. https://drive.google.com/file/d/1fDISUiRNLsnwQkJpgDU-sPeGxABRqbA8/view?usp=sharing