Transcript PICS

PICS / Microcontrollers
Objectives
 Understand:
 What is a Microcontroller (µC)-PIC
 What are the pros & cons of using µC’s
 How to design using µC’s
 Flowcharts
 Basic pseudo code
2
Microcontrollers
What is a microcontroller (µC)?
PIC; Programmable integrated circuit is a microcontroller
 The “process” element of any system it belongs to
3
Microcontrollers
What is a microcontroller ?
 Essentially: a complete computer system on a chip !
 CPU
 Flash Memory (same as a USB memory stick)
 Digital Inputs & outputs
 Most (but not all) µC’s also have analog inputs
 Need to be programmed to make them do something useful
4
Microcontrollers
Some Example µC Applications
5
Microcontrollers
microcontroller’s
• Lot of different types of PICs exist
– Stamp
– Picaxe
– OOPic
– Arduino
• We use Genie
– Can be simulated & programmed whilst in
circuit from a host computer via a USB
cable from circuit wizard
6
Microcontrollers
Task
 Generate 2 lists:
 What inputs could potentially be connected to a
microcontroller (PIC) ?
 What outputs could potentially be connected to a
microcontroller (PIC) ?
 For each input & output, draw the symbol that is
associated with it
7
Microcontrollers
Sample Task answer
8
Microcontrollers
µC Sizes
PICAXE-18M
GENIE-E18
PICAXE-08M
GENIE-C08
PICAXE-14M
GENIE-C14
PICAXE-20M
GENIE-C20
9
Microcontrollers
PICAXE-28X
GENIE-E28
Functionality
 A µC can be programmed to perform any logical function
 Counting / maths
 Sequencing
 Latching
 Delays / timing
 Decoding
 Encoding
 Conditional switching
 For simple functions, it may be more cost efficient to use
dedicated hardware (counter chips / timer chips / logic
gates)
10
Microcontrollers
Clocks
 A microcontroller (PIC) executes one instruction every time
it receives a clock pulse
 TASKS:
1. Draw a clock waveform
2. Name a circuit that can produce a clock waveform?
 Some simple microcontroller’s have internal clock generator
circuits
 Can also use crystals to generate very precise, very fast clocks
11
Microcontrollers
Microcontroller (PIC)
Considerations
 Cost
 For simple functions, may be more expensive than simple logic
 For complex functions may be more efficient
 Speed
 Typical clock speed for a Genie is 8MHz
 May be slower than dedicated hardware
 Complexity
 The hardware is very simple
 The complexity of design is in the programming (firmware)
 Flexibility
 microcontroller’s can be changed very easily during production or in the field
(maintenance & reuse)
 Size
 Much more space efficient than dedicated logic or PC’s for complex functions
 Power supply
 They require a very precise voltage between 3.3 and 5.0 Volts
12
Microcontrollers
Review
 What is a microcontroller (PIC) µC ?
 Do microcontroller’s do anything useful without being





13
programmed ?
What could they be used for ?
Does changing the circuit function require a change to the
electronic hardware ?
Does removing the power mean that the microcontroller
needs reprogramming ?
What are some of the advantages of microcontroller’s
What are some of the disadvantages of microcontroller’s
Microcontrollers
How are microcontroller’s (PIC)Programmed ?
 A program is developed & simulated on a PC
 downloaded to the PIC via a programming cable
 The program can be written directly using a programming
language
 BASIC
C
 Other
 The program can be translated from a flow diagram
14
Microcontrollers
Review
 How many times do you need to connect the microcontroller
to a PC ?
 How is the program developed on the PC ?
 How do you know if the program you have written is going
to do the right thing before you download it ?
15
Microcontrollers
Flowcharts - symbols
Terminator: used to start or stop a program
Process box
Describes an action of some sort
The action may or may not be dependant on inputs
The action may not affect any outputs
Only one arrow may enter or leave the box
Decision box
Different routes out of the box can be taken
depending upon a condition
One arrow enters the box and two leave the box
- arrows leaving the box should be labelled
Set outputs
1 or more system outputs may change state
Only one arrow may enter or leave the box
16
Microcontrollers
Data flow direction arrows
Flowchart Example
Specification:
Turn on the lights as soon as it
goes dark
start
Turn all
lights off
no
Is it dark ?
yes
Turn all
lights on
17
Microcontrollers
Flowchart Task
 A quiz game for 2 players
 Each player has a switch to activate a buzzer
 You must decide which was pressed first and indicate your
result by lighting one of two LED’s for 5 seconds
start
You have 5 minutes !!
18
Microcontrollers
start
Turn off
both
LED’s
no
no
Switch 1
pressed ?
yes
Turn on
LED 1
Switch 2
pressed ?
yes
Turn on
LED 2
19
Microcontrollers
Wait 5s
Wait 5s
Task
 Show the sequence of events
needed in the design of a
pedestrian crossing
 A switch gets pressed and the
man goes from red to green
.......
 What else ????
 You have 5 minutes !!
20
Microcontrollers
start
Task Answer
Traffic light = yellow
“man” = red
Wait 2s
Traffic light = red
“man” = green
Wait 20s
Traffic light = yellow (flashing)
“man” = red
21
Microcontrollers
Wait 2s
Traffic light = green
“man” = red
yes
Switch
pressed ?
no
Exam Questions
 For the past 3 years, at least one big question has been on
Microcontroller (µC)-PIC
 questions can be worth up to 22 marks
 This is 2 full grades worth of marks !
 Don’t worry about types of Microcontroller (µC)-PIC or exact
programming code
 Think about the logical processing flow that has to happen to
make a function work
22
Microcontrollers