Using MAX II & MAX 3000A Devices as a Microcontroller I/O Expander Application Note 265 March 2004, ver 2.0 Introduction Many microcontroller and microprocessors limit I/O ports and pins to conserve pin counts and reduce package sizes. For many microcontroller(e.g., PIC, 8051, and SX) or microprocessor-based systems, the system design requires more I/O pins without changing the microcontroller. To increase the number of I/O pins without changing the microcontroller, I/O expansion provides a solution. With up to 272 I/O pins and MultiVoltTM I/O capability, Altera® MAX® II and MAX 3000A devices allow you to implement microcontroller I/O expansion in microcontroller- or microprocessor based systems. This application note explains how to implement a microcontroller I/O expander in MAX II and MAX 3000A devices. Advantages of Using MAX II & MAX 3000A Devices A key advantage of using MAX II and MAX 3000A devices as a microcontroller I/O expander is the integration of logic functions across your entire board. The flexibility of a programmable device means that not only can the I/O expansion function be implemented, but other functions can be integrated such as LED drivers or bus-bridging logic. Additionally, with the user flash memory in MAX II devices, functions that use memory also can be implemented. This integration allows you to reduce component count across the board, minimizing cost and maximizing board space efficiency. Another advantage in using MAX II and MAX 3000A devices is the MultiVolt I/O capability which enables MAX II and MAX 3000A devices to interface to multiple-voltage I/O pins (i.e., 5.0 V, 3.3 V, 2.5 V, 1.8 V, and 1.5 V). This capability allows you to implement voltage-level shifting to interface older 5.0-V devices with newer 3.3-V, 2.5-V, 1.8-V, or 1.5-V devices or microcontrollers. Table 1 summarizes the MultiVolt I/O support for MAX II and MAX 3000A devices. Table 1. MAX II & MAX 3000A MultiVolt I/O Support (Part 1 of 2) Device MAX 3000A VCCINT VCCIO (V) (V) 3.3 Altera Corporation AN-265-2.0 Input Signal (V) 1.5 1.8 Output Signal (V) 2.5 3.3 5.0 3.3 v v 2.5 v v 1.5 1.8 2.5 3.3 5.0 v v (1) v v v v 1 Preliminary Using MAX II & MAX 3000A Devices as a Microcontroller I/O Expander Table 1. MAX II & MAX 3000A MultiVolt I/O Support (Part 2 of 2) Device VCCINT VCCIO (V) (V) MAX II 3.3 2.5 1.8 Input Signal (V) 1.5 1.8 2.5 Output Signal (V) 3.3 5.0 1.5 1.8 2.5 3.3 v (2) v v (3) v (4) v (4) v (4) 2.5 v v v (7) v (7) v v v (8) v 1.8 v 1.5 v v (9) v (9) 3.3 5.0 v v (5), (6) v v v Notes to Table 1: (1) (2) When VCCIO is 3.3 V, a MAX 3000A device can drive a 2.5-V device that has 3.3-V tolerant inputs. When VCCIO = 3.3 V and a 2.5-V input signal feeds an input pin, the VCCIO supply current will be slightly larger than expected. (3) (4) (5) (6) (7) (8) (9) MAX II devices can be 5.0-V tolerant with the use of an external resistor and the internal PCI clamp diode available in the EPM1270 and EPM2210 devices. When VCCIO = 3.3 V, a MAX II device can drive a 1.5-V, 1.8-V, or 2.5-V device with 3.3-V tolerant inputs. When VCCIO = 3.3 V, a MAX II device can drive a device with 5.0-V LVTTL inputs. MAX II outputs can drive a 5.0-V LVCMOS input if the output is configured as open-drain and pulled up to 5.0 V with an external resistor. For this case, the internal PCI clamping diode must be enabled. When VCCIO = 2.5 V, a MAX II device can drive a 1.5-V or 1.8-V device with 2.5-V tolerant inputs. When VCCIO = 1.8 V, a MAX II device can drive a 1.5-V device with 1.8-V tolerant inputs. When VCCIO = 1.5 V and a 2.5-V or 3.3-V input signal feeds an input pin, higher pin leakage current is expected. The large number of I/O pins on MAX II and MAX 3000A devices make them an ideal device for microcontroller I/O expansion. Tables 2 and 3 show the maximum user I/O pins available in MAX II and MAX 3000A devices. The maximum I/O pins available are 272, which translates to 34, 8-bit ports. Additionally, in-system programmability (ISP) means that these features come with the flexibility of reprogrammability on the board. Table 2. Maximum User I/O Pins in MAX II Devices Maximum User I/O Pins EPM240 EPM570 EPM1270 EPM2210 80 160 212 272 Table 3. Maximum User I/O Pins in MAX 3000A Devices Maximum User I/O Pins 2 Preliminary EPM3032A EPM3064A EPM3128A EPM3256A EPM3512A 34 66 98 161 208 Altera Corporation Using MAX II & MAX 3000A Devices as a Microcontroller I/O Expander Implementing a Microcontroller I/O Expander in MAX II & MAX 3000A Devices The I/O expander design example includes four ports (A, B, C, and D) which can be independently programmed as I/O ports. Each port is 8 bits wide and is bidirectional, becoming an input port when tri-stated. You can connect the microcontroller unit (MCU) port to or from any port (A, B, C, or D) to perform read and write operations. Figure 1 shows the block diagram of the design example for the microcontroller I/O expander. Figure 1. Block Diagram for Microcontroller I/O Expander Design Example in MAX II & MAX 3000A Devices 8 Port A 8 8 8 Input Data Registers 8 8 8 Port B 8 4 MCU Port 2 2 I/O Setting Data Register I/O Ports 8 4 I/O Ports Port C 8 Output Data Registers 8 8 8 8 8 Port D 8 CLK CS Altera Corporation RST CONF LOAD WR RD MODE 3 Preliminary Using MAX II & MAX 3000A Devices as a Microcontroller I/O Expander Table 4 lists all the functions of the input and output pins. Table 4. Input & Output Pins in a Microcontroller I/O Expander Example Design (Part 1 of 2) I/O Name Type Description Active CLK Input Input clock signal to the trigger Input data registers, output data registers, and I/O setting data registers. MCU port Bidirectional 8-bit bidirectional data lines that interface with the MCU data bus. The 8-bit data can be written into or read out of the microcontroller I/O expander on the WR and RD signals with a positive edge clock trigger. Configuration data is also transmitted through this port. The MODE signal determines whether the MCU port is a data or address bus. CS Input Input signal to select the device. Low RST Input Input signal to reset the device and all internal registers asynchronously. Low CONF Input This control signal stores the address[5..0] from the MCU port on the rising edge of CLK into the configuration registers. CONF enables the clock signal to the configuration registers. Data on address[7..6] is ignored. (The operation will be discussed later in this application note.) Low LOAD Input This control signal stores the address[1..0] from the MCU port the rising edge of CLK into the configuration registers. LOAD enables the clock signal to the configuration registers. Data on address[7..2] is ignored. (The operation will be discussed later in this application note.) Low WR Input Input signal that causes the data on the MCU port to be written to the enabled port (A, B, C, or D) on the rising edge of CLK. WR enables the clock signal to the output data registers. Low RD Input Input signal that enables the data bus transfer to the MCU port from the enabled port (A, B, C, or D) on the rising edge of CLK. RD enables the clock signal to the input data registers. Low MODE Input Tri-states the MCU port when this signal is high. The MCU port setting (input or output) depends on the configuration registers when MODE is low. - Port A Bidirectional 8-bit, general-purpose I/O port that can be programmed to either output or input mode. - Port B Bidirectional 8-bit, general-purpose I/O port that can be programmed to either output or input mode. - 4 Preliminary Positive Edge - Altera Corporation Using MAX II & MAX 3000A Devices as a Microcontroller I/O Expander Table 4. Input & Output Pins in a Microcontroller I/O Expander Example Design (Part 2 of 2) I/O Name Type Description Active Port C Bidirectional 8-bit, general-purpose I/O port that can be programmed to either output or input mode. - Port D Bidirectional 8-bit, general-purpose I/O port that can be programmed to either output or input mode. - Functional Description The microcontroller I/O expander operates as a slave that sends and receives data through the MCU port. Data is sent through the I/O expander at the rising edge of CLK when the WR signal is low (with CS set to low) and received at the rising edge of CLK when the RD signal is low (with CS set to low). If the WR or RD signal is high, the CLK signal is disabled through the input/output data registers so that no data can be sent or received through the MCU port. Write Mode In write mode, the selected port (Port A to Port D) will be configured as an output port and the MCU port as an input port. When the WR signal is low (with CS set to low), the clock through the output registers is enabled. Therefore, the data from the MCU port will be written to the output data register of the selected port on the rising edge of CLK. Read Mode In read mode, the selected port (Port A to Port D) will be configured as an input port and the MCU port as an output port. When the RD signal is low (with CS set to low), the clock through the input data registers is enabled. Therefore, the data from the selected port will be written to the input data registers of the MCU port on the rising edge of CLK. 1 During read and write operation, the MODE signal control pin must be set to low. See “Design Verification” on page 8 for an example of read and write operations. Configuration of the Microcontroller I/O Expander Configuration of the microcontroller I/O expander is used to determine whether the port is input or output and enabled or disabled. Activation of the new configuration occurs with a single configuration pulse of the CONF signal for one clock period. Altera Corporation 5 Preliminary Using MAX II & MAX 3000A Devices as a Microcontroller I/O Expander Data controlling the microcontroller I/O expander is stored in a set of 6-bit registers. Data to be written into these registers, consisting of 4 bits for I/O port configuration data and 2 bits of address for the enabled port address data, is placed on the input address bus (MCU port) with the MODE signal set to high and the CS signal set to low. Input data is stored in the configuration registers at the rising edge of CLK when the CONF signal is low (with CS set to low), which enables the clock through the configuration registers. This transition causes the state of the microcontroller I/O expander to be set to the selected configuration. When the LOAD signal is asserted low (with CS set to low) to enable the clock through the configuration registers, only 2 bits of the enabled port address data (bit1 and bit0) are stored in the configuration registers at the rising edge of CLK. Use the LOAD signal when you need to select the enabled port to perform read or write operation instead of configuring the ports. Figure 2 shows the functionality of every bit in the address bus during configuration mode. Figure 2. I/O Expander Address Bus Configuration Function A7 6 Preliminary A6 A5 A4 A3 A2 bit 7-6: A7:A6: No functionality bit 5: A5: Port D configuration bit 0 = Configured as input 1 = Configured as output bit 4: A4: Port C configuration bit 0 = Configured as input 1 = Configured as output bit 3: A3: Port B configuration bit 0 = Configured as input 1 = Configured as output bit 2: A2: Port A configuration bit 0 = Configured as input 1 = Configured as output bit 1-0: A1:A0: Port Address A1 A0 Altera Corporation Using MAX II & MAX 3000A Devices as a Microcontroller I/O Expander Table 5 shows the address contents to enable the particular I/O ports. Table 5. Port Addresses A1:A0 Port 00 A 01 B 10 C 11 D MCU port direction, input or output, cannot be directly configured by the user. It is configured internally by the selected enabled port. For example, if the enabled port is in input mode, the MCU port is set to an output mode. However, you can use the MODE signal control pin to tri-state the MCU port so that it becomes an input port, allowing you access to the configuration registers. Reset mode is also supported in the microcontroller I/O expander reference design. When the RST signal is asserted (with CS set to low), the contents of all registers will be reset to zero asynchronously and the entire I/O expander will be in its initial state, where all the ports (including the MCU port) are set to input mode. Microcontroller I/O Expander Implementation The microcontroller I/O Expander design example can be targeted to MAX 3000A devices (EPM3128ATC100) or MAX II devices (EPM240T100C3) using the Quartus® II software. The design utilization in MAX 3000A and MAX II device is shown in Tables 6 and 7. The data in both Tables 6 and 7 show that there are sufficient resources (I/O pins and macrocells/logic elements) remaining in the device for the implementation of the other logic in the system. Table 6. Microcontroller I/O Expander EPM240 Utilization Resource Altera Corporation Available Used Utilization (%) Logic Elements 240 67 27 Flipflops 240 50 20 I/O Pins 80 48 60 7 Preliminary Using MAX II & MAX 3000A Devices as a Microcontroller I/O Expander Table 7. Microcontroller I/O Expander EPM3128A Utilization Resource Available Used Utilization (%) Macrocells 128 51 39 Flipflops 128 50 39 I/O Pins 80 48 60 Shareable Expanders 128 2 1 Design Verification Design verification of a microcontroller I/O expansion was accomplished by using the Quartus II software. The design was verified both in functional and timing simulation in MAX II (EPM240T100C3) and MAX 3000A (EPM3128ATC100) devices. Figures 3 and 4 show the timing simulation of the microcontroller I/O expansion during read and write operation. 8 Preliminary Altera Corporation Using MAX II & MAX 3000A Devices as a Microcontroller I/O Expander Figure 3. Microcontroller I/O Expansion Write Mode Timing Simulation Configure the Microcontroller I/O Expander The Low Signal of the WR Enables the Clock through the Output Data Registers to Create New Output Values Change the Enabled Port The WR Signal Creates New Output Values With all the I/O pins in tri-state mode, each port is initialized. After initialization, Port A and Port B are configured as output, Port C and Port D are configured as input, and Port B is enabled for write operation. When WR asserts a low signal, the clock through the output data registers is enabled and creates a new output value (146) at the output Port B from the MCU port. Altera Corporation 9 Preliminary Using MAX II & MAX 3000A Devices as a Microcontroller I/O Expander In the last section of simulation, Port A is enabled once the LOAD signal is asserted low. When the WR signal is low to enable the clock through the output data registers, the MCU port data (108) is created at the output Port A. Figure 4. Microcontroller I/O Expansion Read Mode Timing Simulations The RD Signal Creates New Output Values Configure the Microcontroller I/O Expander 10 Preliminary Change the Enabled Port The Low Signal of the RD Enables the Clock through the Input Data Registers to Create New Output Values Altera Corporation Using MAX II & MAX 3000A Devices as a Microcontroller I/O Expander With all the I/O pins in tri-state mode, each port is initialized. After initialization, all ports (A, B, C, and D) are configured as inputs and Port C is enabled for read operation. When RD asserts a low signal, the clock through the input data registers is enabled and creates a new output value (214) at the MCU port from Port C. While in last part of the simulation, Port D is enabled once LOAD is asserted low. When RD is low to enable the clock through the input data registers, Port D data (146) is created at the MCU Port. Microcontroller I/O Expander Applications Figures 5 shows how to increase the microcontroller’s I/O ports using the I/O expander. This microcontroller I/O expander can be targeted or modified to target to any 8-bit microcontroller (e.g., PIC and 8051). Figure 5. Application of Microcontroller I/O Expander Microcontroller I/O Expander RD output 8 RD Port A WR output WR CS output CS 8 Port B LOAD output LOAD CONF output CONF 8 Port C MODE output MODE RST output 8 RST Port D 8 Microcontroller I/O Port CLK MCU Port CLK System Clock Conclusion Altera Corporation With up to 272 I/O pins and MultiVolt I/O capability, Altera MAX II and MAX 3000A devices allow you to implement microcontroller I/O expansion in a single device. MAX II and MAX 3000A devices enable you to design custom microcontroller I/O expanders with additional features other than the example provided in this application note. 11 Preliminary Using MAX II & MAX 3000A Devices as a Microcontroller I/O Expander 101 Innovation Drive San Jose, CA 95134 (408) 544-7000 www.altera.com Applications Hotline: (800) 800-EPLD Literature Services: [email protected] 12 Preliminary Copyright © 2004 Altera Corporation. All rights reserved. Altera, The Programmable Solutions Company, the stylized Altera logo, specific device designations, and all other words and logos that are identified as trademarks and/or service marks are, unless noted otherwise, the trademarks and service marks of Altera Corporation in the U.S. and other countries. All other product or service names are the property of their respective holders. Altera products are protected under numerous U.S. and foreign patents and pending applications, maskwork rights, and copyrights. Altera warrants performance of its semiconductor products to current specifications in accordance with Altera's standard warranty, but reserves the right to make changes to any products and services at any time without notice. Altera assumes no responsibility or liability arising out of the application or use of any information, product, or service described herein except as expressly agreed to in writing by Altera Corporation. Altera customers are advised to obtain the latest version of device specifications before relying on any published information and before placing orders for products or services. Printed on recycled paper Altera Corporation