More Related Content
More from محمدعبد الحى (13)
Dio
- 2. Agenda:
•
Topics:
•
ATMEGA 32 and DIO
pull up and down resistors
types of switches
switch bouncing
Led ,seven segment and Led Matrix
Practical work :
switching led on and off through sw with delay
switching led on and off through switch
exp of bouncing and solve it through Sw(first time) and Hw(second time)
make any digit on Led matrix
make counter using seven segment
Copyright © 2012 Embedded Systems
Committee
- 3. ATMEGA 32 and DIO:
ATmega 32 has 32 programmable I/O lines divided into 4 PORTS(groups):
1-PORTA(PA7……..PAO)
2-PORTB(PB7….…..PBO)
3-PORTC(PC7….…..PCO)
4-PORTD(PD7……..PDO)
Each PORT is controlled by 3 registers:
1-DDRx (Data Direction Register)
2-PORTx (Output Register)
3-PINx (Input Register
Note: Most pins in Mc make more than one function(multiplexed
functions)
Copyright © 2012 Embedded Systems
Committee
- 4. ATMEGA 32 and DIO (cont.):
ATmega 32 pin out
Copyright © 2012 Embedded Systems
Committee
- 5. ATMEGA 32 and DIO (cont.):
Register controlling I/O port:
Copyright © 2012 Embedded Systems
Committee
- 6. How to set value in register:
Example:
DDRA=5;
//(decimal)mean I activate pin 0 and pin 2 as output
and the rest as input pins
DDRB=0x14;
//(hexadecimal)mean I activate pin 2 and pin 4 as
output and the rest as input pins
DDRC=0b00000011;
//(binary)mean I activate pin 0 and pin1 as output
and the rest as input pins
Copyright © 2012 Embedded Systems
Committee
- 7. How to set a specific pin with conserving
other pins:
To set specified pin with 1:
Make OR operation on the register with The pin no
Example: We want to set pin no 5 with 1
PORTA=PORTA|(0b00100000);
//(decimal)32
To set specified pin with 0:
Make AND operation on the register with (NOT) The pin no
Example: We want to set pin no 3 with 0
PORTB=PORTB&( ~(0b00001000) );
//(decimal)8
Copyright © 2012 Embedded Systems
Committee
- 8. How to set a specific pin with conserving
other pins:
To toggle specified pin with 0:
Make XOR operation on the register with The pin no
Example: We want to set pin no 2 with 0
PORTB=PORTB^(0b00000100) );
//(decimal)4
Copyright © 2012 Embedded Systems
Committee
- 9. ATMEGA 32 and DIO (cont.):
Driving pin:
Copyright © 2012 Embedded Systems
Committee
- 10. Pull up and pull down resistors:
Consider this schematics:
• The input state of most logic gates is called a high impedance.
• the value of the input is considered to be floating.
• Most gates will float towards a high state. This is a very weak condition,
and any electrical noise could cause the input to go low.
• This convert pin as antenna that can receive electrical noise
Copyright © 2012 Embedded Systems
Committee
- 11. Pull up and pull down resistors (cont.):
Solution:
Copyright © 2012 Embedded Systems
Committee
- 12. Switches:
Types of electronics switches
Toggle switch: The toggle switch is usually a two position switch. The internal
construction includes a spring such that it is held firmly in the position to which it
has been switched.
Push button switch: Push button switches are used in many electronic circuits.
These electronic switches are often used when a push action is required to give a
momentary connection.
Rotary switch: As the name implies, rotary switches are operated by turning a knob.
Selecting the correct position enables the relevant connections to be made.
Copyright © 2012 Embedded Systems
Committee
- 13. Switches (cont.):
ON-OFF
Single Pole, Single Throw = SPST
(ON)-OFF
Push-to-make = SPST Momentary
ON-(OFF)
Push-to-break = SPST Momentary
Copyright © 2012 Embedded Systems
Committee
- 14. Switches (cont.):
ON-ON
Single Pole, Double Throw = SPDT
ON-OFF-ON
SPDT Centre Off
Dual ON-OFF
Double Pole, Single Throw = DPST
Copyright © 2012 Embedded Systems
Committee
- 15. Switches (cont.):
Dual ON-ON
Double Pole, Double Throw = DPDT
ON-OFF-ON
DPDT Centre Off
DIP Switch (DIP = Dual In-line Parallel)
Multi-way Switch
Copyright © 2012 Embedded Systems
Committee
- 16. Switches (cont.):
Switch parameters and specifications
1-volltage rating: This is the maximum voltage that the switch can
withstand
.
2-Current carrying rating: The rating of the maximum steady current that a
switch can carry through a closed contact.
3-Contact resistance
4-Number of operations:
Copyright © 2012 Embedded Systems
Committee
- 17. Dealing with Switch Bouncing:
The Problem:
Switch closed:0v
Switch opened:5v
>Due to the mechanical nature of any switch that may contains spring
return action of some kind.
>there wont be a clean transition from a state
to another.
>there will be a series of high and low states
spikes as shown.
Copyright © 2012 Embedded Systems
Committee
- 18. Dealing with Switch Bouncing (cont.):
The Solution:
1-Hardware Based:
>Add a capacitor that makes the voltage smooth
and clean(without spikes).
>the value of R and C determine to react and give
adequate output , As T=RC and the capacitor is full
charged at 5T:
>you can choose R1 = 10 K and C1 = 100 nf
>add a schmitt trigger so that it can output
5v (threshold value)when capacitor Is full
charged.
Copyright © 2012 Embedded Systems
Committee
- 19. Dealing with Switch Bouncing (cont.):
2-Software Based:
>T1 and T2 are fake logic 0 but T3 is the valid one
> Difference between those is their length.
>Make a counter count up as long as the signal is Low, and reset this counter when
the signal is High.
>If the counter reach a fixed value(bigger than T1 or T2) this means that
the pulse is a valid pulse (T3).
Copyright © 2012 Embedded Systems
Committee
- 20. LED:
>we want to calculate value of Resistance that put in serial with Led:
>supply voltage Vcc=5v
>According to datasheet Vd=2v, Id=15mA
>so the value of resistance is 200 ohm
Copyright © 2012 Embedded Systems
Committee
- 21. Seven Segment Display (cont.):
>The required current per small segment is 2mA in very small display
>The current per segment is 60 mA and increase in the case of of larger Display.
>For safe mode we can use a driver such as UDN2981A and UDN2585A IC’s.
Copyright © 2012 Embedded Systems
Committee
- 22. Seven Segment Display:
>UDN2585A can source up to 120 mA while UDN2981A can source up to 500mA.
>So that we can illuminate large displays without burning the Microcontroller.
Copyright © 2012 Embedded Systems
Committee
- 23. LED Matrix:
>We have a Problem here that we have to connect column pins to micro
and the micro pins must be Logic 0.
> so that micro has to sink so much current so that we need a solution.
Copyright © 2012 Embedded Systems
Committee
- 24. LED Matrix (cont.)
The solution
Put ULN2003A IC that output 0 when the input is 1,so we can output Logic 1
from micro that make it protected.
Copyright © 2012 Embedded Systems
Committee
- 25. LED Matrix (cont.)
How we can write alphabet A on Led Matrix???
Copyright © 2012 Embedded Systems
Committee
- 26. LED Matrix (cont.)
Steps
Copyright © 2012 Embedded Systems
Committee
- 28. Programming Embedded System I(book)
Esc Presentation
Links:
http://www.kpsec.freeuk.com/components/switch.htm
http://www.electronics-radio.com/articles/electronic_components/switchesrelays/electronics-switches.php
http://www.ikalogic.com/de-bouncing-circuits/
http://www.micahcarrick.com/avr-tutorial-switch-debounce.html
http://embedded-lab.com/blog/?p=2478
Copyright © 2012 Embedded Systems
Committee