1 / 82

Week #4 Parallel IO Interfacing

Week #4 Parallel IO Interfacing. ENG3640 Microcomputer Interfacing. Topics. I/O Addressing Techniques I/O Port Structure CPU12 I/O Ports Programming I/O Ports: Driving LEDs/7-Segment Displays Interfacing to Switches Switch Debouncing

lorand
Télécharger la présentation

Week #4 Parallel IO Interfacing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Week #4 Parallel IO Interfacing ENG3640 Microcomputer Interfacing

  2. Topics • I/O Addressing Techniques • I/O Port Structure • CPU12 I/O Ports • Programming I/O Ports: • Driving LEDs/7-Segment Displays • Interfacing to Switches • Switch Debouncing • Keypad Interfacing Techniques/Issues • Liquid Crystal Displays ENG3640 Fall 2012

  3. Resources • Huang, Chapter 4 Sections • 4.10 Intro to Parallel I/O Ports • 4.11 Simple I/O Devices • Huang, Chapter 7 Section • 7.2 I/O Related Issues • 7.3 I/O Addressing Issues • 7.5 The HCS12 Parallel Ports • 7.6 Electrical Characteristics • 7.7 Liquid Crystal Displays • Interfacing Parallel Ports to a keypad ENG3640 Fall 2012

  4. Why Parallel I/O? • Several embedded applications require interfacing an MCU with Light Emitting Diodes, Switches, Liquid Crystal Display, Seven Segment Displays. • I/O ports therefore have to be programmed to handle input/output signals. ENG3640 Fall 2012

  5. I/O Addressing Techniques • If the same address bus is used for both memory and I/O, how should the hardware be designed to differentiate between memory and I/O reads and writes? I/OInterface Memory CPU Data Address Control ENG3640 Fall 2012

  6. Memory Mapped I/O vs. Isolated I/O • Memory Mapped I/O (MOTOROLA): • Any instruction that reads or writes memory can read/write I/O Port • Address specifies which module (input, output, RAM, ROM), will communicate with the processor • Ex: LDAA #56 STAA $0024 (copy value to port H) • Isolated I/O (INTEL): • The control bus signals that activate the I/O are separate from those that activate the memory device. • These systems have a separate address space. • Separate instructions are used to access I/O and Memory. • Ex: IN AL, $10 (copy values of port $10 into register AL) Advantages/Disadvantages? ENG3640 Fall 2012

  7. I/O Port Structure Data Register: for data in transit Control Register: Hold commands from processor to port Status Register: Used to monitor I/O activity Polling Principle functionality is serve as way station for data in transit between the computer and external world. Interrupt Driven ENG3640 Fall 2012

  8. 1-KB SRAM 4-KB EEPROM 68HC812A4 Block Diagram CPU12 ENG3640 Fall 2012

  9. Memory Map ENG3640 Fall 2012

  10. Port Details

  11. General Purpose I/O: Bidirectional • Most GPIO pins on the 68HC12 MCU can be programmed for use in either direction. • Two registers: the data register PORT and data direction register DDR. • The DDR determines the direction of the port pin. • If the DDR = 1 then the port is an output and • if the DDR = 0 the data register output is disabled and the port pin is placed in high impedance state. ENG3640 Fall 2012

  12. I/O PORTS Addresses

  13. I/O PORTS Usage on EVB • Port B is connected to the Light Emitting Diodes (LEDS) • Each Port B line is monitored by an LED. • In order to turn on Port B LEDs, the PJ1 (Port J pin 1) must be programmed as output and set for logic zero. • If you ignore the status of the LEDs, the Port B can drive any other I/O on the breadboard. • Port P is connected to the Seven Segment Display • There are 4 digits of 7-Segment Displays on the EVB. • Port B is used to drive the 7-segment anodes and PP0-PP3 (Port P) to drive common cathodes • To use the 7-Segments you need to multiplex among them. • Port K is connected to the Liquid Crystal Display (LCD) • Port A is connected to the Hex Key Pad • Port H is connected to the DIP Switches and Push buttons.

  14. General Purpose I/O Usage • Parallel ports are often used for simple I/O such as turning on LEDs, 7-segment displays or reading switches (unconditional transfer) • Steps for using Ports: • Identify the address of an I/O port and its Data Direction Register (DDR) • Program the DDR by writing a value to it. • The value written to the DDR reflects the appropriate setting for the port (i.e a `0’ will make the corresponding pin an input and a `1’ will force the pin in the port to be an output). • Load a register with a value and store this value to the address of the I/O PORT. ENG3640 Fall 2012

  15. General Purpose I/O Usage To make bit 0 of PORTH (PH0) an output, we would use the following instruction: DDRH EQU $25 bset DDRH, $01 ; Set PORTH direction Once bit 0 of PORTH has been configured as an output, we can make the pin go to one by writing a one to bit0 of PORTH as follows: PORTH EQU $24 bset PORTH,$01 ; Set PORTH bit-0 high ENG3640 Fall 2012

  16. Avoiding Transients and Glitches • When the MCU is powered up or reset, all GPIO ports are configured as inputs. • The port will remain an input until the software changes the data direction register. • Can this cause a problem when a port is used as an output in normal operation? • The external device connected to the port may do strange things! • For example, if an output is connected to a motor or solenoid driver, the motor or solenoid may run intermittently during this time and have serious consequences! ENG3640 Fall 2012

  17. Avoiding Transients and Glitches • A pull-up or pull-down resistor can be added to the port so the node will always be pulled to the inactive level instead of floating. • The port can be preset to the inactive level before changing its direction to an output (when the port direction is changed a temporary glitch on the output will occur!) • To avoid the glitch, we can write to the port data register before the direction is changed. bset PORTH, $00 ; preset PORTH bit-0 low bset DDRH, $01 ; PORTH bit-0 an output ENG3640 Fall 2012

  18. Interfacing: Voltage Parameters • Like any digital device, before we can connect something to an input or output, we need to know the specification for the interface parameter. • The first parameter to consider are the input and output voltage levels and corresponding noise margins. VDD and VSS are supply voltages. The output voltage parameters are VOL and VOH.The input voltage parameters are VIL and VIH.For a digital system to work correctly, the output high voltage always must be between VIH,min and VDD. Noise Margin? ENG3640 Fall 2012

  19. Interfacing: Applications Like most digital logic devices, the output of MCUs can sink more current than they can source. Consequently, devices that require significant load current like an LED should be connected active-low. ENG3640 Fall 2012

  20. Light Emitting Diodes (LED) An LED emits light when current flows through it in the positive direction i.e. when the voltage on the anode side is made higher than the voltage on the cathode side. The forward voltage across the LED is typically about 1.5 to 2 Volts. MCU produces low ENG3640 Fall 2012

  21. Connecting an LED to an Output Port • Determine whether we can drive an active-low LED from an M68HC12 output? • Assume that a high-efficiency LED with IF,min = 10mA and VF,max = 2.0 V is used • The LED in the figure is connected active low so that when the output goes low, the current IL flows through the LED and turns it on. ENG3640 Fall 2012

  22. Connecting an LED to an Output Port • Using a 5-volt supply and assuming that the LED has a 2.0 V drop across it, what resistor value will limit the current to 10mA? • Answer: • 5V = 2.0V + IRx x Rx • Setting IRx to 10mA the resistor Rx is solved to be 300 Ohm. ENG3640 Fall 2012

  23. Connecting an LED to an Output Port • An I/O port pin of a microcontroller generally does not have enough drive to supply the current. • So an inverter is often used as a switch to turn the LED on and off. Active High since MCU produced a 1 to turn the LED on ENG3640 Fall 2012

  24. Use the 68HC12 Port H to drive green, yellow, red, and blue LEDs. Light each of them for half of a second in turn and repeat. The 68HC12 uses a 16-MHz crystal oscillator to generate internal clock signals. Solution: The upper four pins of the Port H can be used for this purpose. ENG3640 Fall 2012

  25. PORTH equ $24 DDRH equ $25 org $1000 ldaa #$FF ; configure PORTH for output staa DDRH ; “ Forever ldaa #$80 ; turn on green LED and turn off other LEDs staa PORTH ; “ jsr delay_hs ; wait for half of a second ldaa #$40 ; turn on yellow LED and turn off other LEDs staa PORTH ; “ jsr delay_hs ; wait for half of a second ldaa #$20 ; turn on red LED and turn off other LEDs staa PORTH ; “ jsr delay_hs ; wait for half of a second ldaa #$10 ; turn on blue LED and turn off other LEDs staa PORTH ; “ jsr delay_hs ; wait for half of a second jmp forever ; repeat swi ENG3640 Fall 2012

  26. Seven Segment Displays • Consists of seven LED segments (a, b, c, d, e, f, g) • Alphanumeric characters can be displayed by controlling the segments. • Two types of Seven Segment Displays: • Common Cathode • Common Anode ENG3640 Fall 2012

  27. Seven Segment Displays • Common Anode: • All anodes are tied in common. • Segment will be lit whenever a low voltage is applied. • Common Cathode: • all cathodes are tied in common. • Segment will be lit whenever a high voltage is applied. • Current limiting resistors must be included or else you might damage display. ENG3640 Fall 2012

  28. Seven Segment Displays: Examples • Depending on the type of display used a different hex code is generated by the MCU. • Common Anode: sending a ``0” will illuminate the segment. • Common Cathode: sending a ``1” will illuminate the segment. ENG3640 Fall 2012

  29. Seven Segment Displays: Decoders • Some ICs are specially designed to drive 7-segment displays. • They contain buffers to supply required drive currents. • When using MC144495 decoder, no current limiting resistors have to be used since they are built in the MC14495 ENG3640 Fall 2012

  30. Software 7-Segment Code Look-up • If your interface circuit uses only buffers and resistors to connect an output port to a seven segment display, you will have to use software to generate the character codes. • LAB #2 • The program can do this by using a look-up table. • The contents of the table depends on the application and type of display. • For example, to display hex digits for a common anode display, entry 4 would have the byte $19. • What addressing mode to use? ENG3640 Fall 2012

  31. Interfacing a Switch: Pull Up • To convert the mechanical signal into an electrical signal, a resistor pull-up is used. • The amount of current this output can source is determined by the resistor value. • When the switch is open, Output? • When the switch is closed, Output? +5V 1K I/O Port ENG3640 Fall 2012

  32. Interfacing a Switch: Pull Down • When the switch in pull-down circuit is open the output is pulled to the ground • The amount of current this output can sink (IOL) is determined by the resistor value. +5V I/O Port 1K ENG3640 Fall 2012

  33. Interfacing a Switch: PORTJ MCU • Port J on the MC68HC812A4 supports both internalpull-ups and pull-downs. • Either of the two previous circuits could be implemented on the 6812 without the resistor +5V PJ1 with pull-down PJ0 with pull-up ENG3640 Fall 2012

  34. PORTJ: Pull-up/Pull-down Registers • Each bit in the PUPSJ Register corresponds to a PORT J pin. • Each bit selects a pull-up or pull-down device for the associated PORT J pin. • The pull-up or pull-down is active only if enabled by the PULEJ Register ENG3640 Fall 2012

  35. PORTJ: Pull-up/Pull-down Registers ENG3640 Fall 2012

  36. PORTJ: Data Register/Data Direction • RECALL: PORTJ can act as a general purpose I/O • PORTJ (Data Register) and DDRJ (Data Direction Register) are used to setup the port for reading/writing information • PORT J is also used in the key wakeup feature of the MC6812! ENG3640 Fall 2012

  37. PORTJ : Wakeup Flag/Interrupt Enable • The key wakeup feature of the MC6812 issues an interrupt that wakes up the CPU when it is in stop or wait mode. • Wakeups are triggered with falling/rising signal edge • An interrupt is generated when a bit in KWIFJ register and its corresponding KWIEJ bit are both set. ENG3640 Fall 2012

  38. Switch Bouncing • When mechanical switches are opened or closed there are brief oscillations due to mechanical bouncing (switch bounce). +5V +5V A 0V What is the consequence of such bouncing for interfacing? ENG3640 Fall 2012

  39. Switch Debouncing • When the mechanical switch is touched (pressed) or released it bounces microscopically for a period of milliseconds. • The MCU will see many occurrences of ``make” and ``break” instead of one occurrence. • The MCU should see only one ``break” and one ``make” ENG3640 Fall 2012

  40. Switch Debouncing: Techniques • Several techniques exist to solve the debouncing problem: • Hardware Techniques: • RS-flip flop • Integrating debouncer (capacitor) • Schmitt Trigger Circuit • Software Techniques: • Delay loops ENG3640 Fall 2012

  41. Hardware Debouncing: Flip Flop NAND • An SR latch can be used to debounce a switch +5V S Q S R R Q +5V ENG3640 Fall 2012

  42. Hardware Debouncing: Schmitt Trigger • A Schmitt trigger is a special circuit that uses feedback internally to shift the switching threshold depending on whether the input is changing from low to high or high to low. • The difference between V T+ and V T- is called hysteresis. • A 74LS14 Schmitt Trigger inverter can be used to debounce a switch. VOUT V T- V T+ 5.0 VIN Example: 74LS14 2.1 2.9 5.0 ENG3640 Fall 2012 42

  43. Hardware Debouncing: Schmitt Trigger A noisy slowly changing input Output produced by ordinary inverter ENG3640 Fall 2012 43

  44. Hardware Debouncing: Schmitt Trigger A noisy slowly changing input Output produced by ordinary inverter Output produced by inverter with 0.8 V of hysteresis ENG3640 Fall 2012 44

  45. Integrating Debouncer: • The RC constant of the integrator determines the rate at which the capacitor charges up towards the supply voltage. • The capacitor value is chosen large enough so that Vout does not exceed the zero threshold value while the switch is bouncing! 5V R Vout Threshold Level C ENG3640 Fall 2012

  46. Calculating the capacitor value • Given R = 1K, bounce time = 5ms, what is the value of C such that the output voltage seen by the MCU = 0.7V? • Vout = 5 – 5e-t/RC • 0.7 >= 5 – 5e -5ms/(1K.C) • 0.86 <= e -5ms/(1K.C) • 1/0.86 >= e 5ms/(1K.C) • 1.16 > = e 5ms/(1K.C) • ln(1.16) >= 5ms/(1K.C) • C >= 5ms/(1K.ln(1.16)) = 33micro Farad. ENG3640 Fall 2012

  47. Integrating Debouncer: • The capacitor value is chosen such that the voltage does not exceed the 0.7-V threshold of the NOT gate while it is bouncing. 5V R 74LS14 MCU Input Port Vout C Problem? ENG3640 Fall 2012

  48. Integrating Debouncer: 5V 74LS14 1K Vout MCU Input Port 22 ohm C Current can be large (causes spark), these sparks will produce carbon deposits on the switch that will build up until switch no longer works. To limit the current a small resistor is placed in series with the switch. ENG3640 Fall 2012

  49. Software Debouncing • To debounce a switch we can use the following simple approach: • A software time delay is used that provides a time delay (usually 10-20 ms) longer than the duration of the switch bouncing action. • So if switch goes low, wait for longer than 10ms or 20ms and then test for the switch still being low. ENG3640 Fall 2012

  50. Keyboard/Keypad Interfacing • Keyboards are used to enter input into a computer. • A common type of keyboard is the matrix type. • It saves an amount of I/O wiring because the keys share wires. • Each has its own combination of row and column. ENG3640 Fall 2012

More Related