Solution Manual for Introduction to Mechatronic Design Do Not Circulate
Chapter 5 Program Structures for Embedded Systems
5.1) Work with a DVD player and develop an exhaustive set of events that you think the sofware must sense
and respond to.
There will be a wide variety of responses to this question. Grade based on reasonableness and
thoroughness of the answer.
Example:
Any button pressed on the user interface (front panel or remote): Stop, Play/Pause, Forward pressed, Back
5.2) Identify the events and draw an STD for the behavior of a DVD player. Limit yourself to the events
generated by the DVD player (ignore the remote control).
There will be a wide variety of responses to this question. Grade based on the reasonableness and
thoroughness of the answer. For the state diagram, ensure that standard state diagram conventions are
used.
5.3) Given a function GetRoomTemperature() that returns the room temperature and a variable, SetPoint, write
a pair of functions in pseudo-code called IsTemperatureTooHot() and IsTemperatureTooCool() that return
TRUE-FALSE values and together implement a hysterisis band around the SetPoint temperature.
Both routines return TRUE or FALSE and adjust hysteresis threshold SetPoint as a side effect.
IsTemperatureTooHot()
Read GetRoomTemp() and store result in CurrentTemp
5.4) Work with an answering machine to develop the list of events that the machine’s software must respond to.
There will be a wide variety of responses to this question. Grade based on reasonableness and
5.5) You are writing code to implement cruise control for a car. Given a function GetVehicleSpeed() that
returns the speed of a vehicle, write a single function TestAccelDecel() in pseudo-code that returns,
NeedAccelerate, NeedDecelerate or SpeedOK based on the speed relative to a setpoint DesiredSpeed. To
provide noise immunity, implement hysteresis around the switch point.
Note: implement so that there is a hysteresis band around the DesiredSpeed, with an UpperThreshold
5.6) In an application, the state of a switch is determined by reading a variable called PortA. The state of the
switch is indicated by the state value of bit 4 within the byte variable PortA. In pseudo-code, write an event
checking function TestSwitch() that returns Opened, Closed, or NoChange depending on what has
happened since the last time TestSwitch() was called.
Create SwitchMask constant = 0x10 (the switch is at bit 4 in PortA)
Routine returns Opened, Closed or NoChange.
TestSwitch()
Read PortA, use SwitchMask to mask out all bits other than bit 4, and
5.7) Work with a microwave oven to develop the list of events that the oven’s software must respond to.
There will be a wide variety of responses to this question. Grade based on reasonableness and
5.8) Figure 5.7 shows a simple microwave oven. Draw an STD that captures the behavior described by the
following description as follows:
a) The Open button opens the door, stops cooking, holds time.
b) The Clear button clears the timer. If cooking was active it is disabled.
c) The Start button starts cooking for whatever time has been set. While cooking, the timer decrements to
zero and turns off cooking when it reaches zero.
d) The Popcorn button forces a time of 2 minutes to be set into the timer.
e) The Def/Light button forces the power level to 50%.
f) Time is set by twisting the dial and then pressing the button at the center of the dial. No action takes
place until the button is pressed. At that point, the time on the dial is entered into the timer.
g) There is a switch connected to the door to show whether it is open or closed.
Figure 5.7: Front view of the microwave oven described in Problem 5.8.
A representative solution is shown below. Wide variation in execution is likely. Grade based on whether
the solution will function correctly, whether the oven’s function is completely described, and whether state
diagram conventions are used.
IDLE
Door Closed
CLEAR Pressed
IDLE
Door Open
Door Closed
CLEAR Pressed
Power = 100%, Timer = 0
Disable Magnetron,
Suspend Timer
Load Timer with time
indicated on Timer Dial
Disable Magnetron,
CLEAR Pressed
Disable magnetron
5.9) Assume that the switches from the microwave oven in Problem 5.8 are available in a single variable
(Switches), that the timer can be set with a function SetTimer(),that the timer can be read with a function
IsTimerExpired(), and the power level can be set with a function SetPower(). In pseudo-code, write
routines for the required event checkers, state machine function and main() to implement the your design
from Problem 5.8.
If SwitchEvent = TIMER: SetTimer to time indicated on dial
If SwitchEvent = OPEN: OpenDoor, set state = IDLE, Door Open
If SwitchEvent = START
Enable magnetron
Start/resume decrmenting timer
If state = COOKING
Check for SwitchEvent(s)
If SwitchEvent = OPEN:
Disable magnetron
Suspend timer
If CLEAR button pressed:
Disable magnetron
Solution Manual for Introduction to Mechatronic Design Do Not Circulate
Function SwitchEvent() returns one of the following constant values: NO_SWITCH_EVENT, CLEAR,
OPEN, START, STOP, DEF/LIGHT, POPCORN, TIMER, DOOR_CLOSED. Events, with the exception
of NO_SWITCH_EVENT, are reported when there is a change of state from “not active” (e.g. not being
pressed) to “active” (e.g. being pressed).
SwitchEvent()
Read Switches and store in CurrentSwitchState
If CurrentSwitchState = LastSwitchState
Save CurrentSwitchState as LastSwitchState
Report NO_SWITCH_EVENT
End If
Else If CurrentSwitchState LastSwitch State
Save CurrentSwitchState as LastSwitchState
Report POPCORN
If DEF/LIGHT switch is active in CurrentSwitchState and inactive in LastSwitchState:
Save CurrentSwitchState as LastSwitchState
Report DEF/LIGHT
5.10) Draw the STD for a soft drink machine that accepts nickels, dimes and quarters and sells drinks that cost
$0.75 each.
A representative solution is shown below. Wide variation in solutions is likely. Grade this problem based
on whether the solution will function properly and is reasonably complete, and whether correct state
diagram conventions are used.
5.11) Draw a state diagram for modified combination lock like that shown Figure 5.4. Make your lock such that
it will not accept unlock if 4 or more digits are entered that end with the combinations that end in 2-1-8
sequence.
A representative solution is shown below. Wide variation in solutions is likely. Grade this problem based
5.12) There are many common behaviors that can be described using state machines. As an example, identify the
relevant events and draw a state diagram to describe the behavior of a ‘Shy Party Guest’ (a guest who does
not initiate conversations but participates when someone else initiates).
A representative solution is shown below. Wide variation in execution is likely. Grade based on whether