18/08/2013
Embedded Systems Design ELEN90066
Lecture 6 Push Buttons, Interrupts, LEDs David Jahshan
Notes from last lecture
• VoltageDividersandhowtousethem
• Pulsewidthmodulation
• Howtouseaboostconverter
• Howtoreadtheboostconverterdatasheet
• Understandingefficiencyofpowerregulation circuits. Pin x efficiency = Pout
• Vin x Iin = Vout x Iout + Heat generated
• Youshouldbeabletowireupthepowersupply.
Example exam question
• A boost converter takes a 3.2v input from a lithium ion cell and outputs 4v at 100mA. What is the input current if the device is 90% efficient at that operating point.
• Referring to the graph on the top left of page 9 of the SC120 data sheet, what is the efficiency of the SC120 if there is an input of 3.2v and an output of 4v at 100mA. What is the input current.
Specifications
• 1.3 The device will have a two pin 2.54mm header, one pin connected to the 3.3v line the other pin to ground to power during debugging.
• 1.4 The device will have a two pin 2.54mm header, one pin connected to the 1.5v line the other pin to ground to power during debugging.
• 1.5 The device will have a single ground pin connected to ground to facilitate the connection of the ground wire of the oscilloscope. This pin will be far away from any other pins such that the alligator clips do not risk shorting other components to ground.
• 1.6 A green LED will illuminate if the power is on.
Specification Soft Power
• 2.1 The device will have a soft power switch.
• 2.1.1 The device will power on when the power push button is pressed and the device is in the off state.
• 2.1.2 The device will power off when the power push button is pressed and the device is in the on state.
• 2.1.3 The device will use less than 1uA of standby current.
D Flip Flop
• When rising edge of a clock (clk), the state at the input (D) is stored and made available on the output (Q) the inverse is also available (Q’)
• How can we use a D Flip Flop for soft power?
DQ
Clk
Q’
1
18/08/2013
Push button switch
• Creates a short circuit when button is pressed
• How do we convert this to a clocked input into the D Flip Flop
Why wont these work?
Floating Inputs are Bad!
• Undefined states are just that undefined. – Are effected by background noise.
– Must always tie floating inputs high or low
Power Usage
• If the flip flop is always powered will the battery not be drained?
• Lets look at the D-Flip Flop data sheet.
• Virtually no power to run the device.
• Why don’t you power the circuit off the D Flip Flop output?
• Lets look at the Boost Converter data sheet.
Contact Bounce
• When a switch is pressed the contact is usually not smooth.
Image: Wikipedia Creative Commons
Debouncing using a capacitor
• By adding a capacitor you slow down the change in voltage, removing the bounce.
2
18/08/2013
Push Button Inputs
• 3.PushButtonInputs
• 3.1Thedevicewillhaveupto9pushbuttons.
• 3.2Therewillbeonebuttonforpower.
• 3.3Therewillbefourbuttonsforleft,right,up and down.
• 3.4Therewillbeatleastoneactionbutton.
• 3.5Therewillbeonebuttontoresetthe
microcontroller
• 3.6Theremaybetwomoreadditionalaction buttons.
Push buttons to microcontroller
• Why would this circuit work as an input to the microcontroller?
ATMEGA16 Input Pins
• Have software enabled pull up resistors. • Lets have a look in the data sheet.
Interrupts Specification
• 3.7 The buttons will be debounced using an RC circuit.
• 3.8 Multiple simultaneous button presses should be detectable.
• 3.9 Circuitry will be included to generate a single interrupt when any button is pressed.
Interrupts vs polling
• Polling is checking if the button is pressed over and over again.
– Wastes CPU cycles.
– Known reaction time.
• Interrupt creates a signal when a button is pressed.
– CPU does not check signal until the button is pressed.
– Reaction time less predictable.
Routing multiple signals to a single interrupt
• ATMEGA 16 only has 3 external interrupts, we require up to 7 buttons to three interrupts.
• We can connect multiple gates through a multi input AND,OR,NAND,NOR gate.
• Which one do we use.
• Remember floating inputs are bad!
3
18/08/2013
Reset button
• Allows you to reset the microcontroller, so that you can restart your program
• Very useful during debugging
• Good practice to use an external pull up and possibly a capacitor to ensure no accidental resets due to noise in the system.
Next Lecture
• LEDs
• Brightness control of backlight
• Driving enough current through the backlight • LCD interfacing
• RAM interfacing
• Analogue to digital converters
4