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 Microcontrollers
What is a microcontroller (µC) What is a microcontroller (µC)? PIC; Programmable integrated circuit is a microcontroller The “process” element of any system it belongs to 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 Microcontrollers
Some Example µC Applications Microcontrollers
microcontroller’s Lot of different types of PICs exist We use Genie 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 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 Microcontrollers
Sample Task answer Microcontrollers
µC Sizes PICAXE-18M GENIE-E18 PICAXE-14M GENIE-C14 PICAXE-08M PICAXE-28X GENIE-E28 Microcontrollers
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) 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 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 Microcontrollers
Review What is a microcontroller (PIC) µC ? Do microcontroller’s do anything useful without being 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 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 ? 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 Data flow direction arrows Microcontrollers
Flowchart Example Specification: start Specification: Turn on the lights as soon as it goes dark Turn all lights off Is it dark ? no yes Turn all lights on Microcontrollers
Flowchart Task You have 5 minutes !! 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 !! Microcontrollers
start Turn off both LED’s Switch 1 pressed ? no yes Turn on LED 1 no Wait 5s Turn on LED 2 Wait 5s Microcontrollers
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 !! Microcontrollers
Traffic light = yellow (flashing) start Task Answer Traffic light = green “man” = red Switch pressed ? Traffic light = yellow “man” = red yes no Wait 2s Traffic light = red “man” = green Wait 20s Traffic light = yellow (flashing) “man” = red Wait 2s Microcontrollers
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 Microcontrollers