Electronic Control Systems

Download Report

Transcript Electronic Control Systems

Gary Plimer 2005
Electronic Control Systems

Electronic devices have
been developed to make life
more enjoyable, easier,
safer or more productive.

Some examples:
Microwave oven.
Traffic lights.
Computers.
Games consoles.
Gary Plimer 2006
There are 2 types of Electronic device,
1) Purely electronic devices such as Digital Watches
2) Mechatronic devices such as a Video Recorders
Question:
Why do you think a Video Recorder comes
under Mechatronic devices?
Pupil Assignment
Gary Plimer 2006
1. List three electronic devices.
2. List three mechatronic devices.
3. Explain the ‘mechanism’ in each of the three
mechatronic devices listed.
Some possible answers:
1) Gameboy, Television remote control, Calculator
2) Computer CD-ROM drive, Microwave oven, Remote
door lock in a car
System Diagram
Gary Plimer 2006
Both Electronic and Mechatronic devices have one thing in
common, they both have a control unit.
The system diagram for a warning
device for a freezer in a restaurant
would be drawn as below.
INPUT
HEAT
INPUT
TRANSDUCER
TEMPERATURE
SENSOR
PROCESS
0
0C
OUTPUT
TRANSDUCER
OUTPUT
SOUND
DRIVER
BUZZER
Transducers
Gary Plimer 2006
Input transducers are electronic devices that detect
changes in the ‘real world’ and send signals into the
process block of the electronic system.
Output transducers are electronic devices that can be
switched on and off by the process block of the electronic
system.
A popular electronic
toy is shown. Try to
identify as many input
and output
transducers as you
can.
Pupil Assignment
Gary Plimer 2006
List the Input and Output transducers for the following
products
Pop
Fizzy
Kolah
Juice
Ginger
Yuk
Personal Music Player
Vending Machine
Washing machine
Hairdryer
Microcontrollers
Gary Plimer 2006

A microcontroller is often described as ‘a computer on a chip’

It has a memory and the ability to receive inputs and control
outputs

It is a small & inexpensive device

Often built into products to make them more intelligent and
easier to use

Usually programmed for a specific purpose/ product
Advantages of Microcontrollers
Gary Plimer 2006

A microcontroller can often replace several parts or
even a complete circuit.

The main advantages to using one are:
Increased reliability
Simplified product assembly (less parts)
Greater product flexibility (can be re-programmed)
Pupil Assignment
Gary Plimer 2006
List three devices that may contain a microcontroller.
Explain why you think it would be useful to have a
microcontroller in these devices.
Inside a Microcontroller
Gary Plimer 2006



ROM
 Read only memory (permanent)
 Contains STAMP operating instructions
 Retains this program even when without power
EEPROM
 Electronically erasable programmable read only memory
 Your program is stored here
 The ROM will read this and carry out the instructions
RAM
 Random access memory (temporary)
 Stores information from calculations whilst running
 Is wiped when the power is cut
Gary Plimer 2006
Inside a Microcontroller

ALU



Arithmetic and Logic Unit
The control centre of the Microcontroller
Runs the instructions stored in the ROM



I.e. it can only READ from this memory and not write or send information
to it!
Clock
 The clock synchronises all of the internal blocks
 It sets the operating speed of the system
Buses
 Information is carried between the various blocks on buses
 These are groups of wires
 Data Bus carries data between the ALU and RAM
 Program Bus carries data from ROM to the ALU
Gary Plimer 2006
Inside a Microcontroller
PROGRAM
COUNTER
ROM
PROGRAM
MEMORY
RAM
DATA
BUS
REGISTER
FILES
ALU
‘REAL
WORLD’
I/O
PORTS
PROGRAM
BUS
CLOCK
TIMERS
IMPORTANT – Input
SIMPLIFIED PIC MICROCONTROLLER
Output port,
BLOCK DIAGRAM
connects to “Real
World”
Stamp Controller
Programming Procedure:
 Draw a flowchart for
the control task.
 Write the program on
the computer using
the Stamp software.
 Connect the download
cable from the
computer to the stamp
controller.
 Connect the power
supply
to the
stamp controller.
 Use the Stamp software
to download the
program.
Gary Plimer 2006
Getting Started - Programming
Gary Plimer 2006
Start up the Stamp software
and key in the program.
Save the program and then
download it to the stamp
controller by clicking ‘Run’.
Your teacher will give you
help with the software, if
you need it.
In your own words explain
what the program does.
main:
high 7
pause 1000
low 7
pause 1000
end
Pupil Assignment
Gary Plimer 2006
red
red and
amber
10 s
2s
green
10 s
amber
2s
Using the times shown in the table for each stage of a Traffic
Light sequence, write a P-Basic Program for the lights then run
and test your program.
Flow Charts
Gary Plimer 2006
START
Start / Stop
Symbol
SWITCH PIN 7
HIGH
WAIT 2 SECONDS
Input / Output
Symbol
Wait Symbol
SWITCH PIN 6
HIGH
WAIT 1 SECOND
SWITCH PIN 4
& 5 HIGH
WAIT 3 SECONDS
There are other symbols you will
need to learn, but we will discuss
those when we need to use them.
SWITCH ALL
OFF
STOP
Pupil Assignment
Gary Plimer 2006
A microwave oven operates with the following
sequence. Draw a flowchart and write a P-Basic
program for this sequence.
Light on
Turntable on
Magnetron on
Wait 30 seconds
Magnetron off
Wait 10 seconds
Turntable off
Buzzer on
Wait 0.5 second
Buzzer off
Light off
You can decide for
yourself which pins to
allocate to the outputs
transducers
Adding Comments
Gary Plimer 2006
Comments are always added to program listings to help
explain the program operation. An example is shown
below.
Main:
high 7
‘switch pin 7 high
pause 1000
‘wait 1 second
low 7
‘switch pin 7 off
pause 1000
‘wait 1 second
goto main
‘jump to label main
Note the apostrophe which tells the program that
what follows is a comment, not a line of code.
White Space
Gary Plimer 2006
Lets have a look at the layout of the previous code. Note how the code
is indented, (tabbed in). This is known as leaving “WHITE SPACE”.
White space makes the layout and reading of programs much clearer.
The start of the program is indicated by the “LABEL” main, note the
colon after the label. Labels can have any name as long as it is not a
P- Basic command.
Copy down the program below and label each part as shown.
White Space
Main:
Label
Code
high 7
‘switch pin 7 high
pause 1000
‘wait 1 second
low 7
‘switch pin 7 off
pause 1000
‘wait 1 second
goto main
‘jump to label main
Comments
Symbols
Gary Plimer 2006
Sometimes it can be hard to remember which pins are connected to
which devices. The ‘symbol’ command can then be used at the start
of a program to rename the inputs and outputs.
symbol red = 7
symbol green = 5
' rename 7 ‘red’
' rename 5 ‘green’
main:
'
'
'
'
'
'
'
'
high red
low green
pause 1000
low red
high green
pause 1000
goto main
make a label called ‘main’
red LED on
green LED off
wait 1 second
red LED off
green LED on
wait 1 second
jump back to the start
Key in the program, then run and test.
LOOPS
Gary Plimer 2006
START
Sometimes it is
necessary to
create programs
that loop
‘forever’, as is the
case in this
flowchart. There
is no ‘Stop’
symbol because
the program
never ends!
What command
makes the
program loop?
SWITCH PIN 7
HIGH
WAIT2 SECONDS
SWITCH PIN 6
HIGH
WAIT1 SECOND
SWITCH PINS 4& 5
HIGH
WAIT3 SECONDS
SWITCH ALL
OFF
WAIT1 SECOND
main:
high 7
pause 2000
high 6
pause 1000
high 4
high 5
pause 3000
low 4
low 5
low 6
low 7
pause 1000
goto main
Pupil Assignment
red
1. Draw a flow chart for the
control of the traffic lights
2. Write a P-Basic program
using the symbol command
to give names to pins
3. The program should loop
4. Run and test your program
red and
amber
Gary Plimer 2006
10 s
2s
green
10 s
amber
2s
Pupil Assignment
Gary Plimer 2006
A fountain in a garden centre is to be used to attract visitors to a new range of
plastic ponds. The garden centre owner wishes to develop a microcontrollerbased system that can be programmed to switch the fountain pump and an
external lighting system on and off at regular intervals.
Draw a flowchart for the control sequence and add the missing comments to the
program listing.
main:
high 7
pause 10000
high 6
pause 40000
low 6
pause 10000
low 7
pause 60000
goto main
' switch the pump on
' wait 10 seconds
' switch the lights on
'…
'…
'…
'…
'…
'…
Pupil Assignment
Gary Plimer 2006
A toy shop has a train set in the window. The train set has an electric train,
a set of red/green signals and a set of moving track points that allow the
train to move around two different loops of track. Draw a flow chart and
write a P-Basic program to control the train set.
1.
2.
3.
4.
Switch the green signal on
Switch the train on for 30 seconds
Stop the train
Switch the green signal off and the
red signal on
5. Switch the points on
6. Switch the train on for 30 seconds
7. Stop the train
8. Switch the points off
9. Switch the red signal off
10. Jump back to step 1
Input
connection
Pin
Output
connection
7
train motor
6
points
5
green signal
4
red signal
3
2
1
0
Output Module

Allows output transducers to be
connected to the stamp controller

Typical output transducers are
Motors, Buzzers and Bulbs

To use the output module, the
output device should be connected
between the screw-terminal
numbered output (4–7) and a V+
connection.
Gary Plimer 2006
Pupil Activity
Gary Plimer 2006
Connect 2 dc motors to the output module, enter the following code
then run and test your program.
YOUR TEACHER WILL EXPLAIN THE MODULE CONNECTIONS
main:
high 5
high 7
pause 1000
low 5
low 7
pause 1000
high 4
high 6
pause 1000
low 4
low 6
goto main
'
'
'
'
'
'
'
'
'
'
'
'
'
make a label called ‘main’
motor A forward
motor B forward
STAMP
CONTROLLER
wait 1 second
motor A halt
motor B halt
wait 1 second
motor A backward
motor B backward
wait 1 second
motor A halt
motor B halt
jump back to the start
OUTPUT
DRIVER
MODULE
Pupil Assignment
Gary Plimer 2006
START
MOVE
FORWARD
WAIT 3 s


Copy the flow chart into your
work book
Write a P-Basic program to
control the movement of the
buggy as indicated by the
Flowchart
TURN
LEFT
WAIT 1 s
MOVE
FORWARD
WAIT 3 s
STOP
Pupil Assignment

Build a maze on the table out of
books.

Write a PBASIC program to steer
the buggy through the maze.

Add comments to each line in
your program to explain how it
works.
Gary Plimer 2006
Speed Control
Gary Plimer 2006
 There are two ways to control the speed of a d.c. motor.

Vary the voltage applied to the motor. Unfortunately the
‘turning power’ (torque) of the motor will also drop, which
means the whole motor system will be less powerful.

The second way to control the motor is to always apply the
full voltage but then to switch the power supply on and off
rapidly. The advantage of this system is that the torque
remains quite high.

This method is known as PULSE WIDTH MODULATION
Pulse Width Modulation
Gary Plimer 2006
V
MARK
SPACE
t

Motor off is known as SPACE – Larger Space to Mark Ratio
= slow speed

Motor on is known as MARK – Larger Mark to Space Ratio
= fast speed
Pupil Activity
Gary Plimer 2006
Connect a d.c. solar motor across the ‘V+’ and ‘7’ terminals on the
output driver module.
Key in, download and run the program listed below. This program drives
the motor at approximately half speed, as the space (off time) is twice
the length of the mark (on time).
main:
high 7
pause 5
low 7
pause 10
goto main
'
'
'
'
'
output high
pause for 5 ms
output low
pause for 10 ms
loop
Try out different speeds (by experiment) by altering the length of the
pause delays.
Pupil Assignment
Gary Plimer 2006
1)
Explain the terms ‘mark’ and ‘space’ in relation to
PWM speed control of a d.c. motor.
2)
Describe the advantages and disadvantages of
using PWM speed control.
3)
Sketch 2 PWM graphs, one for a fast speed and
one for a slow speed.
Pupil Assignment
The motor on the washing machine is
controlled by outputs 6 and 7 (motor B).
Switching output 6 on will make the motor
turn one way; switching output 7 on will
make the motor turn the other way.
Draw a flowchart and write a PBASIC
program that will make the motor rotate at
full speed in each direction for five seconds.
Write a second PBASIC program that will
make the motor rotate at half speed in each
direction for five seconds. Use PWM speed
control for the motor.
Gary Plimer 2006
For Next Loops
It is often useful to repeat the same part of a program
a number of times, for instance when flashing an LED.
In these cases a ‘for … next’ loop can be used.
Gary Plimer 2006
START
SET COUNTER = 5
SWITCH PIN 7
HIGH
Note the new flowchart
symbol. This is the
decision symbol
WAIT 1 s
SWITCH PIN 7
LOW
NO
WAIT 1 s
?
HAVE WE
LOOPED 5
TIMES?
YES
STOP
For Next Loops – Pupil Activity
Gary Plimer 2006
Key in, download and run the following program.
symbol counter = b0
symbol red = 7
main:
' define the variable ‘counter’
' define pin 7 with the name ‘red’
for counter = 1 to 5
high red
pause 1000
low red
pause 1000
next counter
end
'
'
'
'
'
'
'
start a for … next loop
switch pin 7 high
wait for 1 second
switch pin 7 low
wait for 1 second
end of for … next loop
end program
Pupil Assignment
Gary Plimer 2006
Connect the buggy to the output
module.
The buggy should follow the path
shown in the diagram, moving in each
direction for three seconds.
Draw a flowchart for the movement of
the buggy, making use of a ‘for … next’
command structure.
3
3
3
3
Write a high-level program in PBASIC
to control the movement of the buggy
as shown by your flowchart.
Sub - Procedures
Gary Plimer 2006

A sub-procedure is a separate ‘mini-program’ that
can be called from the main program.

Once the sub-procedure has been carried out, the
main program continues.

Sub-procedures are often used to separate the
program into small sections to make it easier to
understand.

Sub-procedures that complete common tasks can
also be copied from program to program to save
time.
Pupil Activity
Gary Plimer 2006
symbol red = 7
symbol buzzer = 6
symbol counter = b0
' rename pin 7 ‘red’
' rename pin 6 ‘buzzer’
' define a counter using variable b0
main:
'
'
'
'
flash:
noise:
for counter = 1 to 25
high red
pause 50
low red
pause 50
next counter
return
'
'
'
'
'
'
'
'
make a label called ‘main’
call the sub-procedure flash
call the sub-procedure noise
loop back
' end of the main program
make a sub-procedure called ‘flash’
start a for … next loop
red LED on
wait 0.05 second
red LED off
wait 0.05 second
next loop
return from the sub-procedure
high buzzer
pause 2000
low buzzer
return
'
'
'
'
buzzer on
wait 2 seconds
buzzer off
return from the sub-procedure
gosub flash
gosub noise
goto main
end
Flowchart Symbol
Sub-Procedure symbol
Your teacher will show you
the correct way to draw a
flowchart which includes a
sub-procedure
Gary Plimer 2006
Pupil Assignment
A washing machine motor should rotate
15 seconds in one direction before
reversing and rotating 15 seconds in
the opposite direction. This should
repeat 10 times.

Draw a flowchart

Write a P-Basic program making
use of sub-procedures

Run and test your program
Gary Plimer 2006
Input Module



Gary Plimer 2006
Allows sensors to be connected to the stamp
controller
There are 4 digital and 2 analogue inputs
Pins 0 and 1 have a test button, they can be pressed
instead of adding switches
Gary Plimer 2006
Digital Signals and Input Transducers
Digital Sensors act like switches
They are either
VOLTAGE
ON or OFF
HIGH or LOW
1 or 0
5V
0V
TIME
Some common switches you will meet are the ,
Microswitch
Push and Rocker switch
Reed switch
Analogue Signals
Gary Plimer 2006
Volts
(V)
Time (s)
Analogue signals can vary between a maximum and minimum value
and depend on the conditions being monitored, for example light or
temperature.
Common analogue input transducers are the Light Dependent
Resistor, thermistor, (temperature sensor) and variable resistor.
More Symbols
Gary Plimer 2006
Microswitch (Single
pole, single throw).
Light Dependent
Resistor, LDR
Push Switch
-t
Push to make
Thermistor
Reed Switch
Magnet
Variable
Resistor
if-then Command
Gary Plimer 2006
To enable the Stamp Controller to accept inputs, we need
to learn a new command, the IF – THEN command
Connect a switch to pin 0, key in, download and run the program
listed below. This program makes output pin 7 flash every time the
push-switch on input pin 0 is pushed.
main:
flash:
if pin0 =1 then flash
goto main
' make a label called ‘main’
' jump if the input is on
' else loop back around
high 7
pause 2000
low 7
goto main
'
'
'
'
'
make a label called ‘flash’
switch output 7 on
wait 2 seconds
switch output 7 off
jump back to start
Pupil Assignment
A burglar alarm must sound a
buzzer and light a warning signal
for 20 seconds when any of the 2
windows in a room are opened.
Each window contains a reed
switch that is connected to the
alarm.
Draw a flowchart and write a
PBASIC program that will operate
the burglar alarm correctly. Use the
following input and output
connections.
Input
connection
Gary Plimer 2006
Pin
Output
connection
7
red light
6
buzzer
5
4
3
2
switch 1
1
switch 0
0
Pupil Assignment
As part of a Christmas
decoration in a shop, a
lighting sequence is to be
controlled by a
microcontroller. The output
connections are shown below.
Gary Plimer 2006
Input
connection
Pin
Output
connection
7
red light
6
yellow light
5
green light
4
3
When a visitor treads on a
pressure mat under the
carpet, the lights should flash
on and off in sequence three
times.
2
1
pressure
mat
0
Pupil Assignment
Develop a PBASIC program that will carry out the
instructions shown in the flowchart. Use the
following pin configuration.
Gary Plimer 2006
START
GREEN
LED ON
SWITCH
PUSHED?
Input
connection
Pin
Output
connection
Y
GREEN LED OFF
AMBER LED ON
7
red light
6
amber light
WAIT 3 s
5
green light
GREEN LED OFF
RED LED ON
4
WAIT 4 s
3
AMBER LED ON
2
1
start switch
0
WAIT 2 s
RED/AMBER LED
OFF
GREEN LED ON
N
Pupil Assignment
A washing machine operates as
follows.
Wait until the start switch is on.
Wait until the door switch is on.
Switch on the LED.
Switch on the solenoid bolt.
Wash cycle: repeated 20 times –
motor forwards for five seconds,
motor backwards for five
seconds.
Spin cycle: repeated 10 times –
motor forwards for two seconds,
motor backwards for two
seconds.
Switch off the solenoid bolt.
Switch off the LED.
Draw a flowchart and write a
PBASIC program to control the
movement of the washing
machine as described above.
Input
connection
Gary Plimer 2006
Pin
7
6
Output
connection
motor reverse
motor
forward
5
solenoid bolt
4
LED
3
2
door
Microswitch
1
start switch
0
Analogue Sensing
Gary Plimer 2006
Copy the program to your workbooks. Connect a LDR to the input
module, key in the program, run and test. In your own words
explain what is happening
main:
red:
green:
if sensorA > 50 then red
goto green
' make a label called ‘main’
' jump to red if the value > 50
' value is < 50 so jump to green
high 4
low 5
goto main
'
'
'
'
make a label called ‘red’
switch output 4 on
switch output 5 off
jump back to start
high 5
low 4
goto main
'
'
'
'
make a label called ‘green’
switch output 5 on
switch output 4 off
jump back to start
Pupil Assignment
A street lamp must turn on when the
light level is below the level ‘100’ and
turn off when the level is above ‘100’.
The lamp is connected to output 7
and the LDR light sensor is
connected to sensor A.
Draw a flowchart and write a PBASIC
program that will make the street
lamp work correctly.
Gary Plimer 2006
Pupil Assignment
Gary Plimer 2006
State whether each of the input transducers below is an analogue or
digital sensor.
(a) LDR
(b) reed switch
(c) microswitch
(d) thermistor
(e) variable resistor
(f) tilt switch
(g) push switch
(h) rocker switch
For each of the input transducers give an example of an electronic
product that may use that transducer. Explain how the transducer would
be used within the product.
Number Systems
Gary Plimer 2006
The Stamp Microcontroller can accept decimal numbers as
well as binary numbers. However, we need to tell the
microcontroller what we are using.
Decimal values are written as usual: 10 (= 10 in decimal)
Binary values are indicated by a % symbol: %10 (= 2 in
decimal)
Your teacher will now show you how to convert
decimal to binary and binary to decimal.
Pupil Assignment
Gary Plimer 2006
Convert each of the following binary numbers into decimal.
1) %11110000
2) %11000011
3) %01010101
4) %10101010
Convert each of these decimal numbers into binary.
1) 17
2) 23
3) 11
4) 38
5) 33
The “let dirs” command
Gary Plimer 2006
Up till now, if we wanted to switch on more than one output,
we needed to switch them on one by one. However, by using
binary, we can now switch on more than one pin at a time.
To enable us to achieve this, we must first tell the
microcontroller what pins are outputs and which are inputs.
To do this we use the
Let dirs = %00001111
dirs command.
‘let pins 0 to 3 be outputs the rest
inputs
The “let pins” command
Gary Plimer 2006
Once we have instructed the microcontroller what is outputs
and what is inputs, we use the let pins command.
Let dirs =%11111111
‘all pins outputs
Main:
let pins = %00001111
‘switch on pins 0 to 3
pause 1500
‘1.5 second delay
let pins = 0
‘switch all pins off
pause 1500
‘1.5 second delay
let pins = %11110000
‘switch on pins 4 to 7
pause 1500
‘1.5 second delay
let pins = 0
‘switch off all pins
end
‘end program
Stepper Motors
Stepper motors are very accurate
motors that are commonly used in
computer disc- drives, printers, X–
Y plotters and clocks. Unlike d.c.
motors, which spin round freely
when power is applied, stepper
motors require that their power
supply is continuously ‘pulsed’ in
four different patterns. For each
pulse, the stepper motor moves
around one ‘step’, typically 7.5
degrees (giving 48 steps in a full
revolution).
Gary Plimer 2006
Stepper Motors
Gary Plimer 2006
The table below shows the four different steps required to
make the motor turn. Copy the table into your workbook
Step
Coil 4
(output 7)
Coil 3
(output 6)
Coil 2
(output 5)
Coil 1
(output 4)
1
1
0
1
0
2
1
0
0
1
3
0
1
0
1
4
0
1
1
0
1
1
0
1
0
Pupil Assignment
An X-Y plotter movement is
controlled by stepper motors.
Write a P-Basic program that
will rotate the one stepper
motor 20 steps in one
direction then 20 steps in the
opposite direction.
Your teacher will show you
how to connect the stepper
motor to the stamp.
Gary Plimer 2006
End of unit Assignment
A new automatic railway
crossing is to be installed at a
local site. The operation of the
crossing should follow a set
sequence.
Design a PBASIC control program
to control the sequence described
on the next slide. The train sensors
give a logic (1) when the train is
sensed. For this simulation, you
only need to control one side of the
crossing, (one barrier and one
warning light).
Gary Plimer 2006
End of unit Assignment






Gary Plimer 2006
When a train is 1 mile from the crossing, a signal
is sent, warning of the train’s approach.
When the warning signal is received, the
crossing’s warning lights begin to flash.
The lights should flash on and off continuously at
1 second intervals.
After 30 seconds, the crossing barriers come
down.
The barriers remain down until the train activates
a second signal 1 mile further down the track.
After 30 seconds the barriers should rise and the
lights should stop flashing..