Professional Documents
Culture Documents
Handbook
R
R
Xilinx is disclosing this Document and Intellectual Property (hereinafter “the Design”) to you for use in the development of designs to operate
on, or interface with Xilinx FPGAs. Except as stated herein, none of the Design may be copied, reproduced, distributed, republished,
downloaded, displayed, posted, or transmitted in any form or by any means including, but not limited to, electronic, mechanical,
photocopying, recording, or otherwise, without the prior written consent of Xilinx. Any unauthorized use of the Design may violate copyright
laws, trademark laws, the laws of privacy and publicity, and communications regulations and statutes.
Xilinx does not assume any liability arising out of the application or use of the Design; nor does Xilinx convey any license under its patents,
copyrights, or any rights of others. You are responsible for obtaining any rights you may require for your use or implementation of the
Design. Xilinx reserves the right to make changes, at any time, to the Design as deemed desirable in the sole discretion of Xilinx. Xilinx
assumes no obligation to correct any errors contained herein or to advise you of any correction if such be made. Xilinx will not assume any
liability for the accuracy or correctness of any engineering or technical support or assistance provided to you in connection with the Design.
THE DESIGN IS PROVIDED “AS IS” WITH ALL FAULTS, AND THE ENTIRE RISK AS TO ITS FUNCTION AND IMPLEMENTATION IS
WITH YOU. YOU ACKNOWLEDGE AND AGREE THAT YOU HAVE NOT RELIED ON ANY ORAL OR WRITTEN INFORMATION OR
ADVICE, WHETHER GIVEN BY XILINX, OR ITS AGENTS OR EMPLOYEES. XILINX MAKES NO OTHER WARRANTIES, WHETHER
EXPRESS, IMPLIED, OR STATUTORY, REGARDING THE DESIGN, INCLUDING ANY WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND NONINFRINGEMENT OF THIRD-PARTY RIGHTS.
IN NO EVENT WILL XILINX BE LIABLE FOR ANY CONSEQUENTIAL, INDIRECT, EXEMPLARY, SPECIAL, OR INCIDENTAL DAMAGES,
INCLUDING ANY LOST DATA AND LOST PROFITS, ARISING FROM OR RELATING TO YOUR USE OF THE DESIGN, EVEN IF YOU
HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. THE TOTAL CUMULATIVE LIABILITY OF XILINX IN CONNECTION
WITH YOUR USE OF THE DESIGN, WHETHER IN CONTRACT OR TORT OR OTHERWISE, WILL IN NO EVENT EXCEED THE
AMOUNT OF FEES PAID BY YOU TO XILINX HEREUNDER FOR USE OF THE DESIGN. YOU ACKNOWLEDGE THAT THE FEES, IF
ANY, REFLECT THE ALLOCATION OF RISK SET FORTH IN THIS AGREEMENT AND THAT XILINX WOULD NOT MAKE AVAILABLE
THE DESIGN TO YOU WITHOUT THESE LIMITATIONS OF LIABILITY.
The Design is not designed or intended for use in the development of on-line control equipment in hazardous environments requiring fail-
safe controls, such as in the operation of nuclear facilities, aircraft navigation or communications systems, air traffic control, life support, or
weapons systems (“High-Risk Applications”). Xilinx specifically disclaims any express or implied warranties of fitness for such High-Risk
Applications. You represent that use of the Design in such High-Risk Applications is fully at your risk.
© 2005 Xilinx, Inc. All rights reserved. XILINX, the Xilinx logo, and other designated brands included herein are trademarks of Xilinx, Inc. All
other trademarks are the property of their respective owners.
Programming. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388
Power-Up Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388
I/O Banking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
Mixed Voltage, Power Sequencing, and Hot Plugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
Development System Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
ATE Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
Preface
Acknowledgements
This book would not have been possible without the efforts and cooperation of several
applications engineers, and at least one FAE. I would like to thank them for their
contributions to the ideas, designs, and hard work performed in the creation of application
notes and white papers for the digital consumer marketplace. They are:
Additional appreciation goes to the Xilinx CPLD Marketing team for guidance and the
creation of collateral marketing material to support the efforts of the digital consumer
initiative. They are:
Additional Resources
To find additional documentation, see the Xilinx website at:
http://www.xilinx.com/literature/index.htm.
To search the Answer Database of silicon, software, and IP questions and answers, or to
create a technical support WebCase, see the Xilinx website at:
http://www.xilinx.com/support.
xii www.xilinx.com
June 26, 2006
R
Chapter 1
Chapter 1
R
IrDA and UART Design in a CoolRunner
CPLD
XAPP345 (v1.3) December 23, 2003
Summary This application note illustrates the implementation of an IrDA and UART system using a
CoolRunner™ CPLD. The fundamental building blocks required to create a half-duplex IrDA and
full-duplex UART interface design is described. The source code for this design is available and
can be found in the section HDL Code, page 11. This design fits an XC2C128 CoolRunner-II or
XCR3128XL CPLD.
Introduction IrDA devices provide a walk-up, point-to-point method of data transfer that is adaptable to a
broad range of computing and communicating devices. The first version of the IrDA
specification (version 1.0) provides communication at data rates up to 115.2 Kbps. Later
versions (version 1.1) extended the data rate to 4 Mbps, while maintaining backward
compatibility with version 1.0 interfaces. The protocol described in this application note is only
for 115.2 Kbps. The 4 Mbps interface uses a pulse position modulation scheme which sends
two bits per light pulse.
The IrDA standard contains three specifications. These relate to the Physical Layer, the Link
Access Protocol, and the Link Management Protocol. This document provides information on
the Physical Layer and does not provide a detailed explanation of the requirements for full IrDA
conformity. For more information on IrDA see "References" on page 12.
IrDA System Figure 1 illustrates the basic hardware building blocks for IrDA communication. The selection of
UART interface, RS232, and microcontroller or microprocessor, depends upon the
communication speed required. Data rates above 115.2 Kbps require a direct interface to the
address and data lines of the microprocessor or microcontroller. Data rates below 115.2 Kbps
can be implemented over a UART or RS232 port
Serial Out Infrared
UART Transmit
RS232 Modulation/
μP Demodulation
μC
Infrared
Serial In Receive
X345_01_080601
A UART interface is implemented in this design for data rates up to 115.2 Kbps. The IrDA
specification is intended for use with a serial communications controller such as a conventional
UART. The data is first encoded before being transmitted as IR pulses. As shown in Figure 2,
the serial encoding of the UART is NRZ (non return to zero) encoding. NRZ encoded outputs do
not transition during the bit period, and may remain High or Low for consecutive bit periods.
This is not an efficient method for IR data transmission with LEDs. To limit the power
consumption of the LED, IrDA requires pulsing the LED in a RZI (return to zero, inverted)
modulation scheme so that the peak power to average power ratio can be increased. IrDA
© 2002 Xilinx, Inc. All rights reserved. All Xilinx trademarks, registered trademarks, patents, and further disclaimers are as listed at http://www.xilinx.com/legal.htm. All other
trademarks and registered trademarks are the property of their respective owners. All specifications are subject to change without notice.
NOTICE OF DISCLAIMER: Xilinx is providing this design, code, or information "as is." By providing the design, code, or information as one possible implementation of this feature,
application, or standard, Xilinx makes no representation that this implementation is free from any claims of infringement. You are responsible for obtaining any rights you may
require for your implementation. Xilinx expressly disclaims any warranty whatsoever with respect to the adequacy of the implementation, including but not limited to any warranties
or representations that this implementation is free from claims of infringement and any implied warranties of merchantability or fitness for a particular purpose.
requires the maximum pulse width to be 3/16th of the bit period. A 16x clock is required, and
counting three clock cycles can easily be done to encode the transmitted data.
0 1 0 1 0 0 1 1 0 1
UART
TXD
(NRZ)
IR_TXD
(RZI)
Bit
Time
3/16
X345_02_080601
UART and IrDA Figure 3 illustrates the system architecture for implementing a UART serial port interface with
Design an IrDA module in a CoolRunner CPLD. The UART or a discrete device must provide a 16x
clock for the IrDA 3/16 modulation scheme.
UART IrDA
TXD
TRANSMIT IR_ENCODE IR_TXD
Parallel
Data
Byte
RCV
RECEIVE IR_DECODE IR_RCV
16XCLK X345_03_080601
The Verilog code provided in this design for the UART interface consists of two HDL modules,
TRANSMIT and RECEIVE. Data is written to the transmitter and data is read from the receiver
through an 8-bit parallel data bus.
The Verilog code provided in this design for the IrDA emulates the operation of the Agilent
Technologies HSDL-7000. The IrDA HSDL-7000 consists of logic for both encoding and
decoding the transmit and receive data. Each encode and decode operation is driven by the
clock, derived from the UART, or supplied from a discrete source. This clock must be initially
configured to cope with the IrDA specified startup data rate of 9.6 Kbps, then adjusted to 16
times the desired baud rate.
UART Interface Figure 4 illustrates the functionality of the UART interface. The data bus interface to the UART
module is 8-bits. Even or odd parity can be selected on the serial data out, SOUT.
UART
16XCLK RECEIVE
Hold Register
Shift Register
RESET
Mux
Parallel Control SIN
Data Byte Logic
Parity Error
READ
Hold Register
Shift Register
Overrun Error
WRITE
X345_04_080701
The serial data out, SOUT follows the format shown in Figure 5.
LSB MSB
write = '0'
ASSIGN
write = '1'
DATA_RDY
X345_06_080701
The second part of control logic for the UART transmitter is dividing the 16x clock to transmit
data at the desired baud rate. The transmit clock, TXCLK, is generated using a 3-bit counter
that increments on the rising edge of the 16x input clock. TXCLK controls when data changes
on the serial data output of the UART. Figure 7 illustrates this logic, TXCLK changes value
when the 3-bit counter is equal to zero.
reset = '1'
IDLE
cnt = 8 cnt = 0
X345_07_080701
The last main portion of the UART transmit logic is shifting out data on SOUT. Figure 8
illustrates the control logic to send data out according to the data format shown in Figure 5. The
START TRANSMIT logic sends the start signal out on SOUT. The SHIFT OUT logic shifts the
transmit shift register and sends data out on SOUT. When the paritycycle signal is asserted, the
parity bit is transmitted. Once the data and parity has been transmitted, the done bit is sent by
the STOP OUT logic.
reset = '1'
START
TRANSMIT
txdone = '0' or
txdatardy = '0'
paritycycle = '1'
PARITY
OUT
txdone = '1'
STOP
OUT
X345_08_080701
stream. The start bit is indicated by an active Low signal for eight clock cycles after a falling
edge on SIN.
reset = '1'
rxclk = '1'
SHIFT IN
DATA
GENERATE
PARITY
Stop Bit
No Detected
?
Yes
SET ERROR
FLAGS
X345_09_080701
A falling edge on SIN is read by the DETECT EDGE logic as shown in Figure 9. To receive data,
the receive clock must be centered on the low leading start bit. The receive clock, RXCLK is
generated by dividing the 16x clock using a 4-bit counter.
Once a valid start bit is detected, the data is sampled on SIN at each RXCLK rising edge. The
receive shift register is shifted with the incoming SIN data. Running parity is generated with
each incoming data bit. When a stop bit is detected, any error flags are set. This includes parity,
overrun, and framing error flags.
A main function of the UART receive logic is interfacing with the processor. The CPLD detects
a valid edge on the READ signal asserted by the processor. The CPLD then places the
received parallel data on the system data bus.
IrDA Interface Figure 10 illustrates the input and output requirements of the IrDA module in this design. RXD
and TXD are the serial connections to the UART SIN and SOUT data lines respectively. IRRXD
and TXRXD are the IrDA 3/16th pulse signals that are fed into the LED driver/receiver circuitry
as shown in Figure 10.
IRTXD
TXD
IR Module LED
RXD (HSDL-7000) LED Driver
16XCLK
IRRXD
PIN
Post Pre-
Amplifier Amplifier
X345_10_080701
The encoding scheme shown in Figure 2 sends a pulse for every space or "0" that is sent on the
TXD line. On a High-to-Low transition of the TXD line, the generation of the pulse is delayed for
seven clock cycles of the 16XCLK before the pulse is set High for three clock cycles (or 3/16th
of a bit time) and then subsequently pulled low.
The decoding scheme shown in Figure 11 seeks a High-to-Low transition of the IRRXD line
which signifies a 3/16th pulse. This pulse is stretched to accommodate one bit time (16 clock
cycles). Every pulse that is received is translated into a "0" on the RXD line equal to one bit
period.
16
Clock
Cycles
16XCLK
IRRXD
3/16
RXD
1 0 1 1 1 0 1 1
CoolRunner The UART and IrDA design was implemented in Verilog as described above. Xilinx Project
Implementation Navigator was used for compilation, fitting, and simulation of the design in a CoolRunner CPLD.
Xilinx Project Navigator, which includes the ModelTech simulation tool, is available free-of-
charge from the Xilinx website at www.xilinx.com/products/software/webpowered.htm. The
design was targeted for a 3.3V, 128 macrocell CoolRunner XPLA3 CPLD (XCR3128XL-
VQ100). The UART and IrDA design utilization is shown in Table 1. These utilizations were
Ir DA an d UA RT D es ig n in a C o o lR u n n er C PL D
achieved using certain fitting parameters, actual results may vary. As shown, there is area
remaining in the CPLD for the implementation of other logic in the system.
The Verilog IrDA design can also be targeted as a stand alone module in a 3.3V 32-macrocell
CoolRunner XPLA3 CPLD (XCR3032XL). CPLD utilization for implementing the IrDA design is
shown in Table 2.
Design Verification
The UART/IrDA transmit and receive Verilog design verification has been done through
simulation using ModelSim XE in Project Navigator. The design has been verified both
functionally and with the timing model generated when fitting in a CoolRunner CPLD. The
implemented test bench drove the data, control, and timing necessary to test a transmit
operation from the UART to the IrDA output and test the received data from the IrDA and UART
modules. Implementation in an actual system may require modification of the control signals
used in the source code and test benches provided.
ModelSim Implementation
Notes:
Please refer to XAPP338: Using Xilinx WebPack and ModelTech ModelSim Xilinx Edition as a guide
to using ModelSim with Project Navigator. The ModelSim Quick Start demo provides a good first step
for getting familiar with ModelSim.
Figure 12 illustrates the test environment for transmitting a data byte using the UART and IrDA
modules. Upon receiving an active WRITE signal, the UART TXRDY signal is asserted. Data is
sent to the UART module and transmitted as shown on the SOUT signal. TXCLK is the internal
divided clock signal for the UART module. IRTXD is the data transmitted from the IrDA module.
The IR transmitted data is in the form as shown in Figure 2 and includes the start bit, eight data
bits, a parity bit, and a stop bit in each data transmission.
Figure 13 illustrates receiving data on the IrDA IRRXD input and presenting the parallel data
byte from the UART to the system. The IrDA receive module recognizes the format of incoming
data and sends the translated serial stream to the UART, as illustrated in Figure 11 on the SIN
signal. The UART module shifts the incoming serial data into a holding register. Upon the UART
receiving an active READ signal, the UART places the parallel data onto the data bus.
HDL Code THIRD PARTIES MAY HAVE PATENTS ON IRDA. BY PROVIDING THIS HDL CODE AS ONE
POSSIBLE IMPLEMENTATION OF THIS DESIGN, XILINX IS MAKING NO
REPRESENTATION THAT THE PROVIDED IMPLEMENTATION OF THIS DESIGN IS FREE
FROM ANY CLAIMS OF INFRINGEMENT BY ANY THIRD PARTY. XILINX EXPRESSLY
DISCLAIMS ANY WARRANTY OR CONDITIONS, EXPRESS, IMPLIED, STATUTORY OR
OTHERWISE, AND XILINX SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF
MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR A PARTICULAR PURPOSE,
THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY
WARRANTY OR REPRESENTATION THAT THE IMPLEMENTATION IS FREE FROM
CLAIMS OF ANY THIRD PARTY. FURTHERMORE, XILINX IS PROVIDING THIS
REFERENCE DESIGNS "AS IS" AS A COURTESY TO YOU.
XAPP345 - http://www.xilinx.com/products/xaw/coolvhdlq.htm
Conclusion IrDA is a low cost, walk-up, point-to-point method of IR communication protocol used in
applications ranging from laptops to phones to fax machines. This design is an example
implementation of an IrDA interface for data ranges less than 115.2 Kbps connected to a UART
interface. Version 1.1 extends the IrDA specification to 4 Mbps and can be implemented using
pulse position modulation.
Revision The following table shows the revision history for this document.
History
Date Version Revision
08/08/01 1.0 Initial Xilinx release.
09/30/02 1.1 Minor edits.
05/15/03 1.2 Minor corrections.
12/23/03 1.3 Updated links.
R
Serial ADC Interface Using a CoolRunner
CPLD
XAPP355 (v1.1) January 3, 2002
Summary This document describes the design implementation for controlling a Texas Instruments
ADS7870 Analog to Digital Converter (ADC) in a Xilinx CoolRunner™ XPLA3™ CPLD.
CoolRunner CPLDs are the lowest power CPLDs available and the ideal target device for
controlling a serial ADC in a portable handheld application. This document provides an
explanation of the VHDL code for the CoolRunner CPLD.
All related source code is provided for download. To obtain the VHDL code described in this
document, go to section VHDL Code Download, page 39 for instructions.
Overview Figure 1 illustrates the high-level block diagram for the data aquisiton system. The system
includes an XPLA3 CoolRunner CPLD, a Texas Instruments ADS7870 ADC, and a Toshiba
SRAM. The Texas Instrument ADS7870 ADC is initialized and controlled by the CoolRunner
CPLD. The CoolRunner CPLD takes conversion data from the ADC and writes the data to
SRAM. The SRAM used in the Insight Handspring Springboard development board is a 4 Mbit
Toshiba SRAM, TC55V400AFT. The Toshiba SRAM is a 16-bit word size SRAM, and is used for
storing data in a conversion cycle. Once conversion data is written into SRAM, the CoolRunner
CPLD allows the system processor to access the data.
Control
Data
Toshiba
4Mbit SRAM
© 2002 Xilinx, Inc. All rights reserved. All Xilinx trademarks, registered trademarks, patents, and disclaimers are as listed at http://www.xilinx.com/legal.htm.
All other trademarks and registered trademarks are the property of their respective owners. All specifications are subject to change without notice.
Usage The VHDL code distributed with this document is designed such that minimal knowledge of
VHDL language is required. A designated "constants" section of the VHDL code can be edited
to specify various aspects of the ADS7870 which include:
• Initialization of internal registers
• Specification of the number of conversions for any (or all) of the eight single-ended
channels
• Specification of SRAM locations where conversion results should be written
Designers who do not wish to understand the VHDL code in detail can simply edit this
designated VHDL "constants" section, compile the design and program the CoolRunner CPLD.
For more information, refer to section High Level Control Logic, page 18.
The following sections will detail the ADS7870 interface for those who wish to understand the
VHDL implementation of the CPLD ADC interface.
For a complete Handspring design example, refer to "XAPP146: Designing an 8 Channel
Digital Volt Meter with the Insight Springboard Kit".
TI ADS7870 Introduction
The ADS7870 ADC is a low power 12-bit, serial, 8-channel analog to digital converter. The
ADS7870 ADC is ideal for portable and handheld applications. The ADS7870 contains an
integrated PGA (Programmable Gain Amplifier) as well as a 2.5 MHz clock source (CCLK) that
is used internally and can be divided for conversion cycles. The CCLK can be configured as an
output for use with multiple ADCs and other system devices. The CoolRunner CPLD uses the
CCLK from the ADC as its system clock.
The information presented in this section is provided for convenience. For more information on
the Texas Instruments ADC, see References, page 38.
Figure 2 shows a detailed block diagram of the ADS7870.
ADS7870
BUF
Clock CCLK
REF Divider
Oscillator OSC ENABLE
Analog
Inputs + BUSY
MUX PGA 12-Bit
A/D
- CONVERT
8 Ch
(4 Ch Diff.) RESET
RISE/FALL
CS
I/O 0
I/O 1 Registers Serial SCLK
Digital and
I/O 2 I/O Interface DIN
Control
I/O 3
DOUT
X9499
Functional Description
Each functional block shown in Figure 2 in the ADS7870 is described in detail in Table 1.
ADS7870 Interface
The ADS7870 has four conventional serial interface pins: SCLK (serial data clock), DOUT
(serial data out), DIN (serial data in), and CS (chip select function) as shown in Figure 3. A wide
variety of microcontrollers can interface to this conventional serial port.
SCLK
In this particular design, the CoolRunner CPLD is used to handle the serial interface. The
condition of the SCLK pin (active level logic "1" or logic "0") is explicitly controlled. The ADC is
configured to latch data on the active edge of SCLK by holding a logic "1" to the RISE/FALL*
pin. Thus, the ADC interface ensures that data is available on the DIN pin when SCLK is "0" and
holds it when SCLK is "1". Figure 4 illustrates this timing.
SCLK
Register Mode
In register mode, the first eight bits transmitted to the ADC specify the address of a particular
register, whether to perform a read or a write operation and whether the data will be sixteen bits
or eight bits. Immediately after these eight bits are sent, eight or 16 more bits (depending upon
what was specified) are sent or received. For a write, data is sent through DIN. For a read, data
will appear on the DOUT pin. For a complete list of available registers please refer to the
ADS7870 datasheet. The VHDL code in this design allows the user to customize the register
usage.
CS must remain Low in order to activate the serial interface. Once CS is brought Low, an
internal counter residing in the ADS7870 begins counting the number of active SCLK edges.
Raising the CS pin will put the DOUT pin in high impedance and will resynchronize the internal
counter. It is possible to keep CS Low throughout an entire chain of serial commands (i.e., write
to all address registers), but doing so will require careful management of the serial interface
pins. One must be extremely careful when attempting to do so, as one error will cascade
throughout the entire sequence.
Therefore, in this design, and in future designs, the CoolRunner CPLD briefly pulls the CS pin
High after the completion of every serial command. This ensures that errors will not cascade.
Direct Mode
A conversion can be initiated on the ADS7870 by issuing a direct mode command. In this
mode, a single 8-bit instruction byte is sent. The direct mode command will specify the input
channel and the PGA gain. Immediately after this 8-bit instruction is sent, the ADS7870 will
perform a conversion on the specified channel, with the specified PGA gain. The results will be
written to Registers 0 and 1 and can be retrieved using a register mode read. However, in this
design, the ADC is configured to use Read Back Mode 1. In this mode, the conversion result
will automatically clock out on the next active edge of SCLK, after the last bit of the direct mode
command is sent. Configuring the ADS7870 for Read Back Mode 1 will increase throughput
since a separate read instruction is not required to read the result in registers 0 and 1.
the CPLD initializes the ADC, it sends multiple "direct mode" instructions to initiate consecutive
conversion cycles. The 12-bit serial data in a conversion cycle is read in by the CPLD and
deserialized for a 16-bit word write to SRAM.
Figure 5 illustrates at a high level the operational flow for the ADC interface. The CPLD must
initialize the ADS7870 registers that are pertinent to the design. This includes specifying each
address register and the corresponding data to write. The CPLD then initializes the ADC for
performing a "direct mode" conversion cycle for a specific input channel. The CPLD must send
the direct mode command before reading out the ADC conversion data. The CPLD brings in the
serial data and presents the deserialized data word to SRAM. The CPLD continues to issue the
same direct mode command while reading the same input channel on the ADC. To read
another input channel on the ADC a different direct mode instruction must be sent. The direct
mode instruction includes control bits to specify the input channel on the ADC.
START
Write to necessary
ADC register
More
Yes Registers
?
No
More
Yes Channels
?
No
END
X355_05_080801
IDLE
Register Mode
Assert go_shift <= "1" WRITE_ADDR
& mode_flag = "0"
shift_done = "1"
shift_done = "1"
More
Registers Yes
?
No
Direct Mode
shift_done = "1"
shift_done = "1"
More
Conversion
Cycles? No
Yes
DONE
X355_06_080801
Table 2 describes the functionality of each state in the MAIN state machine control logic shown
in Figure 6. Note the mode_flag = "0" for the SHIFT control logic to designate the shift size for
data. When mode_flag = "0", an 8-bit data value is shifted out. This is either a register address,
data to write to an address register, or the direct mode command. When mode_flag = "1", a
16-bit data value is shifted in from the ADC. This is for capturing the conversion data which
consists of 12 bits of data, three zero bits, and the overflow bit.
Register Mode
The MAIN state machine continues to remain in the register mode, for initialization, until all
registers have been set up and written to. The VHDL code enables the user to specify which
registers to write to and the data to write to each register. The following VHDL code illustrates
how to specify a write to ADDR3 in the ADC interface VHDL code.
-- Data to be written
constant DATA_WR_ADDR3: STD_LOGIC_VECTOR(7 downto 0) := ’00000100’;
Note the variable WR_ADDR3_EN can be set to either TRUE or FALSE, enabling or disabling
a write to ADDR3. If WR_ADDR3_EN is set to TRUE, then the data to write to that register must
also be specified. This is done in the DATA_WR_ADDR3 constant. In this example, we are
writing "0000 0100" to ADDR3, which specifies Read Back Mode 1 (MSB read back first) and
sets CCLK division factor = 1. For more information on the data that can be written to each
register, refer to References, page 38.
When writing to a register, not only is the register address specified, but additionally a read or
write operation and the data word size can be specified.
The data written to the control registers allows the ADC to set up features such as: reading
MSB or LSB first, the division factor of CCLK, PGA gain for a specific input channel, enabling
the use of the digital I/O, and many more features that can be found in the ADC data sheet.
Direct Mode
Once all the control registers have been initialized in the ADC in the register mode, the ADC
can now operate in the direct mode. The direct mode allows the external ADC controller to
specify the input channel and read the conversion data. The VHDL code in this design has
been constructed to ease the implementation for any application. The VHDL code enables the
designer to specify which input channels to read from and how many conversions are
requested on each input. The VHDL code for enabling/disabling register mode conversions is
similar to the set up for register mode initialization. The following VHDL code illustrates how to
perform eight conversions from the ADC single-ended input channel 0 and read eight
conversions from the ADC single-ended input channel 1.
The number of conversions in this particular example is controlled by counting each conversion
write to SRAM. Therefore, once the address counter for the SRAM reaches the SRAM_HIGH
offset, the specified number of conversions are counted. To enable a conversion from a specific
input channel, the VHDL constant DM_SNG_LN0_EN set to TRUE will enable multiple
conversions from LN0 in the ADC. Note that for only reading from one single-ended input
channel, all other input channel enable constants must be set to FALSE. The constant
DM_SNG_LN0 stores the value to send a direct mode command for a conversion on LN0.
Refer to the ADS7870 data sheet for more information on sending a direct mode command.
go_shift = "1"
SC0
(CNT<8 & mode_flag = "0") or
(CNT<16 & mode_flag = "1")
shift_done <= "1" SC1
The SHIFT state machine is responsible for generating the shift clock, SCLK, and setting up the
appropriate data to send out. As previously described, the data to send must be on the DIN line
before the active edge of SCLK. In the SHIFT state machine, the data register holding the word
to send is enabled in the SC0 state (SCLK = "0"). Then in the SC1 state, SCLK = "1" and the
data bit is shifted out on DIN.
During a direct mode conversion cycle, the SHIFT state machine controls SCLK. The SHIFT
state machine reads in data on the DOUT line at the active edge of SCLK, in the SC1 state.
For more information on implementing these state machines to initialize and read conversion
data from the ADC, see section Hardware Implementation, page 28.
Allowing the After conversion results have been written to SRAM, the Handspring Visor must be given
Visor to Read access to read the conversion result from SRAM. This transfer of control occurs once the MAIN
state machine has written all conversion results to SRAM. This is specified in the DONE state
Conversion of the MAIN state machine.
Results This section will detail how the CoolRunner CPLD releases control of the bus to the Handspring
Visor.
On the Insight Springboard Development Kit, all address, data and control signals originating
from the Springboard expansion area are routed into the CoolRunner CPLD. These signals are
then internally routed to a brand new set of pins, which are then externally connected to the
SRAM, A/D, and Flash. XAPP147: "Low Power Handspring Springboard Module Design
with CoolRunner CPLDs", illustrates this routing scheme. In the most basic case, the
CoolRunner would simply act as a buffer for all signals, all signals would go directly into and
then out of the CPLD, without being manipulated.
In this case, however, the functionality of the CoolRunner has increased because it has the
added task of controlling the ADS7870. The CoolRunner must allow both the Visor and the A/D
to be able to write (and read) to SRAM. Therefore, the simple interface shown in XAPP147
must be slightly modified to include multiplexers. These multiplexers are controlled by the
ADS7870 interface. When the interface is active, the multiplexers allow for the CPLD to write
conversion results to SRAM. When conversions are finished, the Visor is allowed to read these
conversions from SRAM, or alternately write new values to SRAM.
Data[15:0]
Figure 8 below shows the functionality that would allow for data to be passed to/from the Visor,
through the CoolRunner CPLD.
In Figure 8, “SP_D[15:0]” is the name given to the data lines originating from the Visor.
"D[15:0]” is the name of the buffered signal. These buffered data lines are routed to the data
lines of the SRAM and Flash.
A multiplexer is inserted between the input buffer of “SP_D[15:0]” and the output buffer for
“D[15:0]”. The multiplexer’s inputs are “SRAM_Write_Data” and “AD_DATA”.
SRAM_Write_Data is a 16-bit signal that represents the data value present on the Springboard
Data lines. AD_DATA, is a-16 bit signal that is output from the A/D Interface. AD_DATA is the
value of a conversion result.
Mux_Sel, the select line for the multiplexer, controls which of the two inputs will be potentially
applied to SRAM and/or Flash. The output value of the multiplexer is not guaranteed to be
applied since the output of the MUX is tied to the input of a tri-state buffer. Therefore, the value
of the tri-state control signal, “SRAM_Write_Enable” will determine if data will be output.
When Mux_Sel is "0" the Handspring Visor will have control of the data lines. Alternately, when
Mux_Sel is "1", the A/D Interface is allowed to write data to SRAM. The A/D Interface controls
the value of Mux_Sel so that when it is active, the value of Mux_Sel will be "1" and when it is
complete, the value will be set to "0".
SRAM_Write_Enable is a tri-state control signal that determines if the “D[15:0]” pins will
function as an input or as an output. D[15:0] will function as outputs if the value of
SRAM_Write_Enable is a "1". On the other hand, the D[15:0] pins will be inputs if the tri-state
control signal is "0".
The SRAM_Write_Enable equation is equal to:
(SM_WE) + (SM_WE) & [ WE & (CS0 + CS1) ]
Table 3 describes each literal in the SRAM_Write_Enable equation.
In the SRAM_Write_Enable equation, the SM_WE literal is generated by the A/D Interface.
SM_WE is declared to be "1" when the A/D interface is running, thereby making the entire
equation equal to "1". This enables the output buffer and since MUX_Sel is "1" when the A/D
Interface is active, the A/D conversion results can be written to SRAM.
When the conversions are complete, the A/D Interface declares SM_WE to be "0" and Mux_Sel
to be "0" so that the Handspring can either read the conversion results stored in SRAM or write
new data to SRAM.
Once the Visor is given control of the bus (i.e., SM_WE becomes "0"), the Visor can enable the
output buffer by executing a write to SRAM. A write operation to an address between
0x29000000 and 0x29FFFFFF (the default memory mapped region for CS1) will cause CS1
and WE to become "0", making the SRAM_Write_Enable equation true.
If needed, the Visor may also write to the Flash memory region that corresponds to CS0
(address 0x28000000 to 0x28FFFFFF). Doing this will create a falling edge on CS0 and WE.
The Visor can retrieve contents in SRAM by executing a read operation. Once again, an output
buffer will determine if the SP_D[15:0] pins will provide data to the Visor or if these pins will
send data to external components. This output buffer is controlled by the SRAM_Read_Enable
signal.
The equation for SRAM_Read_Enable is equal to:
OE & (CS0 + CS1)
If the Visor executes a read operation from SRAM, the CS1 and OE signals will go Low. The
SP_D[15:0] pins will then be allowed to output data to the Visor.
Address Lines
The address lines originating from the Springboard Expansion Connector, “SP_A[23:1]”, are
routed through the CoolRunner. The SP_A[23:1] pins are connected internally to one input of
the address multiplexer, as shown in Figure 9. This Multiplexer has two inputs, one of which is
SP_A[23:1] and the other which is ADDR_COUNT. MUX_SEL, the same select signal for the
other multiplexers in this design, is used for the select line of this multiplexer.
A[23:1] is the output of this switch. This output bus is tied to external pins which are then routed
to the address lines of Flash and SRAM. Figure 9 illustrates this.
When the A/D Interface is active, MUX_SEL is set to "1". This allows the value of
SM_ADDRESS to determine the value of A[23:1].
The VHDL signal SM_ADDRESS is assigned for each write to SRAM. The value of
SM_ADDRESS is initialized for a specific input channel as specified in the VHDL "constants"
section discussed in section, Direct Mode, page 22. This address counter, SM_ADDRESS is
increment for each subsequent write to SRAM. The ADC will stop reading from the current
input channel once the SM_ADDRESS counter reaches the max address space for the current
input channel.
The Digital Volt Meter design shown in Hardware Implementation, page 28 writes to address
locations 0, 1, and 2 of SRAM for the ADC input channel 0.
23
SP_A[23:1] 0 23
23 A[23:1]
SM_ADDRESS 1
MUX_SEL
Figure 9: Address MUX
Chip Select 1
Figure 10 shows the Chip Select 1 multiplexer. A switch is needed in order to give the A/D
Interface the ability to control the CS pin of the SRAM. The SRAM CS pin is an active Low
signal that enables the SRAM chip. When CS is Low and RW (Write Enable) is Low, data will be
written to SRAM. When CS is Low and OE (Output Enable) is Low, the SRAM will output data
so a read operation can occur.
SPRING_CHIP1_ENn is the CS1 pin originating from the Visor’s expansion area.
STATE_MACHINE_SRAM_ENn is an internal signal that is controlled by the A/D Interface. The
SRAM_CHIP1_ENn signal is externally routed to the CS pin of the SRAM.
When the A/D Interface is active, MUX_SEL is "1" and hence the value of
STATE_MACHINE_SRAM_EN determines the value of the CS pin on the SRAM. When the A/D
Interface writes a conversion result to SRAM, it pulls the STATE_MACHINE_SRAM_EN signal
and the STATE_MACHINE_WE (see next page) signal Low.
After the conversions are complete, MUX_SEL is set to "0" and the Handspring Visor can once
again perform its own read and write operations.
SPRING_CHIP1_ENn 0
SRAM_CHIP1_ENn
STATE_MACHINE_SRAM_ENn 1
MUX_SEL
X9504
Write Enable
Figure 11 shows the Write Enable Multiplexer. This multiplexer is needed in order to give the
A/D Interface the ability to control the RW (Write Enable) pin of SRAM. The RW pin is an active
low signal that, when used in conjunction with the CS pin, will enable a write operation to occur.
SPRING_WRITE_ENn is the Write Enable pin originating from the Visor’s expansion area.
STATE_MACHINE_WE is an internal signal that is controlled by the A/D Interface. The output
of the multiplexer, READ_WRITEn is externally routed to the RW pin of the SRAM.
When the A/D Interface is active, MUX_SEL is "1" and the value of STATE_MACHINE_WE will
determine the value of the SRAM RW pin. When the A/D Interface writes a conversion result to
SRAM, it pulls the STATE_MACHINE_WE signal Low and the STATE_MACHINE_SRAM_ENn
signal low. (See Chip Select 1, page 26 for an explanation of the
STATE_MACHINE_SRAM_ENn signal.
After the conversions are complete, MUX_SEL is set to "0" and the Handspring Visor can once
again perform its own read and write operations.
SPRING_WRITE_ENn 0
READ_WRITEn
STATE_MACHINE_WE 1
MUX_SEL
X9505
Output Enable
Figure 12 shows the Output Enable multiplexer. This multiplexer is needed in order to give the
A/D Interface the ability to control the OE (Output Enable) pin of SRAM. The OE pin is an active
low signal that, when used in conjunction with the CS pin, will allow a read operation to occur.
SPRING_OUTPUT_ENn is the Output Enable pin originating from the Visor’s expansion area.
STATE_MACHINE_OE is an internal signal that is controlled by the A/D Interface. The output of
the multiplexer, OUTPUT_ENn is externally routed to the OE pin of the SRAM.
When the A/D Interface is active, MUX_SEL is "1" and the value of STATE_MACHINE_OE will
determine the value of the SRAM OE pin. When the A/D Interface writes a conversion result to
SRAM, it pulls the STATE_MACHINE_OE signal Low and the STATE_MACHINE_SRAM_ENn
signal Low. (See previous page for an explanation of the STATE_MACHINE_SRAM_ENn
signal.)
After the conversions are complete, MUX_SEL is set to "0" and the Handspring Visor can once
again perform its own read and write operations.
SPRING_OUTPUT_ENn 0
OUTPUT_ENn
STATE_MACHINE_OE 1
MUX_SEL
X9506
-- Data to be written
constant DATA_WR_ADDR3: STD_LOGIC_VECTOR(7 downto 0) := ’00000100’;
-- Data to be written
constant DATA_WR_ADDR4: STD_LOGIC_VECTOR(7 downto 0) := ’00000000’;
-- Data to be written
constant DATA_WR_ADDR5: STD_LOGIC_VECTOR(7 downto 0) := ’00000101’;
-- ID Register
constant ADDR31 : STD_LOGIC_VECTOR(7 downto 0) := ’00011111’;
wait state to resynchronize the serial interface. In this wait state, SCLK remains Low, and CS
is momentarily raised High. Figure 13 shows a logic analyzer trace of this sequence.
mode. Sixteen more SCLK cycles and a wait state are needed, and a logic analyzer trace of this
sequence is shown in Figure 16.
In reality, when we are chaining several conversions together, the CoolRunner does not need to
monitor the BUSY pin. BUSY is shown just to confirm that a conversion is taking place.
the result of the first conversion. The result of this second conversion is returned in the next
frame as shown in Figure 18. .
Within the frame of this example, DOUT reads “0000 1001 1011 0000”. Since the ADS7870 is
set for Read Back Mode 1, the MS Byte of the conversion result is returned first. In other words,
ADDR1 will clock out first, followed by ADDR0. (The Texas Instruments ADS7870 datasheet
provides details of ADDR1 and ADDR0).
The 12-bit output code in this example is “0000 1001 1011”. This is equal to +155. The
corresponding measured voltage would then equal:
(155 / 2047) * 2.5 = 0.189 Volts
It may also be of interest to see that this second direct mode command was issued when the
first conversion was still in progress (Note the BUSY pin). The ADS7870 places this next
conversion in queue and allows the current conversion to finish. Maximum throughput is
obtained through this method, as the next conversion will begin immediately after the previous
one finished. Again, note how the BUSY pin goes low then high during the conversion cycle.
Note, only three direct mode conversion cycles are shown for single ended input channel LN0.
The implemented design allows for eight direct mode conversion cycles on each input channel
of the ADC.
Conclusion The ADS7870 interface presented in this document is an easy to use reference design that will
allow for quick customizing of the Insight Springboard Development Card. Regardless of
whether a designer understands the VHDL language, the designated "constants" section of the
VHDL code can be modified to configure the ADS7870 in a way that best complements a
specific Springboard design. After modification, simply implement the design and program the
CoolRunner CPLD. The inherent low power characteristics of the CoolRunner CPLD will come
at no cost, and users will recognize the advantages of programmable logic.
VHDL Code VHDL source code and test benches are available for this design. THE DESIGN IS PROVIDED
Download TO YOU "AS IS". XILINX MAKES AND YOU RECEIVE NO WARRANTIES OR CONDITIONS,
EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, AND XILINX SPECIFICALLY
DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT,
OR FITNESS FOR A PARTICULAR PURPOSE. While this design has been verified on
hardware, it should be used only as an example design, not as a fully functional core. XILINX
does not warrant the performance, functionality, or operation of this design will meet your
requirements, or that the operation of the design will be uninterrupted or error free, or that
defects in the design will be corrected. Furthermore, XILINX does not warrant or make any
representations regarding use or the results of the use of the design in terms of correctness,
accuracy, reliability or otherwise.
XAPP355 - http://www.xilinx.com/products/xaw/coolvhdlq.htm
Revision The following table shows the revision history for this document.
History
Date Version Revision
09/25/01 1.0 Initial Xilinx release.
01/03/02 1.1 Minor revisions.
R
Wireless Transceiver for the CoolRunner
CPLD
XAPP358 (v1.0) June 25, 2001
Summary This document focuses on the design of a wireless transceiver using an XPLA3™
CoolRunner™ CPLD. The wireless transceiver is implemented using the CoolRunner XPLA3
demo board from Insight Electronics. The wireless transceiver is the perfect application of the
low power capabilities of a CoolRunner CPLD. To obtain the VHDL code described below go to
the section titled “VHDL Disclaimer and Download Instructions” on page 11.
Introduction A wireless transceiver consists of two modules; receive, and transmit. One CoolRunner demo
board comprises the receive portion while the second demo board comprises the transmit
portion. The design transmits the text string "CooLrunnEr," which is displayed on both the
transmit and receive demo boards. The wireless communication is controlled by an RF module
designed by RF Monothilics, Inc. (RFM®).
The protocol designed for the wireless transceiver obeys a custom wireless communication
protocol. A designer could change the protocol has needed to meet the needs of a specific
application.
The addition of keyboard control is also covered in this document. The VHDL code is not
provided for this portion of the design. With keyboard control, a user can enter a text string into
the transmitter and the string would be display on the receive side of the transceiver. The
keyboard described is manufactured by Fujitsu Takamisawa America, Inc. (FBK7603)
(www. fujitsu.takmisawa.com/pdf/EvalKits.pdf).
CoolRunner This section describes the operation of the transceiver. The communication protocol is a
CPLD custom transmit and receive scheme, using Manchester encoding and Bit-Oriented Protocol
(BOP) theory.
Transceiver
Operation Communication Protocol
The communication protocol is show in Figure 2. The preamble and postamble are used to
contain the data to be transmitted. The total transmission is 36 bits. For error checking, the data
is transmitted four times and compared to insure the proper data was received.
© 2001 Xilinx, Inc. All rights reserved. All Xilinx trademarks, registered trademarks, patents, and disclaimers are as listed at http://www.xilinx.com/legal.htm.
All other trademarks and registered trademarks are the property of their respective owners. All specifications are subject to change without notice.
Data [11:0]
PREAMBLE POSTAMBLE
LSB
010101010101 111100001111
Start Flag [11:0] End Flag [11:0]
X358_02_062001
Transmit
A Manchester encoding scheme is used between the transmit and receive modules.
Manchester coding ensures that each bit of the data is D.C. balanced. Also, this coding scheme
provides an edge within each bit period that can be used to align the receiver’s clock if needed.
However, Manchester coding requires twice the bandwidth as compared to NRZ (Non-Return-
to-Zero) codes. To decrease bandwidth, a symbol table is used. It consist of sixteen different
symbols that can be generated using six bits which guarantees that no more than four
consecutive bits are the same. This scheme requires only 1.5 times the bandwidth when
compared with NRZ coding. For more information on Manchester and NRZ coding schemes,
refer to the application note XAPP339 “Manchester Encoder-Decoder for Xilinx CPLDs”
(http://www.xilinx.com/xapp/xapp339.pdf).
Receive
BOP is utilized on the receive side of the transceiver. BOP takes advantage of opening and
closing flag insertion and deletion and zero bit insertion and deletion. Once an edge is
detected, the incoming data is sampled and stored in a shift register. Once the most significant
bits are equal to the postamble, the 12-bit data is stored in a register. This process occurs four
times. This insures the data has time to be displayed on the LCD of the CPLD demo board and
allows for more accurate error checking.
CoolRunner Transmit
CPLD The transmit block diagram is shown in Figure 3. Transmission comprises of three VHDL
Transceiver entities; DISPLAY_COUNT, SHIFT_ENABLE, and SHIFT_OUT. These three logic modules are
controlled by the top level module, TX_MODULE. DISPLAY_COUNT controls the LCD
Block Diagram common line, LCDCOM, which minimizes charging in the LCD. DISPLAY_COUNT also
controls the time between display states. Each state determines which two digits are displayed
on the LCD. It pulses the SWITCH_EN_H signal when it is time to change to the next state. This
control line tells the SHIFT_ENABLE module to output the next state number, CUR_STATE, to
the CHANGE_STATE look up table. When this is completed, it pulses the LOAD_DATA_H
signal to tell the SHIFT_OUT module to load the current state data, CUR_STATE_DATA, output
by the CHANGE_STATE look up table. This module also keeps track of how many
transmissions have been sent. It pulses the LOAD_DATA_H signal four times for each state,
controlling the time between transmissions. The data is sent four times to provide error
checking on the receive side (See Receive). When SHIFT_OUT observes that LOAD_DATA_H
has been pulsed, it loads the current state data, and begins to send the data, with a preamble
and postamble, one bit at a time, to the RF module.
The CONTROL signal is controlled by the TX MODULE which enables the RF MODULE to be
in transmit mode. SYS_CLK_H and SYS_RST_L are external signals that are used as the
system clock and the global system reset.
LCD
LCDCOM
DIGIT1 [8:0] DIGIT2 [8:0]
TX MODULE
SYS_CLK_H
SYS_RST_L SWITCH_EN_H
DISPLAY_COUNT SHIFT_ENABLE
LOAD_DATA_H CUR_STATE
[8:0]
CUR_STATE_DATA
DISPLAY_COUNT CHANGE_STATE
[8:0]
CONTROL
TX
RF MODULE
X358_03_062001
Receive
The receive block diagram is shown in Figure 4. The data is read on the RX pin and shifted into
a 3-bit shift register, RXIN, on every clock cycle. When an edge is detected (a logic 1) in the
least significant bits of RXIN, a counter is enabled. This counter counts to approximately 3/4 of
the bit period (due to non-ideal conditions, see Figure 5), samples the data, and shifts the bit
into a 36-bit data register, SHIFT_DATA (see Figure 10). If there are consecutive bits in the
stream, the counter continues to count 3/4 into the next bit period and samples the data again.
If there is another edge detected, it restarts the counter, to keep the possibility of error due to
drift to a minimum. Once the postamble is seen in the most significant 12 bits of the 36-bit shift
register, the 12 bits of data are stored into a temporary register, REG1 through REG4, and the
module gets ready for the next transmission. After the fourth transmission, if any two of the
temporary registers are equal, the data is symbolized using the RX_SYMBOLIZE function, and
the data is sent to the LCD.
LCDCOM minimizes charging in the LCD. The CONTROL signal is controlled by the receive
MODULE which enables the RF MODULE to be in receive mode. SYS_CLK_H and
SYS_RST_L are external signals that are used as the system clock and the global system
reset.
LCD
LCDCOM
DIGIT1 [8:0] DIGIT2 [8:0]
RX MODULE
SYS_CLK_H
REG1 [12:0]
SYS_RST_L REG2 [12:0]
CHANGE_STATE
REG3 [12:0]
REG4 [12:0]
SHIFT_DATA [35:0]
RXIN [3:0]
CONTROL
RX
New Bit
CPLD Transmit Transmit module contains the look up tables: CHANGE_STATE, RX_SYMBOLIZE, BIN7SEG.
Design The latter two are used to display the letters being transmitted. CHANGE_STATE changes the
current state of TX_MODULE (the data to be transmitted), which is sent from the
SHIFT_ENABLE logic module. The logic function RX_SYMBOLIZE is a look up table to convert
6-bits of each digit of data into a 4-bit number. BIN7SEG is a lookup table that takes the 4-bit
symbolized number from the RX_SYMBOLIZE function and converts it into an 8-bit number
sent to the LCD digits. The block diagram for TX_MODULE is shown in Figure 6.
SYS_RST_L SYS_CLK_H
TX MODULE
SHIFTENABLE
CUR_STATE [3:0]
SHIFT_OUT
RX_SYMBOLIZE
TX_DATA [35:0]
[5:0] [11:6]
[3:0]
TX_DATA
DISPLAY_COUNT
LCD
X358_06_062001
Display Count
The DISPLAY_COUNT block diagram is shown in Figure 7. This logic module controls the time
between each state and the LCDCOM signal. STATE_COUNT is incremented and then
enables SWITCH_EN_H. SWITCH_EN_H then enables the logic module SHIFT_ENABLE to
change state (transmit new data).
DISPLAY_COUNT
SHIFT_ENABLE
SWITCH_EN_H
STATE_COUNT
TX_MODULE
COUNT
SYS_CLK_H
SYS_RST_L
X358_07_062001
Shift Enable
The SHIFT_ENABLE logic module increments the state variable to change states, and sends
an edge to an enable signal (LOAD_DATA_H) to update a register in the SHIFT_OUT module
with the new state value. The block diagram is shown in Figure 8.
TRANS_BETWEEN_COUNT determines the time between each state. TRANS_COUNT
controls the number of transmissions between states.
SHIFT_ENABLE
CUR_STATE [3:0]
TX_MODULE
LOAD_DATA_H
SHIFT_OUT TRANS_COUNT
DISPLAY_COUNT
TRANS_BETWEEN_COUNT
SWITCH_EN_H
SYS_CLK_H
SYS_RST_L
X358_08_062001
Shift Out
The SHIFT_OUT logic module sends the TX_DATA to TX_MODULE for transmission.
LOAD_DATA_H enables the SHIFT_OUT module to load the current data. The block diagram is
shown in Figure 9.
SHIFT_OUT
TX_DATA[35:0]
SHIFT_ENABLE
TX_MODULE
PREAMBLE[11:0]
LOAD_DATA_H
CUR_STATE_DATA[11:0]
POSTABLE[11:0] CUR_STATE_DATA[11:0]
SYS_CLK_H
SYS_RST_L
X358_09_062001
The counter size and value used to sample the incoming bits is determined by the system clock
and the baud rate. The RF module allows for a baud rate between 2.4 Kbps to 19.2 Kbps. With
a 32.7 KHz clock, a 2.4 Kbps can be accurately modeled with a 5-bit counter. If the user wishes
to change the baud rate, the value of the sampling counter must also be changed.
Further, the counter is re-initialized when a edge is detected. As previously discussed, this
allows drift to be reduced to a minimum. Therefore, it is recommended that an encoding
scheme which does not allow for long lengths of consecutive bits in the stream be used.
SHIFT_DATA [35:0]
Initialize 0000000000000000000000000000000000000
Edge
Pulse Width Enable Counter
SHIFT_DATA [35:0]
1000000000000000000000000000000000000 Store Data
X358_10_062001
Hardware The following describes the hardware used to develop the CoolRunner CPLD wireless
Description transceiver.
RF Hardware
The RF transmission was preformed by the DR3000 module, manufactured RFM. The DR3000
is designed for short-range and low power applications with a carrier frequency of 916.5 MHz.
Both On-Off Keyed (OOK) and Amplitude-Shift Keyed (ASK) modulation schemes are
supported by the DR3000 module. The transceiver utilizes an Amplifier-Sequenced Hybrid
(ASH) architecture and supports 2.4 to 19.2 Kbps baud rates. The baud rates can be controlled
with additional hardware changes to the RF module. The CoolRunner transceiver utilizes the
2.4 Kbps transmission. The 2.4 baud rate was chosen due to the clock frequency available on
the CPLD demo board.
CPLD Hardware
The CoolRunner XPLA3 demo board from Insight Electronics is used for the CoolRunner
wireless transceiver. The demo board contains a two-digit LCD, 32.768 KHz clock, prototyping
area and the Xilinx CoolRunner XPLA3 XCR3256XL TQ144 CPLD.
Hardware Setup
If using the AC adapter provided with the CoolRunner demo board, ensure that the resister, R7
(refer to the DR300 data sheet), is removed from the DR3000. If R7 is not removed, the
DR3000 will heat up and no longer function properly. Also, ensure the RF module is attached to
a proper power/ground plane to minimize ground loops.
The DR3000 requires a level shifter to correctly drive the CPLD I/O pin (see Figure 11). The RF
module can not drive loads stronger than 500k ohms.
R=100K
RF DMOS FET
CPLD
Data Out
I/O Pin 99
(XPLA3 TQ144 Pin 122)
X358_11_062001
Keyboard Entry The following is a design implementation option for using keyboard entry with the CoolRunner
Option wireless transceiver. CPLD design implementation is left to the user to develop.
PS/2® Protocol
The keyboard interfaces with the CPLD using the PS/2 protocol. The PS/2 protocol works on
serial communication between a host and a peripheral device. The bus can be in three states:
idle, inhibit, and request to send. The device can transmit a byte to the host only when the bus
is idle. In order for the bus to be idle, both the CLK and DATA pins must be high (logic 1). Table 1
is the pin layout for the PS/2 cable.
The byte transmission includes a start bit (logic 0), eight data bits (LSB first), a parity bit (odd
parity), and a stop bit (logic 1). The transmission occurs by having the device transmit a byte of
data by pulsing the CLK low and high 11 times, sampling the DATA line. Figure 12 depicts the
waveform for one PS/2 transmission.
START
BIT 0 BIT 1 BIT 7 PARITY STOP
BIT
BIT
X358_12_062001
Hardware Description
In order to use a keyboard, a keyboard encoder must be used to manipulate data. The
keyboard encoder used for this implementation is the Semtech Greencoder™ (UR5HCFJL)
Zero Power™ Keyboard Encoder for Portable Systems. This keyboard encoder is the device
used between the keyboard and the peripheral device. It works on a matrix (8 X 16) format with
the capability to support a 128 key keyboard. The keyboard encoder has three states that it
operates in: sleep, stand by, and active. These states are used to efficiently manage power
consumption, making this device a good fit for use with CoolRunner. The keyboard encoder
used for this design implementation can function using 3V, 3.3V, or 5V and uses the PS/2
protocol to receive data from the keyboard.
CoolRunner The CoolRunner transceiver is built using the CoolRunner XPLA3 Development Kit from Insight
XPLA3 CPLD Electronics. Table 2 details the I/O pins on the demo board to the pins used on the XPLA3 256
macrocell part in the TQ144 package.
Implementation
Table 2: Prototyping Area I/O Cross Reference
Transceiver Signal Prototyping Area I/O XPLA3 Pin Number
RX I/O 99 119
TX I/O 106 138
CONTROL I/O 104 136
The Transmit module utilization in an XPLA 256-macrocell device is shown in Table 4. Again,
the total utilization for the transmit portion of the design allows room for addition and/or
improvements to the design.
Design Verification
The design was verified in simulation and hardware implementation described previously in this
document.
VHDL VHDL source code and test benches are available for this design. THE DESIGN IS PROVIDED
Disclaimer and TO YOU “AS IS”. XILINX MAKES AND YOU RECEIVE NO WARRANTIES OR CONDITIONS,
EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, AND XILINX SPECIFICALLY
Download DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGMENT,
Instructions OR FITNESS FOR A PARTICULAR PURPOSE. XILINX DOES NOT WARRANT THE
PERFORMANCE, FUNCTIONALITY, OR OPERATION OF THIS DESIGN WILL MEET YOUR
REQUIREMENTS, OR THAT THE OPERATION OF THE DESIGN WILL BE
UNINTERRUPTED OR ERROR FREE, OR THAT DEFECTS IN THE DESIGN WILL BE
CORRECTED. FURTHERMORE, XILINX DOES NOT WARRANT OR MAKE ANY
REPRESENTATIONS REGARDING USE OR THE RESULTS OF THE USE OF THE DESIGN
IN TERMS OF CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
XAPP358 - http://www.xilinx.com/products/xaw/XAPP358.htm
Conclusion This document has detailed the design of the CoolRunner CPLD logic for a wireless
transceiver. The design is targeted for a 3.3V, 256 macrocell CoolRunner CPLD (XCR3256XL
TQ144). This device, as well as the RF module discussed in this paper, has extremely low static
and dynamic power dissipation and therefore is ideally suited for this application. The design of
the CoolRunner wireless transceiver is also provided as an example of using a CoolRunner
CPLD in a portable application and can be extended to many other types of portable
applications
References 1. Zetez Semiconductors Data Sheet - ZVNL110A N-Channel Enhancement Mode Vertical
D(Double Diffused) MOS FET
2. USAR GreenCoderTM Evaluation Board Data Sheet - EVK5-FJL-7603-200
3. Anthes, John. "Unique Considerations for Data Radio UARTs." RF Monolithics, Inc.
4. RF Monolithics Data Sheet - DR3000 916.5 MHz Transceiver Module
Acknowled- The CoolRunner wireless transceiver was development with the senior design team (May 01) of
gements the University of New Mexico (UNM), Electrical and Computer Engineering Department.
Design team included: Erin Isaacson (Xilinx), Lisa Burckel (UNM), Jeremy Dencklau (UNM),
Kristina MIller (UNM), Parveen Sidu (UNM).
Additional thanks to Jim Beneke, Dennis Schlaht, and Lara Kieltyka of Insight Electronics and
Bruce DeVisser of Fujitsu Takamisawa who donated time and equipment to the transceiver
project.
Revision The following table shows the revision history for this document.
History Date Version Revision
06/25/01 1.0 Initial Xilinx release.
Summary This application note describes the implementation of a Smart Card Reader design with a
CoolRunner™-II CPLD. Different from most of the software-based smart card reader computer
systems, this CoolRunner-II CPLD implementation is a hardware solution. There is no software
development needed in this design. This application note explains the low-level protocol of the
Smart Card Reader and its hardware implementation.
CoolRunner-II devices are the latest CPLDs from Xilinx that offer both low power and high-
speed. A VHDL code for Smart Card Reader design is available with this application note: see
Source Code, page 67
Introduction A smart card is a credit card sized plastic card with an embedded microprocessor and memory
and is used for identification, access, and conducting financial transactions.
© 2003 Xilinx, Inc. All rights reserved. All Xilinx trademarks, registered trademarks, patents, and further disclaimers are as listed at http://www.xilinx.com/legal.htm. All other
trademarks and registered trademarks are the property of their respective owners. All specifications are subject to change without notice.
NOTICE OF DISCLAIMER: Xilinx is providing this design, code, or information "as is." By providing the design, code, or information as one possible implementation of this feature,
application, or standard, Xilinx makes no representation that this implementation is free from any claims of infringement. You are responsible for obtaining any rights you may
require for your implementation. Xilinx expressly disclaims any warranty whatsoever with respect to the adequacy of the implementation, including but not limited to any warranties
or representations that this implementation is free from claims of infringement and any implied warranties of merchantability or fitness for a particular purpose.
Acting like a mini-computer, smart cards allow money and information to be electronically
stored and transferred in a secure but portable medium. When inserted into a reader or passed
over a scanner, the smart card transfers data to and from a central computer. Overall, it is a
replacement for old means of retaining data and transacting business.
There are two fundamental sides of development for any smart card application: the host-side
and card-side. Software programming tends to comprise most of the effort involved in smart
card development. The host software runs on a computer connected to a smart card, and the
card software runs on the card as a counterpart to the host software.
In this application note we use a CoolRunner-II CPLD to build a smart card reader, creating a
host-side design to replace a host computer system. The function of a smart card reader is to
read the card content and display the decoded information on a character LCD display. Unlike
standard smart card readers, though, this CoolRunner-II reader relies on hardware design
rather than software programming to perform these tasks.
Smart Card The block diagram of the CoolRunner-II smart card reader is shown in Figure 2. The dashed
Reader Block area shows the logic that is contained in the CoolRunner-II CPLD. All the other blocks are
external devices that can be obtained commercially. The CPLD logic blocks and the external
Diagram devices in this diagram are briefly described in the following section.
SRAM
SRAM Interface
CoolRunner-II CPLD
X372_02_090803
SRAM Interface
SRAM Interface logic interfaces to the external SRAM. This logic block controls the SRAM
read/write addressing. Smart card data is saved in SRAM and later fetched and decoded for the
LCD display.
LCD Control
LCD control logic interfaces to the LCD Display. This logic block accepts the decoded data and
writes to the LCD Display.
LCD Display
The OKAYA RC1602ARS is a 16-character x 2-line, dot matrix, liquid crystal display module. It
has an on-board controller and LSI drivers, which display alpha numerics, Japanese KATA
KANA characters and a wide variety of other symbols in 5 x 7 dot matrix.
SRAM
A low power, 32k x 8 ISSI IS61LV256 SRAM is used in the module memory. The functionality of
the SRAM does not require additional explanation. For more in-depth SRAM information refer
to the ISSI SRAM data sheet.
Smart Card Smart Card is defined by the international standard ISO 7816. The first two parts cover smart
Standard ISO card’s physical dimensions and locations of the chip contacts. A smart card image and its
contacts are shown in Figure 3.
7816
10.25mm
19.23mm
53.98mm
VCC GND
RST VPP
RFU RFU
X372_03_090803
ISO 7816-3 & -4 govern the electronic signals, transmission protocols and inter-industry
commands for interchange. In this application note we limit the discussion to its transmission
protocols and some basic commands.
ISO 7816-5 to –8 cover the number system, data elements, card SQL and security commands.
These parts are not used by this reference design and will not be discussed in this application
note.
Operating This section details the ISO 7816-3 inter-operation between the smart card and the host
Procedure device.
• Connection and activation of the contacts
• Reset of the card
• Answer to Reset
• The T=0 communication protocol
Answer to Reset
There are two types of transmission defined in ISO 8616-3 for answer to reset: asynchronous
and synchronous transmission. In this application note we only discuss asynchronous
transmission.
In asynchronous transmission, characters are transmitted on the I/O line in an asynchronous
half-duplex mode. The normal bit duration used on I/O is defined as one Elementary Time Unit
(etu). The initial etu is 372/fi second where fi is in Hertz. All are initially operated with fi in the
range of 1 MHz to 5 MHz.
A character consists of ten consecutive bits plus a guard time as follows:
• Start bit, used for character frame synchronization
• 8 data bits of information
• Parity bit, even parity for error detection
The guard time is separation between characters. Figure 4 is a diagram for asynchronous
character frame.
I/O ba bb bc bd be bf bg bh bi Guardtime
X372_04_090803
TC2 _ _ _ _ Specific
TA3 _ _ _ _ TA, TB, TC, are specific TD, code Y1-1 and T
TK
X372_05_090803
The initial character TS determines the data transmission rate and also determines the sense
of the logic. The format of the TS character is shown in Figure 6. This shows the two
possibilities of the direct and inverse convention, where logic level one is A, Ba is MSB for
inverse and logic level one is Z, and Ba is LSB for the direct convention.
Start
Z
ba bb bc bd be bf bg bh bi
Inverse Convention
Start
Z
ba bb bc bd be bf bg bh bi
Direct Convention
X372_06_090803
The format character TO provides information necessary to interpret the remaining answer to
reset characters. See TO in Figure 7. the most significant half byte, b8 to b5, indicates the
presence of TA1 to TD1. The least significant half byte, b4 to b1, indicates the number of
historical characters.
TA1 defines the basic characters of the serial transmission. F1 is the clock rate conversion
factor and D1 is the bit-rate adjustment factor. F1 and D1 are compared against a table in the
ISO 7816-3 standard to achieve actual values of F and D in the table to define the actual work
etu.
TB1 is used to define the EPROM programming voltage and current. TC1 provides the value of
N, which defines the extra guard time to be used between successive characters. The first half
byte of TD1 indicates the presence of TA2 to TD2. The second half byte of TD1 indicates the
protocol type T=0 to T=15.
T0 8 5 4 1
(format character)
F1 D1
TA1 8 5 4 1
I1 PI1
TB1 0 7 6 5 1
TC1 8 1
TD1 8 5 4 1
X372_07_090803
The historical characters may be used to convey information relating to the life cycle of the card.
The check character should not be sent when only the T=0 protocol is indicated in the answer
to reset. In all other cases TCK is sent as the last character of the answer to reset. The value
of TCK is such that the exclusive-or of all bytes from T0 to TCK included is equal to zero.
ICC IFD
CLA INS P1 P2 P3
Procedure
Byte
DATA
Status Bytes
SW1 SW2
ICC IFD
CLA INS P1 P2 P3
Procedure
Byte
DATA
Status Bytes
SW1 SW2
X372_08_090803
In Figure 8. IFD is the smart card controller and ICC is the smart card. The command header
consists of the following 5 bytes,
• CLA, the instruction class
• NS, the instruction code
• P1, instruction code qualifier (e.g. memory address)
• P2, additional INS code qualifier
• P3, the length of the data block
The response from the card has two status bytes, SW1 and SW2, to indicate the current card
status. The normal response is SW1, SW2 = 90, 00 hex. When SW1 = 6x or 9x various error
conditions are reported by the card.
Table 1 and Table 2 show some of the CPA classes and INS commands. In this design we use
ISO 7816-4 instruction class 80 and some basic INS codes such as A4, Select File, B2, Read
Record and C0, and Get Response to read all the information we need.
CoolRunner-II The CoolRunner-II smart card reader design uses the Advanced Card System ACOS1
Implementation microprocessor-based card. The information read from the card includes name, gender, status,
age, and bank balance. gender, status and age are encoded in the same data record.
The initial character TS was programmed to direct convention, and format character and
interface characters are predefined. T=0 protocol is used so there is no TCK in answer to reset.
There are 19 bytes, including historical characters transmitted for answer to reset. To simplify
the design, we count bytes received from the smart card with the CoolRunner-II to determine
the valid data to be used.
There will be no parity check for each character frame and no branch operations to handle
different protocol or bytes received. In this situation only the ACOS1 card can be used for this
smart card reader.
the CoolRunner-II device sets Reset to high, goes to the Wait state, and waits for a low signal
from the card, the start bit of the TS for Answer to Reset.
8 Data_out
Card_io Data_ready
Shift Register Byte Encoder
lo_rw
Card_clk
Bitcounter() Bytecounter()
Baud Rate
Bit Counter Byte Counter
Counter
X372_09_090803
Idle
Enable = 1
Init
Wait
Command_end = 1 I/O = 0
Process
Command_ready = 1
Done = 1
End
X372_10_090803
There is a baud rate counter counting to 372 for every bit received or sent to synchronize the
data transmission. The received bits are sampled at the 186th count, which is in the center of
each bit received.
Two other counters are used, one to count bits for each character and one to count bytes
received or sent. The byte number is also used to determine the end of the read data cycle or
the send command cycle.
For this preprogrammed ACOS1 smart card, the state machine will set to the send command
state after 19 Answer to Reset characters are received. The smart card controller is now ready
to send commands and receive responses based on the T=0 protocol. There is decoder logic
to check the character counts to determine when to send a command, what command to send,
and how many characters will be received by the request.
The first command sent to the smart card contains 5 bytes: 80, A4, 00, 00 and 02. After one
procedure byte (A4) is echoed from the smart card, the controller sends two data bytes (F0, 00)
and the smart card responds with two status bytes (91, 00). As is clear from the T=0 command
table, A4 selects the file address and F0, 00 is the selected file address.
The subsequent commands are to select data records and to retrieve data. All the commands
and data lengths are already defined and fixed. In this design, io_rw controls the shift register
to read data from card_io or shift data from data encoder to card_io. All operations are based
on the byte count.
In this design, the name record is between bytes 38 and 69. gender, status and age records are
bytes 92, 93 and 94. The bank balance record are bytes 126 and 127. A data_ready signal is
enabled for these bytes to filter out unused data. This signal is used for the SRAM interface to
write the smart card data to the SRAM.
Data Decoder
SRAM SRAM Interface
Logic
Sram_rw
Data
Lcd_w
Done
Smart Card Main Control LCD To LCD
Control State Machine Control
Lcd_ready
Counter_enable Counter()
Delay Counter
Idle
Smartcard_done = 1
Standby
Lcd_ready = 1
Write_name
Write_female Write_male
Write_married Write_single
Delay_loop
Write_age
End
X372_12_090803
The next data record is decoded gender information. The data value is one for male, two for
female. After gender comes status information, also decoded as one and two (one for single,
two for married).
The age information is saved as binary value in the smart card. It has to be converted to ASCII
digits before getting sent to the LCD controller. A binary-to-digital module is separated from the
top module, which is for the ASCII coding function.
SRAM Interface
The SRAM interface is controlled by the main control logic. The signal sram_w is always kept
high as write enable during smart card reading. The address counter will be reset when the
main control state machine enters the standby state for writing data to the LCD display. The
data is then retrieved in the order it was saved.
LCD Control
LCD control logic is used to initialize and pass decoded data to the LCD display. This module
uses simplified timing to control the LCD display. Every character write cycle is set to 30000
clock periods and is much higher than the few hundred microsecond LCD controller
specification.
Source Code THIRD PARTIES MAY HAVE PATENTS ON THE CODE PROVIDED. BY PROVIDING THIS
CODE AS ONE POSSIBLE IMPLEMENTATION OF THIS DESIGN, XILINX IS MAKING NO
REPRESENTATION THAT THE PROVIDED IMPLEMENTATION OF THIS DESIGN IS FREE
FROM ANY CLAIMS OF INFRINGEMENT BY ANY THIRD PARTY. XILINX EXPRESSLY
DISCLAIMS ANY WARRANTY OR CONDITIONS, EXPRESS, IMPLIED, STATUTORY OR
OTHERWISE, AND XILINX SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF
MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR A PARTICULAR PURPOSE,
THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY
WARRANTY OR REPRESENTATION THAT THE IMPLEMENTATION IS FREE FROM
CLAIMS OF ANY THIRD PARTY. FURTHERMORE, XILINX IS PROVIDING THIS
REFERENCE DESIGN "AS IS" AS A COURTESY TO YOU.
XAPP372 –http://www.xilinx.com/products/xaw/coolvhdlq.htm
Conclusion This document has explained outlined some of the smart card protocol and has explained how
to implement it using a CoolRunner-II, hardware-based solution. Although this Smart Card
Reader design is a simplified version with no error checking or frills, it is a good reference for
users needing to approach for smart card applications with minimal software development.
Revision The following table shows the revision history for this document.
History
Date Version Revision
11/19/03 1.0 Initial Xilinx release.
12/18/03 1.1 Minor errata.
R
CoolRunner-II CPLD I2C Bus Controller
Implementation
XAPP385 (v1.1) December 30, 2003
Summary This document details the VHDL implementation of an I2C controller in a Xilinx CoolRunner™-
II 256-macrocell CPLD. CoolRunner-II CPLDs are the lowest power CPLDs available, making
this the perfect target device for an I2C controller. To obtain the VHDL code described in this
document, go to section VHDL Code Download, page 87 for instructions. This design fits both
XPLA3 and CoolRunner-II CPLDs. For the CoolRunner XPLA3 CPLD version, please refer to
XAPP333, CoolRunner CPLD I2C Bus Controller Implementation.
Introduction The I2C bus is a popular serial, two-wire interface used in many systems because of its low
overhead. The two-wire interface minimizes interconnections so ICs have fewer pins, and the
number of traces required on printed circuit boards is reduced. Capable of 100 KHz operation,
each device connected to the bus is software addressable by a unique address with a simple
Master/Slave protocol.
The CoolRunner-II I2C Controller design contains an asynchronous microcontroller (μC)
interface and provides I2C Master/Slave capability. It is intended to be used with a
microcontroller (μC) or microprocessor (μP) as shown in Figure 1.
SDA
CoolRunner-II I2C Bus Controller SCL
Address
Data I2C Master/
Microcontroller Microcontroller Slave
Control Interface Interface
X385_01_111902
I2C Background This section will describe the main protocol of the I2C bus. For more details and timing
diagrams, please refer to the I2C specification.
The I2C bus consists of two wires, serial data (SDA) and serial clock (SCL), which carry
information between the devices connected to the bus. The number of devices connected to the
same bus is limited only by a maximum bus capacitance of 400 pF. Both the SDA and SCL lines
are bidirectional lines, connected to a positive supply voltage via a pull-up resistor. When the
© 2002 Xilinx, Inc. All rights reserved. All Xilinx trademarks, registered trademarks, patents, and further disclaimers are as listed at http://www.xilinx.com/legal.htm. All other
trademarks and registered trademarks are the property of their respective owners. All specifications are subject to change without notice.
NOTICE OF DISCLAIMER: Xilinx is providing this design, code, or information "as is." By providing the design, code, or information as one possible implementation of this feature,
application, or standard, Xilinx makes no representation that this implementation is free from any claims of infringement. You are responsible for obtaining any rights you may
require for your implementation. Xilinx expressly disclaims any warranty whatsoever with respect to the adequacy of the implementation, including but not limited to any warranties
or representations that this implementation is free from claims of infringement and any implied warranties of merchantability or fitness for a particular purpose.
bus is free, both lines are High. The output stages of devices connected to the bus must have
an open-drain or open-collector in order to perform the wired-AND function.
Each device on the bus has a unique address and can operate as either a transmitter or
receiver. In addition, devices can also be configured as Masters or Slaves. A Master is the
device which initiates a data transfer on the bus and generates the clock signals to permit that
transfer. Any other device that is being addressed is considered a Slave. The I2C protocol
defines an arbitration procedure that insures that if more than one Master simultaneously tries
to control the bus, only one is allowed to do so and the message is not corrupted. The
arbitration and clock synchronization procedures defined in the I2C specification are supported
by the CoolRunner-II I2C Controller.
Data transfers on the I2C bus are initiated with a START condition and are terminated with a
STOP condition. Normal data on the SDA line must be stable during the High period of the
clock. The High or Low state of the data line can only change when SCL is Low. The START
condition is a unique case and is defined by a High-to-Low transition on the SDA line while SCL
is High. Likewise, the STOP condition is a unique case and is defined by a Low-to-High
transition on the SDA line while SCL is High. The definitions of data, START, and STOP insure
that the START and STOP conditions will never be confused as data. This is shown in Figure 2.
SDA MSB
SCL 1 2 3 7 8 9
S P
Start ACK Stop
Condition Condition
x385_10_111902
Each data packet on the I2C bus consists of eight bits of data followed by an acknowledge bit
so one complete data byte transfer requires nine clock pulses. Data is transferred with the most
significant bit first (MSB). The transmitter releases the SDA line during the acknowledge bit and
the receiver of the data transfer must drive the SDA line low during the acknowledge bit to
acknowledge receipt of the data. If a Slave-receiver does not drive the SDA line Low during the
acknowledge bit, this indicates that the Slave-receiver was unable to accept the data and the
Master can then generate a STOP condition to abort the transfer. If the Master-receiver does
not generate an acknowledge, this indicates to the Slave-transmitter that this byte was the last
byte of the transfer.
Standard communication on the bus between a Master and a Slave is composed of four parts:
START, Slave address, data transfer, and STOP. The I2C protocol defines a data transfer format
for both 7-bit and 10-bit addressing. The implementation of the I2C controller in the Xilinx
CoolRunner-II CPLD supports the seven-bit address format. After the START condition, a Slave
address is sent. This address is seven bits long followed by an eighth-bit which is the read/write
bit. A "1" indicates a request for data (read) and a "0" indicates a data transmission (write). Only
the Slave with the calling address that matches the address transmitted by the Master
responds by sending back an acknowledge bit by pulling the SDA line Low on the ninth clock.
Once successful Slave addressing is achieved, the data transfer can proceed byte-by-byte as
specified by the read/write bit. The Master can terminate the communication by generating a
STOP signal to free the bus. However, the Master may generate a START signal without
generating a STOP signal first. This is called a repeated START.
CoolRunner-II The CoolRunner-II CPLD implementation of the I2C Controller supports the following features:
I2C Controller • Microcontroller interface
• Master or Slave operation
• Multi-master operation
• Software selectable acknowledge bit
• Arbitration lost interrupt with automatic mode switching from Master to Slave
• Calling address identification interrupt with automatic mode switching from Master to
Slave
• START and STOP signal generation/detection
• Repeated START signal generation
• Acknowledge bit generation/detection
• Bus busy detection
• 100 KHz operation
Signal The I/O signals of the CoolRunner-II I2C controller are described in Table 1. Pin numbers have
Descriptions not been assigned to this design, this can be done to meet the system requirements of the
designer.
Block Diagram The block diagram of the CoolRunner-II I2C Controller, shown in Figure 3 was broken into two
major blocks, the μC interface and the I2C interface.
ADDR_BUS[23:0]
DATA_BUS[7:0]
DTACK
R_W
MCF
IRQ
DS
AS
μC Interface
ADDR_DECODE/Bus Interface
RESET
START/
STOP
Arbitration and Main State Machine SCL
START/STOP Generation
Detection
I2C Interface
SDA
SCL
X385_02_111902
Microcontroller The μC interface for the I2C controller design supports an asynchronous byte-wide bus
Logic protocol. This protocol is the method in which the μC reads and writes the registers in the
design and is shown in Figure 4.
X385_11_111902
RESET
Asserted
IDLE
AS Asserted
RESET Negated
ADDRESS_MATCH DS
Negated Negated
ADDR
DS Asserted
ADDRESS_MATCH Asserted
AS Negated
DS Negated DATA_TRS
AS Asserted
DS Asserted
ASSERT_DTACK
X385_03_111902
In the first cycle, the μC places the address on the address bus, sets the read/write line to the
correct state, and asserts address strobe (AS) and data strobe (DS). Address strobe indicates
that the address present on the address bus is valid. If this is a write cycle, the μC also places
the data on the data bus and DS indicates that valid data is present on the data bus. If this is a
read cycle, the μC 3-states the data bus and DS indicates that the CoolRunner-II I2C Controller
can place data on the data bus.
Upon the assertion of AS, the CoolRunner-II I2C Controller transitions to the ADDR state to
decode the address and determine if it is the device being addressed. The enables for the
internal registers are set in this state. If the CoolRunner-II I2C Controller is being addressed
and DS is asserted, the CoolRunner-II I2C controller progresses to the DATA_TRS state. If this
is a read cycle, the requested data is placed on the bus and if this is a write cycle, the data from
the data bus is latched in the addressed register. The CoolRunner-II I2C Controller
automatically progresses to the ASSERT_DTACK state and asserts DTACK indicating that the
data requested is ready if a read cycle or that the data has been received if a write cycle.
Upon the assertion of DTACK, the μC either removes data from the bus if this is a write cycle,
or latches the data present on the bus if this is a read cycle. The read/write line is set to read
and AS and DS are negated to indicate that the data transfer is complete. The negation of AS
and DS causes the CoolRunner-II I2C Controller to negate DTACK and transition to the IDLE
state.
I2C Interface The I2C bus interface logic consists of several different processes as seen in Figure 3. Control
Logic bits from the μC interface registers determine the behavior of these processes.
Arbitration
Arbitration of the I2C bus is lost in the following circumstances:
• The SDA signal is sampled as a "0" when the Master outputs a "1" during an address or
data transmit cycle
• The SDA signal is sampled as a "0" when the Master outputs a "1" during the
acknowledge bit of a data receive cycle
• A start cycle is attempted when the bus is busy
START/STOP Detection
This process monitors the SDA and SCL signals on the I2C bus for START and STOP
conditions. When a START condition is detected, the Bus Busy bit is set. This bit stays set until
a STOP condition is detected. The signals, DETECT_START and DETECT_STOP are
generated by this process for use by other processes in the logic. Note that this logic detects
the START and STOP conditions even when the CoolRunner-II I2C Controller is the generator
of these conditions.
The state machine that generates SCL and SDA when in Master mode is shown in Figure 6.
Note that SCL and SDA are held at the default levels if the bus is busy. This state machine
generates the controls for the system clock counter.
RST
GEN_START = 0
IDLE
GEN_START = 1
REP_START = 1 START
CLK_CNT = HIGH_CNT/2
CLK_CNT = START_HOLD
ARB_LOST = 1
BIT_CNT > 7
CLK_CNT = TBUF
SCL_LOW_EDGE
SCL_LOW
CLK_CNT = LOW_CNT
CLK_CNT < TBUF
CLK_CNT = HIGH_CNT
STOP_WAIT
SCL_INT = 0
SCL_HI_EDGE
GEN_STOP = 1
CLK_CNT = HIGH_CNT/2 SCL_INT = 1
SCL_HI
X385_04_111902
The internal SDA signal output from this design is either the SDA signal generated by this state
machine for START and STOP conditions or the data from the MBDR register when the
CoolRunner-II I2C Controller is in transmit mode. Note that both SCL and SDA are open-
collector outputs, therefore, they are only driven to a "0". When a "1" is to be output on these
signals, the CoolRunner-II I2C Controller 3-states their output buffers. The logic in the design
will set internal SDA and SCL signals to "1" or "0". These internal signals actually control the
output enable of the 3-state buffer for these outputs.
In the IDLE state, SCL and SDA are 3-stated, allowing any Master to control the bus. Once a
request has entered to generate a start condition, the CoolRunner-II I2C Controller is in Master
mode, and the bus is not busy, the state machine transitions to the START state.
The START state holds SCL High, but drives SDA Low to generate a START condition. The
system clock counter is started and the state machine stays in this state until the required hold
time is met. At this point, the next state is SCL_LOW_EDGE.
The SCL_LOW_EDGE state simply creates a falling edge on SCL and resets the system clock
counter. On the next clock edge, the state machine moves to state SCL_LOW. In this state, the
SCL line is held Low and the system clock counter begins counting. If the REP_START signal
is asserted then the SDA signal will be set High, if the GEN_STOP signal is asserted, SDA will
be set Low.
When the SCL low time has been reached, the state machine will transition to the IDLE state if
arbitration has been lost and the byte transfer is complete to insure that SCL continues until the
end of the transfer. Otherwise the next state is the SCL_HI_EDGE state.
The SCL_HI_EDGE state generates a rising edge on SCL by setting SCL to "1". Note, however,
that the state machine will not transition to the SCL_HI state until the sampled SCL signal is
also High to obey the clock synchronization protocol of the I2C specification. Clock
synchronization is performed using the wired-AND connection of the SCL line. The SCL line will
be held Low by the device with the longest low period. Devices with shorter low periods enter
a high wait state until all devices have released the SCL line and it goes High. Therefore the
SCL_HI_EDGE state operates as the high wait state as the SCL clock is synchronized.
The SCL_HI state then starts the system clock counter to count the high time for the SCL
signal. If a repeated START or a STOP condition has been requested, the state machine will
transition to the appropriate state after half of the SCL high time so that the SDA line can
transition as required. If neither of these conditions has been requested, then the state machine
transitions to the SCL_LOW_EDGE state when the SCL high time has been achieved.
The STOP_WAIT state is used to insure that the hold time requirement after a STOP condition
is met.
Master to Slave mode if arbitration is lost or if the CoolRunner-II I2C Controller is addressed as
a Slave.
RESET
Asserted
IDLE
DETECT_START = 1
BIT_CNT < 8
HEADER
Master Rcv
SDA = 0 ACK_HEADER Master Xmit
SDA = 0
Slave Rcv
Slave Xmit
ADDR_MATCH = 1
ADDR_MATCH = 1
RCV_DATA XMIT_DATA
Master
DETECT_STOP = 1 SDA = 1 DETECT_STOP = 1 SDA = 0
BIT_CNT = 8 BIT_CNT = 8
ACK_DATA WAIT_ACK
SDA = 1
STOP
X385_05_111902
This state machine utilizes and controls a counter that counts the I2C bits that have been
received. This count is stored in the signal BIT_CNT. This state machine also controls two shift
registers, one that stores the I2C header that has been received and another that stores the I2C
data that has been received or is to be transmitted.
Note:
This state machine and the associated counters and shift registers are clocked on the falling edge of
the incoming SCL clock. If the load is heavy on the SCL line, the rise time of the SCL signal may be
very slow which can cause susceptibility to noise for some systems. This can be particularly
dangerous on a clock signal. The designer is strongly encouraged to investigate the signal integrity of
the SCL line and if necessary, use external buffers for the SCL signal.
When a START signal has been detected, the state machine transitions from the IDLE state to
the HEADER state. The START signal detection circuit monitors the incoming SDA and SCL
lines to detect the START condition. The START condition can be generated by the
CoolRunner-II I2C controller or another Master—either source will transition the state machine
to the HEADER state.
The HEADER state is the state where the I2C header is transmitted on the I2C bus from the
MBDR register if in Master mode. In this state, the incoming I2C data is captured in the I2C
Header shift register. In Master mode, the I2C Header shift register will contain the data that
was just transmitted by this design. When all eight bits of the I2C header have been shifted in,
the state machine transitions to the ACK_HEADER state.
In the ACK_HEADER state, the CoolRunner-II I2C design samples the SDA line if in Master
mode to determine whether the addressed I2C Slave acknowledged the header. If the
addressed Slave does not acknowledge the header, the state machine will transition to the
STOP state which signals the SCL/START/STOP generator to generate a STOP. If the
addressed Slave has acknowledged the address, then the LSB of the I2C header is used to
determine if this is a transmit or receive operation and the state machine transitions to the
appropriate state to either receive data, RCV_DATA, or to transmit data, XMIT_DATA.
The I2C Header shift register is constantly compared with the I2C address set in the MADR
register. If these values match in the ACK_HEADER state, the CoolRunner-II I2C Controller has
been addressed as a Slave and the mode immediately switches to Slave mode. The MAAS bit
is then set in the MBSR status register. The SDA line will be driven as set in the TXAK register
to acknowledge the header to the current I2C bus Master. Again, the LSB of the I2C header is
used to determine the direction of the data transfer and the appropriate state is chosen.
The RCV_DATA state shifts the incoming I2C data into the I2C shift register for transfer to the
μC. When the whole data byte has been received, the state machine transitions to the
ACK_DATA state and the value of the TXAK register is output on the SDA line to acknowledge
the data transfer. Note that in Master mode, the indication that the Slave has transmitted the
required number of data bytes is to not acknowledge the last byte of data. The μC must negate
the TXAK bit to prohibit the ACK of the last data byte. The state machine exits this pair of states
when a STOP condition has been detected, otherwise, the transition between these two states
continues. In Master mode, the μC requests a STOP condition by negating the MSTA bit.
The XMIT_DATA state shifts the data from the I2C data register to the SDA line. When the entire
byte has been output, the state machine transitions to the WAIT_ACK state. If an acknowledge
is received, the state machine goes back to the XMIT_DATA to transmit the next byte of data.
This pattern continues until either a STOP condition is detected, or an acknowledge is not
received for a data byte.
Note that the data transfer states of this state machine assume that the μC can keep up with the
rate at which data is received or transmitted. If interrupts are enabled, an interrupt is generated
at the completion of each byte transfer. The MCF bit is set as well providing the same
indication. Data is transferred to/from the I2C data register to/from the μC data register during
the acknowledge cycle of the data transfer. The state machine does not wait for an indication
that the μC has read the received data or that new data has been written for transmission. The
designer should be aware of the effective data rate of the μC to insure that this is not an issue.
The STOP state signals the SCL/START/STOP generator to generate a STOP condition if the
CoolRunner-II I2C design is in Master mode. The next state is always the IDLE state and the
I2C activity is completed.
Operational The flow of the interface between the μC and the CoolRunner-II I2C Controller is detailed in the
Flow Diagrams following flow charts. These flow charts are meant to be a guide for utilizing the CoolRunner-II
I2C Controller in a μC system.
Initialization
Before the CoolRunner-II I2C Controller can be utilized, certain bits and registers must be
initialized as shown in Figure 8.
BEGIN
Modify MBCR to
Enable Interrupts
END
X385_06_111902
Master Transmit/Receive
The flow charts for transmitting data and receiving data while I2C bus Master are shown in
Figure 9 and Figure 10. The major difference between transmitting and receiving is the
additional step in the Master Receive flow chart of turning off the acknowledge bit on the
second to last data word.
BEGIN
No
Write I2C Header
in MBDR
Transfer
No
Complete?
(MCF = 1)
Yes
Write Data
to MBDR
Transfer
No
Complete?
(MCF = 1)
Yes
No
Last Word?
Yes
Negate MSTA in MBCR
to Generate STOP
END
X385_07_111902
BEGIN
No
Write I2C Header
in MBDR
Transfer
No
Complete?
(MCF = 1)
Yes
Read Data
from MBDR
Transfer
No
Complete?
(MCF = 1)
Yes
No
Last Word - 1?
Yes
Set TXAK in MBCR
to Turn Off ACK
Yes
Read Data from
MBDR
Transfer
No
Complete?
(MCF = 1)
Yes
Negate MSTA in MBCR
to Generate STOP
END
X385_08_111902
BEGIN
Addressed No
as Slave?
Yes
Check SRW Bit in
MSBR for Xmit/Rcv
Read/Write Data
in MBDR
Transfer
No
Complete?
(MCF = 1)
Yes
Yes
Bus Busy?
MAAS = 1?
No
END
X385_09_111902
CoolRunner-II The design of the CoolRunner-II I2C Controller was implemented in VHDL and targeted to a
CPLD 256 macrocell CoolRunner-II CPLD in a 144-pin TQFP package (XC2C256-5TQ144) using
Xilinx Project Navigator. (Xilinx Project Navigator software is available free-of-charge from the
Implementation Xilinx website: www.xilinx.com/products/software/webpowered.htm.).
Note:
Since the system clock frequency was 1.832 MHz, the speed of the design was not critical and any
speed grade part could have been used.
Note:
The I2C SCL line is used as a clock input into the CoolRunner-II I2C Controller. If there are many
loads on the I2C bus, the rise time of the SCL line can be quite slow. The CoolRunner-II CPLD for this
design requires a rise time no greater than 20ns, therefore, the designer is strongly encouraged to
examine the characteristics of the SCL signal in the I2C system. If the rise time of the I2C signals are
greater than 20 ns, the inputs can be configured as Schmitt Triggers providing for input hysteresis and
noise immunity. Schmitt Trigger inputs will prevent adverse effects of slow rising/falling input signals.
The I2C design utilization in a CoolRunner-II 256-macrocell device is shown in Table 7. This
utilization was achieved using certain fitter parameters, actual results may vary. As shown,
there is plenty of room remaining in the device for the implementation of other logic in the
system.
Design Verification
The Xilinx Project Navigator software package outputs a timing VHDL model of the fitted
design. This post-fit VHDL was simulated with the original VHDL test benches to insure design
functionality. Also, the CoolRunner-II I2C Controller design was simulated with an
independently generated VHDL model of an I2C Slave design to verify that the interface
specifications were implemented correctly. Please note that all verification of this design has
been done through simulations.
VHDL Code VHDL source code and test benches are available for this design. THE DESIGN IS PROVIDED
Download TO YOU "AS IS". XILINX MAKES AND YOU RECEIVE NO WARRANTIES OR CONDITIONS,
EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, AND XILINX SPECIFICALLY
DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT,
OR FITNESS FOR A PARTICULAR PURPOSE. This design has not been verified on hardware
(as opposed to simulations), and it should be used only as an example design, not as a fully
functional core. XILINX does not warrant the performance, functionality, or operation of this
Design will meet your requirements, or that the operation of the Design will be uninterrupted or
error free, or that defects in the Design will be corrected. Furthermore, XILINX does not warrant
or make any representations regarding use or the results of the use of the Design in terms of
correctness, accuracy, reliability or otherwise.
VHDL - ftp://ftp.xilinx.com/pub/applications/refdes/xapp333.zip
Verilog - ftp://ftp.xilinx.com/pub/applications/refdes/xapp333_ver.zip
Disclaimer I2C is a registered trademark of Philips Electronics N.V.. Xilinx provides this reference design
as one possible implementation of this standard and claims no rights to this interface. To use
this reference design, you must contact Philips to obtain any necessary rights associated with
this interface.
Conclusion This document has detailed the design of an I2C Controller design for a CoolRunner-II CPLD.
Though the design has been extensively verified in simulations, Xilinx assumes no
responsibility for the accuracy or the functionality of this design.
Revision The following table shows the revision history for this document.
History
Date Version Revision
12/24/02 1.0 Initial Xilinx release.
12/30/03 1.1 Change to control register address.
R
CoolRunner-II Serial Peripheral Interface
Master
XAPP386 (v1.0) December 12, 2002
Summary This document details the VHDL implementation of a Serial Peripheral Interface (SPI) master in
a Xilinx CoolRunner™-II CPLD. CoolRunner-II CPLDs are the lowest power CPLDs available,
making this the perfect target device for an SPI Master. To obtain the VHDL code described in
this document, go to section VHDL Code Download and Disclaimer, page 107 for
instructions. This design fits XC2C256 CoolRunner-II or XCR3256XL CoolRunner XPLA3
CPLDs.
Introduction The Serial Peripheral Interface (SPI) is a full-duplex, synchronous, serial data link that is
standard across many microprocessors, microcontrollers, and peripherals. It enables
communication between microprocessors and peripherals and/or inter-processor
communication. The SPI system is flexible enough to interface directly with numerous
commercially available peripherals.
A SPI Master design has been implemented in a CoolRunner-II CPLD. The CoolRunner-II SPI
Master design can be used to provide a SPI controller to those microcontrollers or
microprocessors that do not contain a SPI interface. A high-level block diagram is shown in
Figure 1. The microcontroller (μC) interface chosen in this SPI Master implementation is based
on the popular 8051 microcontroller bus cycles, but can easily be modified to other
microcontroller interfaces. For more information on the 8051 microcontroller interface, please
refer to XAPP388, CoolRunner-II CPLD 8051 Microcontroller Interface.
SCK
CoolRunner-II SPI Master MOSI
MISO
SS_N[7:0]
Address
Data SPI Master
Microcontroller Microcontroller Interface
Control Interface
SS_IN_N
X386_01_121202
© 2002 Xilinx, Inc. All rights reserved. All Xilinx trademarks, registered trademarks, patents, and further disclaimers are as listed at http://www.xilinx.com/legal.htm. All other
trademarks and registered trademarks are the property of their respective owners. All specifications are subject to change without notice.
NOTICE OF DISCLAIMER: Xilinx is providing this design, code, or information "as is." By providing the design, code, or information as one possible implementation of this feature,
application, or standard, Xilinx makes no representation that this implementation is free from any claims of infringement. You are responsible for obtaining any rights you may
require for your implementation. Xilinx expressly disclaims any warranty whatsoever with respect to the adequacy of the implementation, including but not limited to any warranties
or representations that this implementation is free from claims of infringement and any implied warranties of merchantability or fitness for a particular purpose.
SPI Background This section will describe the main protocol of the SPI bus. For more details and timing
diagrams, please refer to the description of the SPI bus in the Motorola 68HC11 Reference
Manual.
The SPI bus consists of four wires, Serial Clock (SCK), Master Out Slave In (MOSI), Master In
Slave Out (MISO), and Slave Select (SS_N), which carry information between the devices
connected to the bus.
The SCK control line is driven by the SPI Master and regulates the flow of data bits. The master
may transmit data at a variety of baud rates; the SCK line transitions once for each bit in the
transmitted data. The SPI specification allows a selection of clock polarity and a choice of two
fundamentally different clocking protocols on an 8-bit oriented data transfer. The master selects
one of four different bit rates for SCK. Data is shifted on one edge of SCK and is sampled on the
opposite edge when the data is stable.
The MOSI data line carries the output data from the master which is shifted as the input data to
the selected slave. The MISO data line carries the output data from the selected slave to the
input of the master. There may be no more than one slave transmitting data during a particular
transfer.
All SCK, MOSI, and MISO pins are tied together. A single SPI device is configured as a master;
all other SPI devices on the SPI bus are configured as slaves. The single master drives data out
its SCK and MOSI pins to the SCK and MOSI pins of the slaves. One selected slave device can
drive data out its MISO pin to the MISO master pin.
The SS_N control line selects a particular slave via hardware control. This control line allows
individual selection of a slave SPI device. Slave devices that are not selected do not interfere
with SPI bus activities. Slave devices ignore the SCK signal and keeps the MISO output pin in
a high impedance state unless the slave select pin is active low.
The SS_IN_N control line can be used as an input to the SPI Master indicating a multiple-
master bus contention (SS_IN_N). If the SS_IN_N signal to the master is asserted, it indicates
that some other device on the bus is attempting to be a master and address this device as a
slave. Assertion of SS_IN_N automatically disables SPI output drivers in the master device if
more than one device attempts to become master.
The clock phase and polarity can be modified for SPI data transfers. The clock polarity (CPOL)
selects an active high or active low clock and has no significant effect on the transfer format. If
CPOL = "0", then the idle state of SCK is low. If CPOL = "1", then the idle state of SCK is high.
The clock phase (CPHA) can be modified to select one of two fundamentally different transfer
formats. If CPHA = "0", data is valid on the first SCK edge (rising or falling) after SS_N has
asserted. If CPHA = "1", data is valid on the second SCK edge (rising or falling) after SS_N has
asserted. The clock phase and polarity should be identical for the master SPI device and the
communicating slave device.
Figure 2 shows the timing diagram for a SPI data transfer when the clock phase, CPHA, is set
to "0". The waveform is shown for both positive and negative clock polarities of SCK. The SCK
signal remains inactive for the first half of the first SCK cycle (SCK Cycle 1). In this transfer
format, the falling edge of SS_N indicates the beginning of a data transfer. Therefore, the SS_N
line must be negated and reasserted between each successive serial byte. If the slave writes
data to the SPI data register while SS_N is active low, a write-collision error results.
SCK Cycle 1 SCK Cycle 2 SCK Cycle 3 SCK Cycle 4-6 SCK Cycle 7 SCK Cycle 8
SCK (CPOL=1)
SCK (CPOL=0)
SS
Figure 3 shows the timing diagram for a SPI transfer when the clock phase, CPHA, is set to "1".
The waveform is shown for both positive and negative clock polarities of SCK. The first SCK
cycle begins with an edge on the SCK line from its inactive to its active level. The first edge of
SCK indicates the start of the data transfer in this format. The SS_N line may remain active low
between successive transfers. This format is useful in systems with a single master and single
slave.
SCK (CPOL=1)
SCK (CPOL=0)
SS
When an SPI transfer occurs, an 8-bit data word is shifted out one interface pin while a different
8-bit data word is being shifted in on another interface pin. This can be viewed as an 8-bit shift
register in the SPI Master device and another 8-bit shift register in a SPI slave device that are
connected as a circular 16-bit shift register. When a transfer occurs, this 16-bit shift register is
shifted 8 positions, thus exchanging the 8-bit data between the master and slave devices.
The SPI specification details the timing and wave forms for byte transfers on the SPI bus, but
does not dictate the data protocol used in these transfers, i.e., the interface specification does
not specify that the first byte contain an address or a read/write line. When communicating to
devices over the SPI bus, it is important to review the specifications of these devices to
determine the required communication protocol so that commands, addresses and the data
direction (read/write) can be set correctly. The CoolRunner-II CPLD SPI Master implementation
will not enforce a particular data protocol. It is expected that the μC will specify the data bytes
to be transferred on the SPI bus in the correct order. All data received on the SPI bus will be
stored in a receive register for the user logic to interpret. All data written to the transmit register
will be transmitted on the SPI bus.
CoolRunner-II The CoolRunner-II CPLD implementation of an SPI Master supports the following features:
SPI Master • Microcontroller interface
Implementation • Multi-master bus contention detection and interrupt
• Eight external slave selects
• Four transfer protocols available with selectable clock polarity and clock phase
• SPI transfer complete microcontroller interrupt
• Four different bit rates available for SCK
Signal The 36 I/O signals of the CoolRunner-II CPLD SPI Master are described in Table 1. Pin
Descriptions numbers have not been assigned to this design, this can be done to meet the system
requirements of the designer.
Block Diagram The block diagram of the CoolRunner-II CPLD SPI Master, shown in Figure 4 was broken into
two major blocks, the μC interface and the SPI interface.
ADDR_DATA[7:0]
XMIT_EMPTY
ADDR[15:8]
RCV_FULL
PSEN_N
ALE_N
WR_N
INT_N
RD_N
Microcontroller
Interface
Address Decode/Bus Interface
RESET
Status Register Control Register Slave Select Receive Register Transmit Register
SPISR SPICR Register - SPISSR SPIRR SPITR
SYS_CLK
Input
Registers
SPI Control
State Machine
SPI Interface
SCK
SS_IN_N
SS_N[7:0]
MOSI
MISO
X386_04_121202
μC Interface The μC interface for the SPI Master design supports a byte-wide, multiplexed address/data bus
Logic protocol found in the popular 8051 μC. This protocol is the method in which the μC reads and
writes the registers in the CoolRunner-II CPLD and is shown in Figure 5.
Note that the code to interface to the 8051 μC is a separate VHDL module which interfaces to
the SPI interface logic via a set of registers. Therefore, this code can easily be replaced with the
μC interface of your choice.
IDLE
ale_n=0
psen_n=1 addr_match=0
ADDR_DECODE
rd_n=0 or wr_n=0
addr_match=1
rd_n=0 or wr_n=0
DATA_TRS
rd_n=1 or wr_n=1
END_CYCLE
X386_06_121202
In the first cycle, the μC places the address on the address bus and asserts address latch
enable (ALE_N). ALE_N indicates that the data on the multiplexed address/data bus is a valid
address and that the address on ADDR[15:0] is also valid.
Upon the assertion of ALE_N, the CoolRunner-II SPI Master transitions to the
ADDR_DECODE state to decode the address and determine if it is the device being
addressed. The enables for the internal registers are set in this state. ALE_N is also used to
register the lower address bits from the multiplexed ADDR_DATA bus.
If this is a write cycle, the μC removes the address from the multiplexed address/data bus and
places the data to be written onto these signals. The write strobe (WR_N) is then asserted. If
this a read cycle, the μC 3-states the multiplexed address/data bus and asserts the read strobe
(RD_N) indicating that the CoolRunner-II SPI Master can place data from the addressed
register on the data bus.
If the CoolRunner-II SPI Master is being addressed and either RD_N or WR_N are asserted,
the CoolRunner-II SPI Master progresses to the DATA_TRS state. If this is a read cycle, the
requested data is placed on the bus and if this is a write cycle, the data from the data bus is
latched in the addressed register.
The μC latches the data present on the bus if this is a read cycle and then negates the read
strobe (RD_N). If this is a write cycle, the μC removes data from the bus and then negates the
write strobe (WR_N). The negation of either RD_N or WR_N causes the CoolRunner-II SPI
Master to progress to the END_CYCLE state. The CoolRunner-II CPLD will 3-state the
multiplexed address/data bus in this state, removing the data if it is a read cycle.
At this point, the μC ends the cycle by negating address latch enable (ALE_N), which causes
the CoolRunner-II CPLD to return to the IDLE state.
The registers supported in the CoolRunner-II SPI Master are described in the Table 2. The μC
interface logic of the CoolRunner-II SPI Master handles the reading and writing of these
registers by the μC and supplies and/or retrieves these bits to/from the SPI interface logic.
and START must be asserted before the SPI state machine will begin transmission of data on
the SPI bus.
SPI Interface The SPI bus interface logic consists of several different processes as seen in Figure 4. Control
Logic bits from the μC interface registers determine the behavior of these processes.
select is then negated after the required hold time. The SPI control state machine is shown in
Figure 7.
IDLE
start=1
xmit_empty=0
ASSERT_SSN1
sck_int_re=1
ASSERT_SSN2
sck_int_fe=1
UNMASK_SCK
sck_int_re=1
bit_cnt < > 8
XFER_BIT
bit_cnt=8
cpha=1 ASSERT_DONE
start=1
xmit_empty=0
sck_int_fe=1
CHK_START
start=0 or
cpha=0 and ((cpol=0 and sck_fe=1) or
(cpol=1 and sck_re=1))
MASK_SCK
sck_int_fe=1
HOLD_SSN1
sck_int_fe=1
sck_int_fe=1 HOLD_SSN2
sck_int_fe=1
NEGATE_SSN
X386_07_121202
The SPI Control state machine remains in the IDLE state until the START bit in the SPI Control
register is asserted and the XMIT_EMPTY signal is negated. At this point, the state machine
moves to the ASSERT_SSN1 state to assert the internal SS_N signal. This signal is then
masked with the SPI Slave Select Register (SPISSR) to generate the slave select signals
output to the system. After a rising edge of the internal SCK (SCK_INT_RE=1), the state
machine transitions to the ASSERT_SSN2 state, keeping SS_N asserted until the falling edge
of the internal SCK. This state machine will insure that SS_N will assert ~1 SCK period before
the first SCK edge, meeting the SS_N setup time requirement of most SPI slave devices. This
timing parameter should be verified by the designer for the target system as the SS_N setup
time requirement may vary between different SPI slaves.
After SS_N has been asserted for both the ASSERT_SSN1 and ASSERT_SSN2 states, the
state machine transitions to the UNMASK_SCK state. The first edge of the phase 1 (CPHA=1)
version of SCK occurs before the first data is output, therefore, this state unmasks the phase1
version of SCK. The SPI transmit shift register is loaded with data from the SPITR in this state.
The SPI transmit shift register is clocked by the rising edge of the internal SCK signal. The state
machine waits for a rising edge of the internal SCK signal (SCK_INT_RE) to leave this state to
insure that the SPI transmit shift register has been loaded.
The state machine then moves to the XFER_BIT state. The first edge of the phase 0 (CPHA=0)
version of SCK occurs after data has been output, therefore, this state unmasks the phase 0
version of SCK. This state shifts data from the SPI transmit shift register and the state machine
remains in this state until the byte transfer is complete. Once the byte transfer has completed,
the state machine transitions to the ASSERT_DONE state where the DONE signal in the SPI
Status Register (SPISR) is asserted. The state machine will not transition to the CHK_START
state until the next falling edge of the internal SCK to synchronize this state machine to the
internal SCK.
The SPI specification requires that SS_N be negated and re-asserted between consecutive
byte transfers when CPHA=0. If CPHA=1, SS_N can remain asserted during consecutive byte
transfers. Therefore, if START is still asserted in the CHK_START state and CPHA=1 and
XMIT_EMPTY is negated, the state machine transitions back to the UNMASK_SCK state and
continues SPI transfers. If START is negated or CPHA=0, the state machine transitions to the
MASK_SCK state which masks both the phase 0 and the phase1 versions of SCK. Note,
however, that the state machine waits for either the rising edge (if CPOL=1) or the falling edge
(if CPOL=0) of the external SCK before transitioning to this state to insure that the transmission
has been completed before masking the external clock.
At the next falling edge of the internal SCK (SCK_INT_FE), the state machine transitions to the
HOLD_SSN1 state. SS_N must stay asserted for some time period after the last SCK edge.To
insure that the SS_N hold time is at least 2 SCK periods, the state machine transitions to
HOLD_SSN2 after the next falling edge of the internal SCK (SCK_INT_FE) and remains in this
state until another falling edge of the internal SCK has occurred. This will meet the SS_N hold
time requirement of most SPI slave devices. This timing parameter should be verified by the
designer for the target system as the SS_N hold time requirement may vary between different
SPI slaves.
At this point, the state machine transitions to the NEGATE_SSN state and remains in this state
until the next falling edge of the internal SCK. This insures that the pulse width of SS_N
between SPI transfers is at least one SCK period. This will meet the SS_N pulse width
requirement of most SPI slave devices. This timing parameter should be verified by the
designer for the target system as the SS_N pulse width requirement may vary between different
SPI slaves.
The state machine then transitions to the IDLE state. If START is asserted and XMIT_EMPTY
is negated, the SPI transfer and state machine operation will repeat.
Note that if no further SPI transfers are required, the μC must negate the START signal after
writing the last data word of the transmission to the SPITR as shown in Figure 11.
Also note that at any time, the assertion of SS_IN_N will cause the SPI Control state machine
to return to the IDLE state and the MOSI, SS_N, and SCK outputs will be 3-stated. The SPI
Master will remain in this state until the SS_IN_N signal is negated and the START signal is
asserted. When a SPI error occurs, the system must be examined to determine the cause of
the error. The μC can reset the bit in the SPI status register (SPISR) and then continue to read
the SPI status register (SPISR) to determine if the system error has been corrected. Once the
error has been fixed at the system level, the SPI interface should be reset to guarantee correct
operation as shown in Figure 11. The μC can reset the SPI Master by negating the SPIEN bit
in the SPI control register (SPICR).
The receive full flag (RCV_FULL) is set whenever data is loaded from the SPI receive shift
register to the SPIRR. This signal is clocked from the system clock and is reset whenever the
μC reads data from the SPIRR.
clk_cnt(1) clk0_mask
sck_0
clk_cnt(2)
sck_int
Clock clk_cnt(3) Mux/Reg sck_out
Mux/Reg
Counter clk_cnt(4) sck_1
clk1_mask
clkdiv(0)
cpha
sys_clk
clkdiv(1)
cpol
sys_clk
sys_clk
X386_08_121202
This is accomplished by a single register clocked from SYS_CLK which simply clocks the data
output from the shift register as shown in Figure 9..
data from
SPI Transmit
Register 8
MOSI
8-bit SPI Xmit Shift Register MOSI
Register
load sys_clk
shift
sck_int
X386_09_121202
Register for use by the μC. The SPI receive shift register, MISO input registers, and receive bit
counter are shown in Figure 10.
data to
SPI Receive
Register rcv_load
8
MISO
MISO
SCK Register
MUX 8-bit SPI Receive Shift Register
MISO
Register
shift
rcv_cpol Receive
sck_int
Bit Counter
X386_10_121202
Figure 10: SPI Receive Shift Register and MISO Input Data Registers
Operational The flow of the interface between the μC and the CoolRunner-II SPI Master is detailed in the
Flow Diagrams following flow charts. These flow charts are meant to be a guide for utilizing the CoolRunner-II
SPI Master in a μC system.
SPI error has occurred; the designer should determine the correct operations to execute when
an SPI error occurs based on the system requirements.
BEGIN
No
Read SPI Bus
XMIT_EMPTY
Status from SPISR =1?
Yes
Yes
Bus Busy= 1? Yes
Last Word?
No
Negate START bit
No in SPICR
Configure SPI Master
by writing to SPICR: Write SPI Transmit
SPIEN, INTEN, Data in SPITR
CLKDIV, CPHA
CPOL, RCV_CPOL
No
Write SPI Transmit RCV_FULL
Data in SPITR =1?
Yes
Set START bit in SPITR
Read SPI Receive
Data in SPIRR
No Interrupt
(INT_N=0)?
No
Last Word?
Yes
Read SPI Bus Status Yes
from SPISR
No
SPIERR = 1?
Yes
Yes END
SPIERR = 1?
No
VHDL A VHDL testbench has been developed that verifies the CoolRunner-II SPI Master
Testbench and implementation through all the possible combinations of CLKDIV, CPHA, CPOL, and
RCV_CPOL. This testbench contains a process that emulates the bus cycles of the 8051 μC.
Functional Constants are provided at the top of the testbench file to set up the base address of the SPI
Simulation Master device and all of the registers contained within the device. These constants should be
modified to match the addressing scheme of the designer’s system.
The VHDL testbench also provides a model of a simple SPI slave. The slave first transmits the
hex value "CE" and then simply transmits the value that was received. The clock phase and
polarity of the slave are dynamically set in the test bench based on the CPHA and CPOL values
currently being tested.
To test the SPI Master reaction to an SPI error, the test bench contains the constant
SS_IN_ASSERT_TIME which specifies the delay from the beginning of the simulation until
SS_IN_N is asserted and also specifies the amount of time that SS_IN_N is asserted. Setting
this constant to "0" disables assertion of SS_IN_N.
The test bench contains a signal, ERROR, which indicates that the data received did not match
the expected data. The simulation has run correctly if ERROR stays "0" throughout all SPI
transfers. Note, however, that ERROR may assert some time during the simulation if the
testbench is set up to test SS_IN_N assertion. This is due to the fact that the data received may
be out of alignment with the expected data value.
The ModelSim command file, func_sim.do, can be used to open the correct waveform window
and run the simulation.
CoolRunner-II The CoolRunner-II SPI Master design has been targeted to a CoolRunner-II 256 macrocell
CPLD device. The speed grade chosen is dependent on the system clock frequencies and should be
analyzed by the designer to determine which speed grade is required.
Implementation
The CoolRunner-II SPI Master utilizes 128 of the 256 macrocells available in the device,
leaving 50% of the device resources for user logic.
The top level file for the SPI Master has been entered as a heirarchical VHDL file showing the
connection between the uc_interface block and the spi_interface block. The spi_interface block
is also a hierarchical VHDL fileshowing the inter connectivity between the spi_control_sm
block, the sck_logic block, the spi_rcv_shift_reg block and the spi_xmit_shift_reg block. The
structural VHDL models are found in the files spi_master.vhd and spi_interface.vhd.
Post-fit Timing The Xilinx Project Navigator software package outputs a timing VHDL model of the fitted
Simulation design. This post-fit VHDL was simulated with the original VHDL test benches to insure design
functionality using ModelTech Xilinx Edition (MXE). Please note that all verification of this
design has been done through simulations.
The user of this design is strongly encouraged to thoroughly inspect the timing report for this
design to insure that the design meets the timing specification of the system. The user is also
strongly encouraged to perform post-fit timing simulations as well. The ModelSim command
file, post_sim.do, can be used to open the correct waveform window and run the simulation.
VHDL Code All VHDL source code, VHDL testbenches, and software files associated with this design are
Download and available. THE DESIGN IS PROVIDED TO YOU "AS IS". XILINX MAKES AND YOU RECEIVE
NO WARRANTIES OR CONDITIONS, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE,
Disclaimer AND XILINX SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF
MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR A PARTICULAR PURPOSE.
This design should be used only as an example design, not as a fully functional core. XILINX
does not warrant the performance, functionality, or operation of this Design will meet your
requirements, or that the operation of the Design will be uninterrupted or error free, or that
defects in the Design will be corrected. Furthermore, XILINX does not warrant or make any
representations regarding use or the results of the use of the Design in terms of correctness,
accuracy, reliability or otherwise.
THIRD PARTIES INCLUDING MOTOROLA MAY HAVE PATENTS ON THE SERIAL
PERIPHERAL INTERFACE (SPI) BUS. BY PROVIDING THIS HDL CODE AS ONE POSSIBLE
IMPLEMENTATION OF THIS STANDARD, XILINX IS MAKING NO REPRESENTATION THAT
THE PROVIDED IMPLEMENTATION OF THE SPI BUS IS FREE FROM ANY CLAIMS OF
INFRINGEMENT BY ANY THIRD PARTY. XILINX EXPRESSLY DISCLAIMS ANY
WARRANTY OR CONDITIONS, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, AND
XILINX SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
NON-INFRINGEMENT, OR FITNESS FOR A PARTICULAR PURPOSE, THE ADEQUACY OF
THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTY OR
REPRESENTATION THAT THE IMPLEMENTATION IS FREE FROM CLAIMS OF ANY THIRD
PARTY. FURTHERMORE, XILINX IS PROVIDING THIS REFERENCE DESIGNS "AS IS" AS A
COURTESY TO YOU.
XAPP386 - ftp://ftp.xilinx.com/pub/applications/refdes/xapp386.zip
Conclusion This document has detailed the design of a Serial Peripheral Interface Master design for a
CoolRunner-II CPLD. Though the design has been extensively verified in simulations, Xilinx
assumes no responsibility for the accuracy or the functionality of this design.
Revision The following table shows the revision history for this document.
History
Date Version Revision
12/12/02 1.0 Initial Xilinx release.
R
Design of a Digital Camera with
CoolRunner-II CPLDs
XAPP390 (v1.1) September 27, 2005
Summary This document describes a digital camera reference design using a CoolRunner-II™ CPLD.
The low power capabilities of CoolRunner-II CPLD devices make them the ideal target for
portable, handheld applications such as digital cameras. The complete reference design is
available for download in “VHDL Code,” page 126.
Introduction Digital cameras have become increasingly popular over the last few years. Digital imaging
technology has grown to new markets including cellular phones and PDA devices. With the
diverse marketplace, a variety of imaging technology must be available. Imaging technology
has expanded to include both charge-coupled device (CCD) and CMOS image sensors.
One of the leaders today in digital imaging technology is Micron Technology, Inc. The products
available from Micron include CMOS image sensors that range from CIF-size to 1.3 megapixel
sensors that achieve CCD quality images. For more information on Micron Technology refer to
“References,” page 127.
Video Formats
Until recently, most video equipment was designed for analog video. Today, digital video has
become increasingly available in consumer applications. The most common digital video
formats include RGB and YCrCb. RGB is the digital version of the analog RGB signal, while
YCrCb is the digital version of analog YUV and YPbPr video signals.
The structure of a video stream is actually a series of still images or frames. Video is measured
by frames per second or fps. Typical video is about 60-70 fps. Each frame is composed of lines
of data. The size of an image is determined by the number of lines per frame and the number
of data pixels in each line. For instance, a VGA size image is 480 lines of data that contain 640
pixels of data in each line. So the corresponding VGA image size is 640 x 480 = 307,200 pixels.
For more information on digital video formats refer to “References,” page 127.
Digital Imaging
CMOS vs. CCD
A CMOS or CCD image sensor provides the technology to digitally capture an image and/or
streaming video. CCD image sensors are used in many high end applications, such as high-
resolution digital cameras. CCD image sensors provide a better picture in low-light
environments over CMOS image sensors, but can be costly to manufacturer and integrate into
a system.
CMOS image sensors draw much less power than CCDs. The digital camera system is able to
run longer on batteries, a major advantage in handheld products. Since CMOS sensors use the
same manufacturing platform as most microprocessors and memory chips, they are easier to
produce and more cost effective than CCDs. CMOS image sensors require a single power
supply for operation and only 20-50 milliwatts per pixel output.
© 2005 Xilinx, Inc. All rights reserved. All Xilinx trademarks, registered trademarks, patents, and further disclaimers are as listed at http://www.xilinx.com/legal.htm. All other
trademarks and registered trademarks are the property of their respective owners. All specifications are subject to change without notice.
NOTICE OF DISCLAIMER: Xilinx is providing this design, code, or information "as is." By providing the design, code, or information as one possible implementation of this feature,
application, or standard, Xilinx makes no representation that this implementation is free from any claims of infringement. You are responsible for obtaining any rights you may
require for your implementation. Xilinx expressly disclaims any warranty whatsoever with respect to the adequacy of the implementation, including but not limited to any warranties
or representations that this implementation is free from claims of infringement and any implied warranties of merchantability or fitness for a particular purpose.
Introduction
Micron MI-SOC-0343
The image sensor utilized in this digital camera reference design was manufactured by Micron
Technology, Inc. The MI-SOC-0343 is a complete CMOS image sensor camera-on-chip
solution. The MI-SOC-0343 incorporates an "active pixel" sensor architecture core, plus a
digital image processor or IFP. The MI-SOC-0343 can output digitally processed RGB or
YCrCb data. This CMOS image sensor is a 640 x 480 VGA size sensor and has over 100
programmable registers for customizing. Figure 1 illustrates a block diagram of the MI-SOC-
0343 image sensor.
Serial Interface
(SCLK, SDATA) X390_01_090303
Introduction
approximately 25% of the die area. The "active pixel" architecture developed by Micron
eliminates background noise and prevents image effects such as "line streaking".
Bayer CFA
Each photosite in the "active pixel" sensor array can detect light. It is necessary, however, to
distinguish between colors. The Bayer Color Filter Array (or CFA) was invented to
independently measure red, green, and blue photons. The Bayer CFA is an repeating 2x2
matrix in the image array to measure each color. Diagrams in Figure 3 illustrate aspects of the
Bayer CFA.
G R G R G R G R
B G B G B G B G
G R G R G R G R
B G B G B G B G
G R G R G R G R
B G B G B G B G
Introduction
PIX_CLK
FRAME_VALID
LINE_VALID
LCD Technology
In a digital camera design, the captured image from the sensor may be stored in a memory
component. It is necessary to send this image data to either a peripheral device or a display. In
a digital camera application, an LCD or liquid crystal display is the desired solution. The best
display for video applications is a color active matrix TFT (or thin film transistor). Most TFT
modules offer display resolution with sub-pixels. This allows each pixel to individually display
three colors per pixel or each red, green, and blue color.
The two main types of LCD polarization include: transmissive or transflective. Transmissive
LCDs require a backlight that allows light to shine through the back of the LCD and activate
CoolRunner-II Design
pixels in the display. Transflective LCDs have a specific type of backing that allows light to
shine through the back of the LCD as well as reflect light from the front of the LCD.
Most TFT LCDs have integrated IC drivers that connect in a grid pattern to access all pixels in
the display. With this type of integration, the LCD can be driven through a digital parallel data
interface.
The LCD selected in this CoolRunner-II digital camera reference design is manufactured by
Optrex of America, Inc. For more information on Optrex refer to “References,” page 127. The
display in this reference design is part # T-51382D064J-FW-P-AA. This display is an 6.4"
transmissive color active matrix TFT. The display has an integrated driver and is accessible
through a parallel 6-bit RGB data interface. The display resolution is VGA size or 640 x (RGB)
x 480. This Optrex display is a dual CCT or cold cathode tube display. A block diagram of the
Optrex 51382 device is shown in Figure 5.
Timing CCT
Logic
Vertical IC Driver
Horizontal IC Driver
LCD Panel
(640 x 480)
CCT
X390_05_090303
CoolRunner-II The complete CoolRunner-II digital camera reference design is shown in Figure 6. The
Design CoolRunner-II CPLD is the central controller for the camera design. The CPLD is responsible
for capturing data from the Micron image sensor, storing the image data in SRAM, and sending
the image data to the Optrex display. The CPLD is also responsible for initializing the Micron
image sensor through a configurable register set. The CPLD is also responsible for generating
the PWM pulse that controls the brightness of the Optrex LCD. An inverter controls the voltage
applied to the CCT of the Optrex display.
CoolRunner-II CPLD
SRAM
X390_06_090303
CoolRunner-II Design
IDLE
ship_init_done = '0'
WAIT_SHIP_INIT
ship_init_done = '1'
GET_DATA
get_data_done= '0'
WAIT_IMAGE_DATA
get_data_done= '1'
LCD_DATA
lcd_done = '0'
DONE
lcd_done = '1'
X390_07_090303
CoolRunner-II Design
SCLK
SDATA
Refer to the MI-SOC-0343 data sheet for a detailed description of all available registers on the
image sensor. Table 1 lists a few of the registers that were utilized in this CoolRunner-II digital
camera implementation.
Figure 9 illustrates the main components that generate the SHIP interface logic. Upon a system
reset, the SHIP interface logic starts to configure the desired registers in the MI-SOC-0343
device. The registers to write in the MI-SOC-0343 are determined at configuration time of the
CPLD. All register addresses and data are stored in the CPLD by building a ROM type structure
in the PLA (or programmable logic array) of the CoolRunner-II architecture. The SHIP_TOP
state machine shown in Figure 9 will sequence through each register write. The
CoolRunner-II Design
SHIP_INTERFACE block shown in Figure 9 controls the generation of SCLK and SDATA on the
SHIP serial communication.
ship_init_done
mi_pixclk
sys_reset
MI-SOC-0343
SHIP_INTERFACE
SCLK ship_addr (7:0)
Imager Core SHIP ship_data (15:0) SHIP_TOP
Register Set State Machine State Machine
SDATA ship_start
ship_done
IFP Register Set SHIFT8
UPCNT4
UPCNT8
X390_09_090303
CoolRunner-II Design
ship_start control signal. When the SHIP_INTERFACE logic has completed the single register
write, the ship_done flag is asserted.
sys_reset = RESET_ACTIVE
IDLE
sys_reset \= RESET_ACTIVE
ship_done = '1'
WR_IFPn
ship_done = '0'
ship_done = '1'
WR_IFP01
ship_done = '0'
ship_done = '1'
ship_done = '1'
WR_ICn
ship_done = '0'
DONE
X390_10_090403
CoolRunner-II Design
SHIP_INTERFACE block starts each register write with the assertion of ship_start. When
complete, the ship_done flag is asserted back to the SHIP top level logic.
detect_start = '0'
IDLE
detect_start = '1'
bit_qout = BIT_COUNT
WAIT_ACK_MI_ADDR
bit_qout = BIT_COUNT
WAIT_ACK_REG_ADDR
bit_qout = BIT_COUNT
WAIT_ACK_UDATA
bit_qout = BIT_COUNT
WAIT_ACK_LDATA
DONE
X390_11_090403
When the SHIP Control Logic has completed writing all necessary registers, the ship_init_done
flag is asserted back to the Main Control Logic state machine.
CoolRunner-II Design
state machine will generate the necessary 100 KHz SCLK based on the 13 MHz frequency of
the image sensor pixel clock. Figure 12 illustrates the SCLK_GEN state machine.
gen_start = '0'
IDLE
gen_start = '1'
clk_qout = START_HOLD
SCLK_LOW_EDGE
clk_qout = LOW_SCLK
SCLK_HIGH_EDGE
clk_qout = HI_SCLK
clk_qout = TBUF
X390_12_090403
The Main Control Logic asserts the get_frame_data control signal to the Image Grabber
Control Logic to capture a single image from the sensor and store the data in SRAM. The timing
CoolRunner-II Design
for capturing an image is shown in Figure 4, page 112. The state machine logic for capturing an
image is shown in Figure 14.
get_frame_data = '0'
IDLE
get_frame_data = '1'
fv_edge_detect = '0'
WAIT_FV
fv_edge_detect = '1'
mi_line_valid = '0'
CAP_FV
mi_frame_valid = '0'
mi_line_valid = '1'
DONE
CAP_LDATA
CAP_UDATA
mi_line_valid = '1'
Table 2 below describes the functionality of each state in the Image Grabber state machine.
CoolRunner-II Design
timing on control signals could create image flicker, image scrolling, or partial image display.
The control signals for the Optrex LCD are shown in Table 3.
The Optrex LCD TFT is compatible with four types of VGA timing. The various modes are VGA-
480, VGA-400, VGA-350, and freedom mode. The polarization of HSYNC and VSYNC
determine the VGA timing. In this reference design, the VGA-480 mode is utilized. Table 4
indicates the LCD mode based on polarization of VSYNC and HSYNC.
The sample clock, CLK, frequency for the Optrex LCD is typically 25 Mhz. In this CoolRunner-
II reference design, the LCD clock frequency is 6.6 MHz or 150 ns clock period. The timing
parameters shown below in Table 5 and Table 6 will vary based on LCD clock frequency. The
values shown correspond to a clock frequency of 6.6 MHz.
The horizontal (or HSYNC) and vertical (or VSYNC) timing for the LCD must be given special
consideration. If the timing parameters shown below are not met, the image will not display
correctly on the LCD. Effects such as image scrolling or partial image display will occur.
Horizontal Timing
Table 5 and Figure 15 illustrate the horizontal timing specifications for HSYNC. The back porch
and front porch times are with respect to the assertion of DENB. When DENB is asserted, data
is shifted into the LCD at each rising edge of the LCD CLK.
CoolRunner-II Design
For clarification, each timing parameter in Table 5 is assigned a letter shown in Figure 15.
HSYNC
(active low)
DENB
A B C D
tHP
X390_15_090403
Vertical Timing
Table 6 and Figure 16 below describe the vertical timing parameters for VSYNC. The VSYNC
back porch time is with respect to the rising edge of DENB for the first line of image data. The
VSYNC front porch parameter is with respect to the falling edge of DENB on the last line of
image data. Note the assertion time of DENB in Figure 16 is for shifting data on all lines to the
LCD.
The letters in Table 6 correspond to each timing parameter shown in Figure 16.
VSYNC
(active low)
DENB
A B C D
tVP
X390_16_090403
Another critical timing parameter on the LCD is the phase difference between active edges of
VSYNC and HSYNC. This timing parameter is indicated as tVH and shown in Figure 17. The
CoolRunner-II Design
minimum value of tVH is one clock cycle. The maximum value of tVH is (tHP - 1) clock cycles,
where tHP is the number of clock cycles to shift in an entire line of data.
VSYNC
(active low)
HSYNC
(active low)
tVH X390_17_090403
lcd_clk
VBP_CNT CCT
(UPCNT17) lcd_vsync
LCD Interface lcd_hsync
State Machine
CLK_CNT lcd_denb Optrex 51382
(UPCNT17) lcd_red (5:0)
led_green (5:0)
LINE_CNT lcd_blue (5:0) CCT
PWM
(UPCNT10) Control Logic
Period Width pwm_out
HBP_CNT K2607 Inverter
Counter Counter
(UPCNT6)
X390_18_090403
CoolRunner-II Design
The LCD state machine logic is shown below in Figure 19. The LCD state machine generates
all the control signals to the Optrex LCD.
lcd_start = '0'
IDLE
lcd_start = '1'
clk_cnt_qout = T_VPW
VSYNC_LOW_EDGE
clk_cnt_qout = T_VH
HSYNC_LOW_EDGE
clk_cnt_qout = NUM_COL
WAIT_THBP
hbp_cnt_qout < T_HBP LINE_DONE
clk_cnt_qout = T_HPW
HSYNC_HIGH
line_cnt_qout < NUM_LINES
line_cnt_qout = NUM_LINES
clk_cnt_qout = T_VFP
DONE
X390_19_090403
CoolRunner-II Design
PWM Logic
The PWM Logic of the CPLD is responsible for generating a pulse width modulated (or PWM)
signal. The PWM signal controls the brightness of the LCD as an input to a DC to AC inverter.
The PWM signal is an input to the ERG K2607 low profile DC to AC inverter that is designed
specifically for the Optrex T51382 LCD. The overall period of the PWM signal should be
approximately 5 ms, while the width (or active high time) can vary from 5% to 100% of the
signal period. The K2607 inverter powers the dual cold cathode tubes (or CCT) of the Optrex
LCD.
The PWM Logic in the CPLD mainly consists of two counters, a PERIOD counter and a WIDTH
counter. The PERIOD counter counts the full cycle length of the PWM signal, while the WIDTH
CoolRunner-II Implementation
counter controls the active high time of the PWM signal. Figure 20 illustrates the PWM signal
generation.
+ Vin
PWM
signal
0V
WIDTH
counter
PERIOD counter
(app. 5 ms) X390_20_090403
Verification
The digital camera design functionality has been verified in functional simulation, post route
timing simulation, and in hardware implementation. Test benches are provided in the VHDL
code download pack.
VHDL Code THIRD PARTIES MAY HAVE PATENTS ON THE CODE PROVIDED. BY PROVIDING THIS
CODE AS ONE POSSIBLE IMPLEMENTATION OF THIS DESIGN, XILINX IS MAKING NO
REPRESENTATION THAT THE PROVIDED IMPLEMENTATION OF THIS DESIGN IS FREE
FROM ANY CLAIMS OF INFRINGEMENT BY ANY THIRD PARTY. XILINX EXPRESSLY
DISCLAIMS ANY WARRANTY OR CONDITIONS, EXPRESS, IMPLIED, STATUTORY OR
OTHERWISE, AND XILINX SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF
MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR A PARTICULAR PURPOSE,
THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY
WARRANTY OR REPRESENTATION THAT THE IMPLEMENTATION IS FREE FROM
CLAIMS OF ANY THIRD PARTY. FURTHERMORE, XILINX IS PROVIDING THIS
REFERENCE DESIGN "AS IS" AS A COURTESY TO YOU.
XAPP390 - http://www.xilinx.com/products/xaw/coolvhdlq.htm
Conclusion CoolRunner-II CPLDs are low power devices targeted to portable, handheld electronics such
as digital cameras. This reference design illustrates the complexity of logic that can be fit into a
CPLD. This digital camera solution using CoolRunner-II CPLD to provide seamless integration
between an image sensor, memory, and a LCD.
References
Additional Information
Resolution - Expressed as the number of pixels counted horizontally by the number of pixels
counted vertically. It can be expressed as one of the following formats: QVGA (320 x 240), VGA
(640 x 480), SVGA (800 x 600), XGA (1024 x 768) UXGA (1600 x 1200).
RGB - (Red, Green and Blue) The color system used in most digital cameras in which the
image is separated by capturing the red, green, and blue light separately and then are re-
combined to create a full color image.
Saturation - The degree to which a color is undiluted by white light. If a color is 100 percent
saturated, it contains no white light. If a color has no saturation, it is a shade of gray.
TFT - (Thin Film Transistor) The type of hi-resolution color LCD screen used in many digital
photography cameras.
VGA - An image resolution of 640 x 480 pixels.
Y,U,V - PAL luminance & color difference components. U and V are the names of the B-Y and
R-Y color differences signals (respectively) when they are modulated onto subcarrier.
YPbPr - YPbPr represents component video connections, where luminance (Y) is represented
by a green jack, separate from the color components blue (Pb) and red (Pr). Most high-
definition sets today support this format. These colors should not be confused as RGB output.
Revision The following table shows the revision history for this document.
History
Date Version Revision
04/27/04 1.0 Initial Xilinx release.
09/27/05 1.1 Fixed links in Additional Information
R
CompactFlash Card Interface for
CoolRunner-II CPLDs
XAPP398 (v1.0) September 23, 2003
Summary This application note describes the card-side implementation of an 16-bit CompactFlash (CF+)
card interface using a CoolRunner™-II CPLD. Included in this implementation are the CIS,
Attribute Memory Control and Status Registers, 16-bit Common Memory, and 8-bit I/O
Interface. This design can be easily modified to interface to any memory, DSP or
microcontroller. This application note does not describe the Host Bus Adapter (HBA) side of the
CompactFlash interface, which is resident on a host system such as a Personal Computer or
PDA.
Introduction There are two types of CompactFlash devices: CompactFlash Storage Cards (CF), and CF+
Cards. CF consists only of common memory data storage whereas CF+ is expanded to include
I/O devices or magnetic disk data storage, depending on the specific application. This
application note targets the CF+ type of device. There are three basic modes of operation
called for in the CF specification. Typically, CF+ devices operate in two of the three basic
modes: PC Card ATA using I/O Mode, and PC Card ATA using Memory Mode. The third,
optional mode is True IDE Mode. CF cards are required to operate in all three modes. This
application note implements the CF+ card side interface utilizing PC Card ATA using I/O Mode
and PC Card ATA using Memory Mode. True IDE Mode is not addressed in this application
note, but can be implemented by the designer using the CoolRunner-II CPLD and this
reference design.
The CompactFlash interface consists of two main components: the Host Bus Adapter (HBA)
and the card side interface. The former resides on the host side of the interface, which typically
is built into the socket of a personal computer or Personal Digital Assistant (PDA). The card side
interface resides on the CF card itself. Described in this application note is the implementation
of a controller which resides in the card side of the interface.
Within the card, there is Attribute Memory, Common Memory, and I/O Interface. Attribute
memory consists of the Card Information Structure (CIS) and the Configuration and Control
Registers. Common Memory, in this reference design, interfaces to the Intel StrataFlash
28F320J3 memory. The I/O logic interfaces to the Analog Devices, Inc. ADSP-218xN Series
DSP using the 8 bit I/O Space of the DSP.
In this implementation, the CF+ interface is a 16-bit data bus. The I/O interface within the card
consists of an 8-bit bus to the DSP.
It is necessary to refer to the CompactFlash Specification and the PCMCIA Specification to fully
understand the discussion in this application note.
A free downloadable zip file containing the VHDL source code and a testbench for this
reference design is available as described below in Source Code Download, page 147.
© 2003 Xilinx, Inc. All rights reserved. All Xilinx trademarks, registered trademarks, patents, and further disclaimers are as listed at http://www.xilinx.com/legal.htm. All other
trademarks and registered trademarks are the property of their respective owners. All specifications are subject to change without notice.
NOTICE OF DISCLAIMER: Xilinx is providing this design, code, or information "as is." By providing the design, code, or information as one possible implementation of this feature,
application, or standard, Xilinx makes no representation that this implementation is free from any claims of infringement. You are responsible for obtaining any rights you may
require for your implementation. Xilinx expressly disclaims any warranty whatsoever with respect to the adequacy of the implementation, including but not limited to any warranties
or representations that this implementation is free from claims of infringement and any implied warranties of merchantability or fitness for a particular purpose.
5.0V operation. The core power supply to the CPLD, therefore, must be regulated on the CF+
card to 1.8V while the I/Os must be configured to operate at 3.3V as described in the following
section. For the specific application, if 1.8V regulation is not available or the I/Os will be
subjected to 5.0V, consider using the CoolRunner XPLA3 CPLD, which is a 5V tolerant 3.3V
device and therefore will not require the additional power regulation. I/O considerations for the
CoolRunner-II CPLD are discussed in the following section.
To indicate to the host that the CF+ card is expecting 3.3V signaling, -VS1 must be held at
GND. The signal -VS2 is reserved by PCMCIA for a secondary voltage and therefore must be
left open. These two signals are not implemented in this application note and therefore must be
electrically considered external to the CPLD on the PCB by the designer.
CF+ devices that are configured for 3.3V operation are limited to 75mA max (Power Level 0) or
500mA max. (Power Level 1). Further, during power up and after reset, the CF+ card is limited
to Power Level 0. To assist the designer with more efficiently utilizing the CF+ power budget,
CoolRunner-II CPLDs are the perfect choice since these devices exhibit very low static and
dynamic current consumption.
I/O Considerations
Inputs
The CompactFlash specification calls for three basic types of input configurations in the Pin
Assignments and Pin Type description: IxZ, IxU and IxD. "I" represents the pin is an input, "Z"
represents an input with no resistive termination, "U" represents a weak pullup termination, and
"D" represents a weak pulldown termination. These three configurations are also specified with
one of three electrical characteristics which is denoted by a number 1, 2 or 3 in the "x" position
of the designation. The three numbers correspond to various input threshold levels for the type
of input required. Details of these values and configurations can be found in the CompactFlash
specification.
Outputs
Similarly, the CF+ specification calls for three basic types of output configurations: OTx, OZx,
OPx, and ONx. "O" designates the signal to be an output, "T" represents a totem pole type
output, "Z" a CMOS P-channel/N-channel output with 3-state capabilities, "P" a PMOS only
output, and "N" an NMOS only output. These also have three electrical characteristics denoted
by 1, 2, or 3 in the "x" position of the designation. These three values represent VOH and VOL
levels under certain test conditions. All output types also have a 3-state characteristic and,
together with the voltage levels, are described in the CompactFlash Specification.
Implementation
The CF specification calls for 3.3V or 5.0V for the card power supply and I/O signals.
CoolRunner-II devices are 1.8V devices, but have I/O banking capabilities. To implement the
CF+ interface, the CoolRunner-II CPLD I/Os should be configured as 3.3V LVCMOS.
CoolRunner-II CPLDs are not 5V tolerant. However, external circuitry can be used to interface
to 5V systems. See XAPP364. Alternately, CoolRunner XPLA3 CPLDs are 3.3V devices with
5.0V tolerance. If these voltage requirements are an issue for the application, the CF+
implementation can target the CoolRunner XPLA3 CPLD. Since the CF+ card tells the HBA
what voltage it expects, 5.0V is not present on the I/O pins until the HBA determines the
required voltage. CoolRunner-II CPLDs are therefore acceptable for CF+ applications since
5.0V will never be applied to its I/Os, as long as -VS1 and -VS2 are configured correctly.
Since this application note describes the implementation of the two modes PC Card ATA using
I/O Mode and Memory Mode, the I/Os are required to be configured as I1Z, I2Z, I1U, I3U, OZ3,
OT1, and OT3. The CoolRunner-II CPLD can be configured to support all I/O modes with the
following caveats.
I/O configuration I2Z requires that VIH be at a lower voltage than the CoolRunner-II CPLD is
specified in the data sheet. The signal of interest is RESET whose VIH should be analyzed for
the particular application of this CF+ design. If it is determined that the supplied signal is always
high enough to meet the VIH value of CoolRunner-II devices, then this CPLD should be
sufficient. If not, an external buffer with these characteristics must be supplied to satisfy the
system requirements.
I/O configurations OT1 and OT3 require a totem pole type of driver. CoolRunner CPLDs only
provide CMOS type output buffers and therefore cannot explicitly meet these requirements.
Therefore, an external buffer of totem pole type should be implemented to satisfy the CF+
specification. However, CoolRunner-II CPLDs can meet the I/O drive requirements of VOH and
VOL at the specified IOH and IOL test conditions respectively, regardless of CMOS or totem pole
type configuration. Analysis of the particular application is necessary to determine if
CoolRunner-II CPLD I/Os can be used without the use of external totem pole buffers.
CM A10:A0 Common
Memory
(Intel StrataFlash)
Host Bus Adapter (HBA)
A10:A0 CM D15:D0
40MHz
Clock
Compact Flash Card
X398_01_092203
CPLD Implementation
Figure 2 represents an overview of the CF+ controller reference design contained in the CPLD
(as described in this application note). There are two controllers for the three interfaces: CF+
Address Decode and Control Logic (CF+ Card Controller), and I/O Space Address Decode and
I/O Control Logic (I/O Space Controller).
The former controls transactions with the CompactFlash interface and directs data to the
correct locations—more specifically, the Attribute Memory, Common Memory, and the I/O
Space Controller. It also provides the necessary status and control signals required by the HBA
to effectively communicate with the card.
The I/O Space controller interfaces the CF+ card controller with the devices connected to the
I/O Space bus, which is in this case the DSP. To interface more effectively and synchronously
with the DSP, there are three I/O register banks: Address Register, Data Register, and Status
Register.
As mentioned earlier, the Attribute memory is included in the CPLD reference design. The
Attribute Memory, in this case includes the CIS, COR, CSR and PRR, whose functionality is
described later in this document.
80MHz Clock
Address Bus
Control Bus
Data Bus
Control Bus
CIS
0x000
CF+ Interface
I/O Interface
and I/O Space
Control Logic Address Decode I/O A10:A0
(CF+ Controller) and
I/O Control Logic
D15:D8 (I/O Space Controller) I/O Control Bus
D7:D0
Address Bus 10:0 CM A10:A0
Common Memory
Memory Data Bus 15:0 CM D15:D0
CPLD
X398_02_042403
Signal Table 1 displays the pin descriptions of the CoolRunner-II CF+ Interface. Note that according to
Descriptions the CompactFlash specification, some pin names change depending on the card configuration
mode. For these signals, the I/O Mode nomenclature is used in the table, throughout this
document, and in the VHDL source code.
Table 2 describes the pins of the Common Memory Interface to the Intel StrataFlash device.
Similarly, Table 3 indicates pin names and their functions for the I/O Space Interface to the
Analog Devices DSP.
No pin assignments have been forced, leaving it up to the user to custom fit the design per their
requirements.
CF+ Controller All primary control functions for the CF+ interface are contained in the CF+ controller
(cf_plus_control.vhd). The following subsections describe the CF+ controller’s functionality.
Addressing Modes
This CF+ interface consists of a 16-bit data bus, which may or may not be used to its fullest
capabilities, depending on the architecture of the HBA and the host system. Some host
systems can only support 8-bit transfers which therefore requires the HBA to request 8-bit data
bytes from the CF+ card. It is the card controller’s responsibility to provide 8 bits of data to the
HBA. In the case of the 8-bit host, it is the HBAs responsibility to request the upper or lower byte
of a 16-bit data word from the CF card using specific control signals and then sending that data
to the host over the 8-bit data bus in the correct order.
The CF+ implementation in the CPLD reads the control signals (host_addr(0), ce1_n and
ce2_n) from the interface and interprets them in the correct order for providing data over the 8-
bit or 16-bit data bus as required by the HBA. Table 4 describes in detail this interpretation,
which is compliant to the CompactFlash specification. This table references Odd and Even
bytes as described in the CompactFlash specification. The Intel StrataFlash maintains a
nomenclature of High and Low bytes. Table 4 conveniently shows the correlation between
Odd/Even and High/Low nomenclatures.
Currently, I/O Space access is limited to 8-bit in this implementation. If-16 bit I/O Space access
is required, comments have been added throughout the source code to assist the user to this
end. However, 16-bit I/O Space access has not been tested.
During I/O Mode, this pin takes on the ireq_n functionality and masks the rdy/–bsy functionality.
This active LOW signal now indicates that data is ready to be read from the I/O Space (DSP)
Address or Data registers. When new data is placed in the Address or Data registers by the
DSP, ireq_n goes LOW. Once data has been read from these registers by the HBA, ireq_n
returns to its inactive HIGH state.
Since rdy/–bsy status is masked during I/O Mode, the PRR bit 1 must be read to determine the
status of the Common Memory. A change in status of this PRR bit is reflected on the stschg_n
pin, if enabled.
Attribute The Attribute Memory is divided into two basic sections: The CIS and the Configuration
Memory Registers. There are at least six optional Configuration Registers, but this implementation
integrates three of these registers. The CIS may be found in the reference design source file
named cis.vhd. The Attribute Memory may be found in attribute_memory.vhd, but some
associated control signals for this memory space are found in cf_plus_control.vhd.
LevelReq
ireq_n can be set to indicate interrupts on a level or pulse mode basis. Setting this bit HIGH
enables level mode interrupts, whereas setting this bit LOW enables pulse mode interrupts.
Pulse mode is set to 0.5μs per the CompactFlash specification and uses a 6-bit binary up
counter (upcnt6.vhd) to implement the pulse width. This bit is set to zero by reset.
Conf
These 6 bits select the operation mode of the card. The specification states that for
CompactFlash Cards these bits are used for Memory Mapping or I/O Mapping, depending on
the application. But since this implementation is of a CF+ card, the specification states that
these bits specify either Memory Mapping where I/O cycles are ignored (all bits zero), or the
bits are user-defined. The specification also states that multiple function CF+ cards bits 0
through 2 have specific functionality and bits 3 through 5 are reserved for user implementation.
This CF+ implementation handles the Conf bit functionality where an all zeros condition
disables the I/O space and effectively allows for memory mapping only. Also, since single
function CF+ cards use these bits optionally, and since this implementation is of a single
function CF+ card, these bits are not required. However, they have been included for
convenience. All Conf bits are set to zero when a reset condition occurs.
Conf0 enables the I/O space when set HIGH, and disables the I/O function if LOW.
Conf1 is used for Base and Limit Registers, but since these registers are not used in this
implementation, Conf1 is non-functional.
Conf2 enables ireq_n routing. Its functionality depends on the state of Conf0. If Conf0 is HIGH
and Conf2 is HIGH, interrupts from the I/O Space are routed to the ireq_n pin. If Conf0 is HIGH
and Conf2 is LOW, interrupts are disabled. If Conf0 is LOW, Conf2 is undefined.
Conf3 through Conf5 are reserved for user implementation.
Changed
This bit reflects the status of CRdy_Bsy_n and CWProt in the PRR. Note that the functionality
of CWProt is not implemented since WProt (Write Protect) is not supported by the
CompactFlash specification.
When CRdy_Bsy_n is HIGH, indicating Rdy_Bsy_n has changed state, the Changed bit goes
HIGH. Additionally, this bit will drive the stschg_n pin LOW indicating Rdy_Bsy_n has changed
states, but only if the SigChg bit is HIGH and the card is configured to function in the I/O mode.
The Changed bit is reset to zero by a reset condition. Note that this bit is read-only.
SigChg
As a readable and writable bit, SigChg controls whether the stschg_n pin reflects the Changed
bit status. If SigChg is HIGH, the stschg_n pin indicates the status of the Changed bit when the
card is configured with I/O Space. If SigChg is LOW, the stschg_n pin will be held HIGH when
the card is configured with I/O Space.
This bit is reset LOW during a reset condition.
Int
The Int bit reflects the status of an interrupt request from the I/O Space, regardless of the
setting of Conf2, the interrupt enable/disable bit. When HIGH, this bit indicates an interrupt is
pending. The bit will clear when the interrupt has been serviced. This bit is read only and is
reset to zero during a reset condition.
Bits D2, D3, D6 and D7 are not writable. Bits D2 and D3 will be read as logic HIGH, whereas
bits D6 and D7 will be read as a logic LOW.
CRdy_Bsy_n
When Rdy_Bsy_n changes state, this bit is set to a logic HIGH. This bit may also be written to
by the host and is designated as Host_CRdy_Bsy_n in the source files. This bit is set LOW
during a reset.
CWProt
Since write protect is not used as detailed in the CompactFlash specification, CWProt is
unused in the source files and will read logic LOW.
Rdy_Bsy_n
This bit represents the internal state of the rdy/–bsy pin when it has been reallocated as ireq_n
when the card has been configured for I/O Mode. When rdy/–bsy changes states (due to the
cm_sts pin in this implementation), this bit reflects that state. When written HIGH by the host,
this bit acts as a mask so that Host_CRdy_Bsy_n may be written by the Host. Writing to this bit
is by using the MRdy_Bsy_n bit in the source code. This bit is set LOW during a reset condition.
WProt
Since write protect is not used as specified by the CompactFlash specification, this bit and
MWProt are unused in this implementation. This bit is read as a logic LOW.
Common The functionality for the Common Memory space may be found in the reference design source
Memory file named cf_plus_control.vhd.
Common Memory has been implemented assuming an Intel StrataFlash 28F320J3 flash
memory is used. Since there are only 11 address lines on the CF+ interface, there are only 2 kB
of addressable common memory for the card. Common Memory is typically used as a working
memory space which contains mapping of the larger memory arrays found in the I/O Space
using True IDE Mode. Larger memory arrays are not included in this implementation, but can be
added by the user.
The CF+ controller implements all functionality when interfacing the Common Memory. This
includes addressing, byte mode select, reset, memory status, chip select and reset.
Addressing
The Intel StrataFlash memory can be accessed in either 16-bit or 8-bit modes. This works well
with the CompactFlash specification since the interface is accessed by the HBA in either 16-bit
or 8-bit modes. To access the Common Memory, reg_n must be HIGH. By using ce1_n and
ce2_n the 16-bit or 8-bit modes can be selected as required. When in 16-bit mode, cm_addr(0)
is driven HIGH or LOW depending on host_addr(0). When in 8-bit mode with cm_addr(0) HIGH,
the high (odd) byte is accessed from Common Memory. Conversely, when in 8-bit mode,
cm_addr(0) is LOW accessing the low (even) byte of Common Memory. When in 16-bit mode,
cm_addr(0) is ignored by the flash memory. Addresses cm_addr(10:1) are used to specify the
location of the byte or word in memory. Table 9 describes this relationship.
The signal cm_byte_n is used to indicate to the memory that byte mode is selected and is
active LOW.
Memory status is reflected on the ireq_n pin, acting as rdy/–bsy in Memory Mode. This status
is also available in the Rdy_Bsy_n bit of the PRR. The state of rdy/–bsy is directly related to the
cm_sts pin of the Common Memory Interface.
I/O Space Most I/O Space functionality is found in the reference design source file named
dsp_interface.dsp. The interface state machine is located in this file. Some control signals are
located in cf_plus_control.vhd. The pulse mode IRQ requires use of the counter found in
upcnt6.vhd.
For the I/O Space, the CF+ specification states that either 8-bit or 16-bit I/O access is allowable.
This application note describes the implementation of an 8-bit I/O Space as provided in the
reference design. If 16-bit access is required, the reference design can easily be modified to
support this requirement. There are comments placed throughout the source files (VHDL) to
convert the I/O Space to 16-bit access, although 16-bit I/O Space access has not been tested.
Clock
This Compact Flash implementation requires an 80 MHz clock signal to be supplied to the
CPLD. This particular implementation with the Analog Devices ADSP-218xN series DSP, uses
the CLKOUT signal found on the DSP as the clock source. CLKOUT is a signal provided by the
DSP and is double the input clock signal to the DSP found on pin CLKIN. This implementation
assumes a 40 MHz clock on CLKIN of the DSP which subsequently becomes 80 MHz on
CLKOUT. The CPLD requires this 80 MHz signal on the dsp_clk pin to function correctly. If a
different clock speed is required for another implementation, it is recommended that a functional
and post-route simulation be performed to ensure correct functionality is retained.
Although the CF+ interface itself contains no clock, this 80 MHz clock can be used to ensure
proper timing of the interface signals.
Address Register
An 8-bit register is provided to pass address data to the DSP from the HBA, or in the reverse
direction, from the DSP to the HBA.
Data Register
Similarly, the Data Register is an 8-bit register that is used to pass data to/from the I/O Space.
It is read/write capable from both the DSP and the HBA.
Status Register
As a read-only register, Status Register contains information regarding the current Data
Register and Address Register transactions. Table 11 describes the relationship of the bits in
the register. All unused bits (D5:D2) are available for user implementation, as in the case of
inserting additional I/O Space registers.
IRQ_CF
When new data is available in the Data Register or the Address Register given by the DSP, this
bit supplies an interrupt request to the HBA. A HIGH condition triggers an active LOW interrupt
on ireq_n, provided interrupts are enabled in Conf(0) of the COR. An interrupt condition is
recorded in the Int bit of the CSR regardless of the Conf(0) bit state.
To safeguard data in the Address and Data Registers prior to the HBA reading the new data,
the HBA is not permitted to write to these registers until the IRQ_CF bit has cleared. This bit is
cleared when the HBA reads data from either the Address or Data Registers or a card reset has
been performed.
The IRQ_CF bit is found in the reference design source files as io_status_reg(7).
IRQ_DSP
When new data is available in the Data Register or the Address Register given by the HBA, this
bit, in a HIGH state, indicates an interrupt request is pending to the DSP. This reference design
does not utilize an interrupt request pin for the DSP, and therefore, this bit is unused throughout
this implementation. This bit is available only for the purposes of the user if an interrupt request
pin is desired to be added for a specific application.
To safeguard data in the Address and Data Registers prior to the DSP reading the new data,
the DSP is not permitted to write to these registers until the IRQ_DSP bit has cleared. This bit
is cleared when the DSP reads data from either the Address or Data Registers or a card reset
has been performed.
This bit is found in the reference design source files as io_status_reg(6).
DataReg
When the Data Register has been written by either the DSP or the HBA, this bit is set HIGH.
This bit is used to indicate the Data Register has been written when an interrupt has been
detected by the system monitoring interrupts. This bit is cleared when the Data Register has
been read by the target system, or a card reset has been issued.
This bit is found in the reference design source files as io_status_reg(1).
AddrReg
When the Address Register has been written by either the DSP or the HBA, this bit is set HIGH.
This bit is used to indicate the Address Register has been written when an interrupt has been
detected by the system monitoring interrupts. This bit is cleared when the Address Register has
been read by the target system, or a card reset has been issued.
This bit is found in the reference design source files as io_status_reg(0).
State Machine
The I/O Space interface state machine synchronizes the communication between the DSP and
the HBA and relies on the 80MHz clock provided to the CPLD. This state machine consists of
seven states, including the IDLE state. Two basic paths in the state machine are available:
communication initiated by the DSP and communication initiated by the HBA. Figure 3 displays
the flow as described in the following paragraphs.
CF_ADDR DSP_ADDR
io_address_match = 1 dsp_address_match = 1
and dsp_ioms_n = 0
io_read_n_sync = 0 dsp_rd_n = 0
io_address_match = 1
and CF_DATA_READ DSP_DATA_READ dsp_address_match = 1
io_write_n_sync = 0 dsp_ioms_n = 0
dsp_wr_n = 0
io_read_n_sync = 1 dsp_data_done = 1
or
dsp_ioms_n = 1
CF_DATA_WRITE DSP_DATA_WRITE
io_write_n_sync = 1 dsp_data_done = 1
or
X398_03_062003
dsp_wr_n = 1
Figure 3: I/O Space State Machine
IDLE State
The default state upon reset, is the IDLE state. In this state, the machine waits for either the
DSP or the HBA to initiate communications with the I/O Space registers. For a DSP initiated
data transfer, the state machine follows the right hand branch shown in Figure 3, whereas an
HBA data transfer is contained in the left hand path of Figure 3. The signal dsp_ioms_n
represents the ioms_n pin as it is driven by the DSP. The signals io_write_n_sync and
io_read_n_sync are the active low write and read request conditions as driven by the HBA. The
latter two are synchronized to the state machine using the 80 MHz clock.
DSP Read/Write
When a chip select condition has been detected as found on the ioms_n pin, the state machine
transitions to the DSP_ADDR state. During this branch of the machine, no HBA transactions
can occur with the I/O Space registers. The DSP_ADDR state waits for a valid address for one
of the registers in the I/O space. Once a valid address has been detected, the state machine
transitions to the DSP_DATA_READ or DSP_DATA_WRITE state, depending on the status of
the dsp_rd_n and dsp_wr_n pins.
The DSP_DATA_READ state allows data from the I/O space registers to be placed on the DSP
data bus. Once the data has been transferred to the DSP, the state machine transitions to the
IDLE state.
The DSP_DATA_WRITE state permits the DSP to transfer data from the data bus to the register
being addressed. Once data has been captured in these registers, the state machine
transitions to the IDLE state.
HBA Read/Write
When the HBA issues a request for data from the I/O space, as indicated using the
io_write_n_sync and io_read_n_sync signals, and the state machine is in the IDLE state, the
machine branches to the CF_ADDR state. It is in this state that the machine waits for a valid
address from the HBA to access the I/O space registers. Once a valid address has been
detected from the HBA as indicated with io_address_match at a HIGH level, the state machine
transitions to either the CF_DATA_READ_STATE or CF_DATA_WRITE_STATE state. The
signals io_read_n_sync and io_write_n_sync direct the state machine to the respective state
when one of these signals is LOW.
Once in the CF_DATA_READ_STATE state, data is placed from the addressed I/O Space
register to the HBA data bus. Once the HBA has received the data and removed the read
condition from the CF+ interface, the state machine transitions to the IDLE state.
The CF_DATA_WRITE_STATE state allows data to be written to the addressed I/O Space
register from the HBA data bus. After the HBA has written the data and removed the write
condition from the CF+ interface, the state machine moves to the IDLE state.
Source Code The VHDL source code and test benches are available for this design. THE DESIGN IS
Download PROVIDED TO YOU "AS IS". XILINX MAKES AND YOU RECEIVE NO WARRANTIES OR
CONDITIONS, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, AND XILINX
SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, NON-
INFRINGEMENT, OR FITNESS FOR A PARTICULAR PURPOSE. This design has not been
verified on hardware (as opposed to simulations), and it should be used only as an example
design, not as a fully functional core. XILINX does not warrant the performance, functionality, or
operation of this Design will meet your requirements, or that the operation of the Design will be
uninterrupted or error free, or that defects in the Design will be corrected. Furthermore, XILINX
does not warrant or make any representations regarding use or the results of the use of the
Design in terms of correctness, accuracy, reliability or otherwise.
XAPP398 - http://www.xilinx.com/products/xaw/coolvhdlq.htm
To simulate the files included in the download, it is necessary to obtain the VHDL model of the
Intel StrataFlash 28F320J3 memory from the Intel website. To obtain this VHDL model, visit
http://appzone.intel.com/toolcatalog/listtools.asp?pid=5319&cid=683&pfamily=
Disclaimer CompactFlash and CF+ are registered trademarks of CompactFlash Association. Xilinx
provides this reference design as one possible implementation of this standard and claims no
rights to this interface. To use this reference design, you must contact the CompactFlash
Association to obtain any necessary rights associated with this interface.
Conclusion The CoolRunner-II CPLD is the perfect device to use as an interface to a CompactFlash host.
These CPLDs exhibit low power consumption as well as other features that are beneficial to
these cards. Features such as 3.3V I/Os, Schmitt Triggers and DualEDGE clocking allow easy
integration to this type of system as well as provide flexibility to other functions on a
CompactFlash card.
Further Reading CoolRunner-II Data Sheets, Application Notes, and White Papers
Revision The following table shows the revision history for this document.
History
Date Version Revision
09/23/03 1.0 Initial Xilinx release.
R
Interfacing to Mobile SDRAM with
CoolRunner-II CPLDs
XAPP394 (v1.1) December 1, 2003
Summary This document describes the VHDL design for interfacing CoolRunner™-II CPLDs with low
power Mobile SDRAM memory devices. Mobile SDRAM is the ideal memory solution for
wireless, handheld, and mobile computing applications, making this a perfect match with the
Xilinx CoolRunner-II low power CPLD family. The VHDL code described here can be found in
VHDL Code, page 154.
Introduction CoolRunner-II CPLDs are the latest CPLD product offering from Xilinx. CoolRunner-II CPLDs
combine high performance with low power operation. Standby current on CoolRunner-II CPLD
devices is less than 100μA. More information on the CoolRunner-II CPLD family can be found
at http://www.xilinx.com/cr2.
Key features of the CoolRunner-II CPLD family include DualEDGE triggered registers, a global
clock divider, and voltage referenced I/O standards. These features provide the capability to
interface a CoolRunner-II CPLD with low power memory devices such as Mobile SDRAM.
Mobile SDRAM manufacturers include Micron and Samsung with data sheets available in
References, page 154.
Signal It is important to define the connections in this design before describing the CPLD logic to
Definitions interface with the Mobile SDRAM. Table 1 defines the Mobile SDRAM interface signals
described in this document.
© 2003 Xilinx, Inc. All rights reserved. All Xilinx trademarks, registered trademarks, patents, and further disclaimers are as listed at http://www.xilinx.com/legal.htm. All other
trademarks and registered trademarks are the property of their respective owners. All specifications are subject to change without notice.
NOTICE OF DISCLAIMER: Xilinx is providing this design, code, or information "as is." By providing the design, code, or information as one possible implementation of this feature,
application, or standard, Xilinx makes no representation that this implementation is free from any claims of infringement. You are responsible for obtaining any rights you may
require for your implementation. Xilinx expressly disclaims any warranty whatsoever with respect to the adequacy of the implementation, including but not limited to any warranties
or representations that this implementation is free from claims of infringement and any implied warranties of merchantability or fitness for a particular purpose.
Mobile SDRAM Mobile SDRAM devices feature low power technology to meet the needs of handheld
electronics. Additional power savings are achieved with two self-refresh features, temperature-
compensated self-refresh (TCSR) and partial-array self-refresh (PASR).
Read and write accesses to the Mobile SDRAM are burst-oriented, starting at a specific
address. SDRAM is organized in banks, where each data location can be represented with a
row and column address. Each access must begin with an ACTIVE command followed by the
READ or WRITE operation. The ACTIVE command selects the bank and row address, while
the individual READ or WRITE command select the column address. The Mobile SDRAM
features AUTO PRECHARGE, in which the row being accessed is initiated with a
PRECHARGE command at the end of the burst sequence.
The operation of the Mobile SDRAM device can be customized by writing different values to the
mode register and extended mode register. Each register allows the designer to set parameters
for interfacing with the memory device.
The following commands are available to execute with Mobile SDRAM devices:
• NOP (Deselect SDRAM device)
• ACTIVE (Opens row in specified bank for access)
• READ (Select bank and column, and start READ burst)
• WRITE (Select bank and column, and start WRITE burst)
• DEEP POWER DOWN (Maximum power savings, data is not retained)
• PRECHARGE (Deactivates open row in specified bank or all banks)
• AUTO REFRESH or SELF REFRESH (Retains data in SDRAM)
• LOAD MODE REGISTER (Defines operating mode of SDRAM)
More information on the Mobile SDRAM devices targeted in this design can be found in
References, page 154.
CPLD Design A CoolRunner-II CPLD is utilized as the controller for interfacing to the Mobile SDRAM memory
device. The CPLD is responsible for interpreting the system level commands and creating the
interface requirements to the Mobile SDRAM. Figure 1 illustrates the main control logic in the
CoolRunner-II CPLD.
CoolRunner-II CPLD
sys_clk sdram_clk
sdram_cke
SDRAM State Machine sdram_csn
sdram_casn
sys_reset
CAS_CNT sdram_rasn
sys_addr [23:0] Mode Register
(UPCNT2) sdram_wen
sys_cmd [3:0]
WR_BRST_CNT RD_BRST_CNT
sdram_ba [1:0]
(UPCNT4) (UPCNT4)
sdram_a [12:0]
sdram_read_en
sdram_write_en
sys_data [15:0] sdram_ldqm
Data Control Logic sdram_udqm
sdram_dq [15:0]
X394_01_021003
The system level interface is illustrated in this design as an example interface. This system
interface example is an asynchronous communication, with the signals registered in the CPLD.
The SDRAM state machine is the main controller in this design and is responsible for
generating the control, data, and address signals to the Mobile SDRAM device. The SDRAM
state machine also asserts control signals that are used internally by the CPLD for
reading/writing data and generating the SDRAM address signals. The SDRAM state machine
in this design utilizes a 2-bit counter for waiting the CAS latency in a READ cycle, and two 4-bit
counters, one for the length of a WRITE cycle burst and one for the length of a READ cycle
burst.
A detailed description of the SDRAM state machine is illustrated in Figure 2. The SDRAM state
machine remains in the IDLE state waiting for the next instruction to execute. The next
instruction to execute is interpreted from the system command bus, sys_cmd. In this design,
AUTO PRECHARGE is utilized, where an ACTIVE command must be issued prior to any READ
or WRITE operation.
PRECHRG_ST
DPD_ST sys_cmd = DEEP_PD
ACTIVE_ST
sys_cmd = READ sys_cmd = WRITE
WAIT_READ_ST WAIT_WRITE_ST
READ_ST WRITE_ST
WRITE_DATA_ST
CAS_DELAY_ST
wr_brst_qout = BURST_LEN
cas_qout = CAS_LAT
X394_02_021003
The function of each state in the SDRAM state machine is described in Table 2.
Device Utilization
The SDRAM interface design utilizes a CoolRunner-II XC2C128-4TQ144 device. The system
interface, SDRAM state machine, and SDRAM interface logic fits into this device with the
utilization results shown in Table 3.
System Interface
The SDRAM design described in this document includes a generic system interface. The
system interface illustrates the basic control signals needed for the SDRAM logic block. These
signals include a system clock, reset, 24-bit address bus, 16-bit data bus, and 4-bit command
bus. Excluding the system clock, all signals are asynchronous and registered in the CPLD.
Modeling of the system interface in this design is done with testbench logic. The testbench is
responsible for generating the address, data and command signals for any operation with the
Mobile SDRAM device. The testbench controls the initialization requirements, single read/write
operations, and tests the power down modes of the SDRAM.
VHDL Code THIRD PARTIES MAY HAVE PATENTS ON THE CODE PROVIDED. BY PROVIDING THIS
CODE AS ONE POSSIBLE IMPLEMENTATION OF THIS DESIGN, XILINX IS MAKING NO
REPRESENTATION THAT THE PROVIDED IMPLEMENTATION OF THIS DESIGN IS FREE
FROM ANY CLAIMS OF INFRINGEMENT BY ANY THIRD PARTY. XILINX EXPRESSLY
DISCLAIMS ANY WARRANTY OR CONDITIONS, EXPRESS, IMPLIED, STATUTORY OR
OTHERWISE, AND XILINX SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF
MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR A PARTICULAR PURPOSE,
THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY
WARRANTY OR REPRESENTATION THAT THE IMPLEMENTATION IS FREE FROM
CLAIMS OF ANY THIRD PARTY. FURTHERMORE, XILINX IS PROVIDING THIS
REFERENCE DESIGN "AS IS" AS A COURTESY TO YOU.
XAPP394 -ftp://ftp.xilinx.com/pub/applications/refdes/xapp394.zip
Conclusion CoolRunner-II CPLD devices are the perfect compliment to low power Mobile SDRAM memory.
These two low power devices are targeted for handheld, mobile computing applications.
CoolRunner-II CPLD devices feature low power consumption and create a seamless interface
to Mobile SDRAM memory.
References 1. Micron Data Sheet. MT48V16M16LFFG 256Mb: x16 Mobile SDRAM. Micron Technology,
Inc. 2002.
2. Micron Technical Note. TN-48-10. Mobile SDRAM Power-Saving Features. Micron
Technology, Inc. 2002.
3. Samsung Data Sheet. K4S64163LF-RG/S 4Mx16 Mobile SDRAM. Rev 1.0. Samsung
Electronics 2002.
Revision The following table shows the revision history for this document.
History
Date Version Revision
09/23/03 1.0 Initial Xilinx release.
12/01/03 1.1 Errata
Summary Today’s microcontrollers and microprocessors often limit the number of General Purpose I/O
(GPIO) ports in order to conserve pin count and to reduce package sizes. Unfortunately, for
many designs, the number of I/O ports required exceeds the number of available I/O ports on
a microprocessor. Hence, Complex Programmable Logic Devices (CPLDs) can often be found
in a system alongside a microcontroller functioning as a port expander. This Application Note
presents a design of a port expander that fits into a CoolRunner™-II XC2C32A device -- A port
expander that is SMBus and I2C compatible.
CoolRunner-II A key advantage of using any Xilinx CPLD as a port expander is the integration of logic
Advantages functions across the entire board. The flexibility of programmable fabric allows for a variety of
dissimilar functions to be implemented on one chip. A CPLD can be used as a port expander,
an LED driver, an address decoder and a memory controller, all at once.
CoolRunner-II devices add further value being the lowest cost and lowest power CPLDs on the
market. These CoolRunner-II parts also provide I/O Banking capability, allowing for level
translation between the microcontroller and its external peripherals. Both features are favorable
for an SMBus or I2C design, as these environments are typically multi-voltage environments
requiring low power.
Table 1 summarizes the level translation abilities of the CoolRunner-II family.
Using the The port expansion reference design shown in Figure 1 provides 8 output ports and 8 input
CoolRunner-II ports controlled through an I2C compatible serial interface. This design is scalable. The code
can be modified to increase or decrease the number of desired output ports and input ports.
SMBus/I2C Port This section describes the default code implementing 8 outputs and 8 inputs. The fully working
Expander
Design
© 2005 Xilinx, Inc. All rights reserved. XILINX, the Xilinx logo, and other designated brands included herein are trademarks of Xilinx, Inc.
All other trademarks are the property of their respective owners.
CoolRunner-II
top.v
XC2C32A
i2c_module_mod.v
sda_in
8-bit Shift Register
shift_data_in
data_in[7:0]
ack_out
out_en external
pull_up
sda_out
i2c pld_sda_out
INDEX Start START
STATE DECODE
COUNTER
MACHINE LOGIC
scl
pld_i2c_scl
latch_data_out
gpio_input[1:0]
latch_data_in
data_in[7:0]
8 2
GP10_OUTPUT GP10_INPUT
(8 BITS) (2 BITS)
reset goes 8 2
to all
blocks
i2c_rst
pld_i2c_rst
GPIO_OUTPUT_PINS[7:0] GPIO_INPUT_PINS[2:0]
x799_01_071305
Serial Interface
This port expander design uses a serial data line (SDA) and a serial clock line (SCL) to achieve
bidirectional communication with a master. The master, typically a microcontroller or
microprocessor, initiates all data transfers to and from the CPLD. The master is also
responsible for generating the SCL clock that synchronizes the data transfer.
Each transaction consists of a start condition sent by a master, followed by the CPLD’s
predefined 7-bit slave address plus an R/W bit, and one data byte that is either transmitted from
the master to the CPLD (for a write operation) or one data byte that is transmitted by the CPLD
to the master (for a read operation). An Acknowledge bit is used at the end of each data byte,
and data is transferred on every rising clock pulse.
Start Condition
Both SCL and SDA remain high when the interface is inactive. The master signals the start
condition by transitioning SDA from high to low while SCL is high (Figure 2). Once a start
condition is recognized by the CPLD, an internal ‘start’ pulse is generated, and the state
machine will begin.
Acknowledge
The acknowledge bit is sent every 9th bit, indicating receipt of each data byte. Each byte
transferred effectively requires 9 bits. The master generates the 9th clock pulse, and the
recipient pulls down SDA during the acknowledge pulse. This means that when the master is
transmitting to the CPLD, the CPLD generates the acknowledge bit. When the CPLD is
transmitting to the master, the master generates the acknowledge bit.
dictating the values on the GPIO output ports. On the 9th clock cycle, the CPLD acknowledges
this second data byte, and sets the GPIO output pins accordingly.
Standby
The CoolRunner-II family of CPLDs automatically enters "standby" when all pins are set to Vcc
or GND. Standby current is specified in the individual device data sheets. This design fits into
an XC2C32A device, which has a typical standby number of 22 uA -- ideal for SMBus and I2C
applications.
Utilization
The following are the utilization statistics:
Customizing This reference design can be customized to fit any specific design target. If the design requires
the Design more GPIOs, the state machine in the source code can be modified accordingly. Should
bidirectional I/O’s be required, the design can be modified to use the R/W bit as a signal to
decode whether the I/O pin should function as an input or output. There are many possibilities,
and the source code has been written for the most general case.
Conclusion This port expander design can be used as a complete turnkey design that fits readily into a
CoolRunner-II XC2C32A device. You can easily edit the port expansion module to fit your
needs, and additional functionality can be integrated into the CPLD. The CoolRunner-II family
of CPLDs is unique in that it is the only low cost, easy to use, low power device available today.
Revision The following table shows the revision history for this document.
History
Date Version Revision
07/19/05 1.0 Initial Xilinx release.
08/02/05 1.1 Fixed broken link to design files.
Revision History
Summary Light-Emitting Diodes (LEDs) are commonplace on the modern day Printed Circuit Board
(PCB). Whether they are indicating status, activity or some other function, they need to be
driven by a device that can provide sufficient current to illuminate them. Traditionally, LED driver
devices have been used for this purpose, but this application note aims to demonstrate how
that functionality can be incorporated into Xilinx CPLDs to save both cost and valuable board
space.
Introduction Specific driver devices are commonly used to drive common-anode LEDs, including seven
segment displays. Figure 1 shows a typical configuration. The output pin of the driver device
connects to the cathode of the LED, and the anode is connected to VCC. When a low signal is
applied to the output, the driver sinks current and the LED illuminates. Each LED will require a
different threshold current to illuminate, but some common examples are found in Table 1
below. As discrete LED Driver ICs integrate more features, their costs rise.
Vcc
LED
LED
Driver
Series
Resistor
LED
Xilinx
CPLD Series
Resistor
From Table 2, it is clear that Xilinx CPLDs are ideal for driving LEDs that require up to 8-10 mA
to illuminate.
LED
Series
Xilinx Resistor
CPLD Series
Resistor
Display Drivers
Using the example of an 8-digit 7-segment display driver, we can see a typical circuit design in
Figure 4.
Segment Select
8
Digit Select
8
Figure 5 shows how a Xilinx CPLD can be used instead of a discrete display driver. It is very
likely that a Xilinx CPLD will have spare capacity after implementing an LED display driver; this
capacity can be used for other board functions. For example, the functions of other discrete
components on the board can be incorporated into the CPLD. The logic that fills the remaining
capacity of the CPLD does not have to interface at the same level. Because of the split rail
VCCIO available on all CoolRunner-II devices, the CPLD can interface with components of at
least two voltages simultaneously (1.5V, 1.8V, 2.5V or 3.3V). For more information on how to
incorporate discrete components, see White Paper 202. For more information on the use of
split rail I/O banking, see the CoolRunner-II Family Data Sheet.
Discrete Logic
Absorption
VCCIO1 VCCIO2
3.3V 2.5V
I/O Bank 2
I/O Bank 1 Level Shifting
Xilinx CPLD
8 Digit Select
Segment Select
Figure 5: Xilinx CPLD Used as an 8-digit 7-segment Display Driver with Remaining
Capacity Used to Incorporate Discrete Logic and Interface to Different Voltage Levels
Table 3: Output Low Voltage for the XC2C64A (LVCMOS 3.3V and LVTTL 3.3V DC Voltage Specifications Shown)
Symbol Parameter Test Conditions Min. Max. Units
VOL Low Level Output Voltage IOL = 8 mA, VCCIO = 3V - 0.4 V
IOL= 0.1 mA, VCCIO =3V - 0.2 V
These numbers are taken under worst case conditions and, therefore, we can guarantee that
the devices will be able to meet this specification. However, it should also be noted that the
output buffers can probably drive significantly more current than worst case conditions.
To find out how much current the output buffers can typically supply, the I/V curves for the
devices are needed. They can be found in XAPP150 for the XC9500/, XC9500XL, XC9500XV
and CoolRunner XPLA3 families. For CoolRunner-II device I/V curves, look in the individual
CoolRunner-II datasheets. They appear as shown in Figure 6.
Under the typical conditions shown above, it is evident that at 0.4V the output low current (IOL)
is as high as 20 mA. Of course, these numbers are typical and cannot be guaranteed under
all circumstances.
Guidelines for As mentioned earlier, it is possible to tie two or more outputs together to double or triple (and et
Driving Multiple cetera) the drive strength for power hungry LEDs.
LEDs with the If multiple LEDs are to be driven by individual pins on the same CPLD, there are a few
guidelines that may be helpful. These help to reduce the effect of ground bounce due to
Same CPLD multiple outputs switching simultaneously, and hence avoid corrupting the operation of other
devices driven by the CPLD.
• Try to stagger the switching of the outputs. LEDs are almost always used for indicating
status to a human. Human reactions are sufficiently slow that delaying the output
switching by a small amount of time will not be noticable
• Try to skew the switching of the LEDs slightly using the adjustable fast/slow slew rate of
the outputs
• If using an XC9500, XC9500XL, or XC9500XV device, try putting some of the macrocells
into low power mode, and leave others in high frequency mode. This will have the effect of
skewing the switching outputs slightly
• Try to distribute the pins driving LEDs evenly around the device package so as to locate
them next to Ground pins. The individual device datasheet has a listing of the pin locations
on each package.
Conclusion Xilinx CPLDs can easily take the place of discrete LED driver devices. They can deliver
sufficient current to illuminate most LEDs, but if more current is required, multiple outputs can
be tied together. The current drive strength of the different Xilinx CPLDs can be found in the
device data sheets available on the Xilinx website. However, under typical conditions, the Xilinx
CPLDs can output more current.
Additional Information
Revision The following table shows the revision history for this document.
History
Date Version Revision
04/08/05 1.0 Initial Xilinx release.
Quick Look at a Figure 1 shows a fairly straightforward block diagram of a digital-type handset.
Handset
SRAM DRAM
DISPLAY
μproc dsp
Application DUPLEXER
Space
CoolRunner-II EPROM
KEYBOARD
CPLD
In this diagram, we don’t show specific connections between the microprocessor, the
DSP, and the various boxes within the handset. Typically, they are all interconnected.
In fact, some functions may be implemented by either processor. This saves board area
at the expense of processor bandwidth. Let’s assume the microprocessor handles
baseline tasks like managing the display and the keyboard, but the DSP does channel
coding/decoding and other signal processing tasks in the phone. The microprocessor
handles dialing.
Let’s simply look at sending and receiving audio. The microphone delivers audio
signal to the A/D converter, creating a bit-stream. Fidelity and efficiency require
redundancy elimination and compression. This is done in the speech coder (typically
adaptive multirate). Forward Error Correction (FEC) occurs in the channel coder
(Viterbi today, Turbo tomorrow). Coding adds back redundancy, but dropped bits can
be recovered. CDMA channel spreading has been introduced in the U.S. and Korea,
but others may use TDMA, SCDMA or WCDMA. The digital signal finally gets to the
RF modulator and RF amplifier where it becomes one of several signal types (again,
depending on the phone standard). At this point, it is analog. Today, these are in the
gigahertz range and focused on octal phase shift keying. The duplexer is inserted to
switch between receiving and sending at the antenna.
On the receiving end, the signal hits the antenna, slides through the duplexer and is
amplified and demodulated, becoming digital. The Rake Receiver “despreads” the
received bits and forwards the signal to the channel decoder, which reconstructs the
possibly corrupted digital signal and passes it on to the speech decoder. The speech
decoder corrects bit-dropout and should resemble the digital version of the original
analog signal. This forwards to the D/A converter, which, when filtered and
amplified (not shown), drives the earphone.
If the phone is going to support 3G capability, typically it must handle other standards
(2G, 2.5G and GPRS) because different countries are at different levels of deployment.
Why pay for a high-end phone and be able to only use it on the high end systems?
Would you want to carry multiple phones, or should the manufacturer make sure
your super handset just works wherever you are? Given that the latter is the case,
your handset is basically three or four phones, depending on what communication
link you are connecting to. It’s a lot to ask, but 3G isn’t about signaling, quality and
compatibility, as much as it is about applications.
Applications By now, you should have noticed the big box on the right hand side of Figure 1. That
is reserved for advanced applications—things that go beyond making a call. Let's
revise Figure 1 to set the stage for the kinds of things we will need to add applications.
For starters, cell phone standards committees categorize applications according to
parameters like guaranteed bit rate, variable/fixed delay, asymmetric/symmetric
traffic and whether or not buffering is allowed. In terms of words we can relate to,
those categories translate into conversational class, streaming class, interactive class
and background class. These designations are based on the properties of those classes
of applications. For instance, an ordinary conversation cannot tolerate long delays and
echoes, as such things upset users. Lots of image dropout on a video data-stream also
upsets users. So, by thinking through the needs of whole classes of applications,
developers arrive at important quality factors. Listed below are some of potential cell
phone applications; some may cross over more than one of the classes listed above.
Each application has its own particular needs, so it might be appropriate to consider a
few of them individually. For instance, music via MP3 files could be done entirely in
software, the same way that PCs can play files. If the processors are burdened with
channel coding/decoding and possibly with decryption, it might be more feasible to
include an MP3 decoder chip within the phone, or as an add-on. Video movie rental
would probably have the files being downloaded via GPRS and linked through the
Internet. Clearly, vendors renting the files would want to assure their MPEG-4 files
weren’t being delivered to pirates. Vendors would insist on encryption as well as
compression. Adding these to the channel decoding exhausts today’s processors and
drains batteries. There would also be a need for buffering frames, to support dropout
in the Internet protocol. Some applications might require JPEG, MPEG-4, MP3,
encryption and channel coding. This suggests the need for additional offloading logic.
Let’s look at a commercial chipset for doing all of this, and then discuss offloading.
Cell Phone Figure 2 shows an Intel PXA 800F block diagram. Note that this multifaceted chipset is
Chipsets designed to integrate all the key functionality for the baseline, base-band operations,
with a clear focus on using software to handle a broad range of other applications.
PXA800F
JTAG JTAG Intel® Xscale TM Cellular Processor
CTRL Core
External
Memory Interrupt Controller GSM IRQCtrl
Bus I-Cache D-Cache
4MB Flash 512 KB SRAM
Memory Controller
Picking the Figure 3 shows an application that is not on the list—Global Positioning Satellite (GPS)
Right Mix service. It can use the same antenna as the phone receiver/transmitter, but it will drag
the satellite signals into the chip, collect the data and deliver the co-ordinates of your
location to the DSP. Emergency police/ambulance calls need this.
SRAM DRAM
DISPLAY
CoolRunner-II
μproc dsp CPLD GPS DUPLEXER
CoolRunner-II
KEYBOARD EPROM
CPLD
But what about new applications that are not in this group? There are applications yet
to come that we can envision, but whose exact specifications we cannot wholly
anticipate. Designing for their arrival is sometimes called “future proofing.”
It is true that some applications are better served by microprocessor code dropped into
on board EPROM, but that can only happen as long as the processor bandwidth is
available for the application. If this cannot be done, either more processors or
additional silicon needs to be added. Either way, the application will need to interface
into the phone bus network, and that will require programmable logic, very low
power programmable logic.
MediPhone—A To drive home some of these ideas, consider an idea for a product that probably does
Speculative not exist today, but easily could in the near future. It will be marketed under the name
Example “MediPhone” and will target segments of the population that require quick medical
support. This would include the growing population of elderly citizens (frequently
with enough money to buy these) as well as handicapped people needing close
monitoring. See Figure 4 for an “artist” conception of this futuristic phone.
DISPLAY
CoolRunner-II
KEYBOARD EPROM Camera
CPLD MPEG 4 DRAM
Chip
7. Temperature is measured by physical contact of the forehead with the victim off
the back of the phone
8. Microphone gain is adjusted to listen to the victim’s breathing
9. It is determined that a heart attack has occurred and the friend is directed to
elevate the feet and is given directions for CPR from the medic while an
ambulance is dispatched
10. Ten minutes later, the ambulance team takes over and the MediPhone medic is
released. For insurance reasons, all transaction data are encrypted, compressed
and stored on CD for future reference.
11. The victim is saved and lives happily ever after . . .
In order to do this, MediPhone requires greater application functionality than
discussed so far. Adding instrumentation amplifiers, A/Ds, transducers and support
circuitry go beyond just having video and GPS as mentioned earlier. CoolRunner-II
CPLDs would interface the various items needed to support MediPhone. The
associated processor buses and memory interfaces are needed to support the capture
of the information taken. Other ideas quickly come to mind (WeatherPhone, ToxicGas
Phone, etc.)
Power and We have not yet mentioned power in this discussion, but it may be a key element in
Packaging are figuring out a solution, at least at the outset. Power management requires a careful
Key! balance of dynamic operations within a cell phone. Do we add in specialty silicon, or
do we just use a bigger EPROM and do it in software? As mentioned earlier, some
choices are made for us. It would be ideal to just do it in the software, unless the
bandwidth requirement on the processor(s) exceeds what could be done with a
separate chip interfaced into the phone bus. Nonetheless, adding power consuming
chips must be balanced against adding incremental code space, which also increases
the power consumption. Whether you are interfacing more EPROM or additional
ASSP silicon, CoolRunner-II is the ideal low power interface, with standby currents as
low as 14 microamps. For power management, CoolRunner-II CPLDs are frequently
used to enable/disable the power delivery to other chips within a system. So, if you
are not using your camera or GPS capability, they can be automatically shut down to
minimize power draw.
In addition to the unsurpassed power savings at high performance (clocking in the
300+ MHz range) provided by CoolRunner-II RealDigital technology, it is also critical
to note that CoolRunner-II devices are offered in a wide range of very small packages.
Table 1 shows part densities, available packages and other key features of
CoolRunner-II CPLDs.
Table 1: CoolRunner-II CPLD Family Parameters
XC2C32A XC2C64A XC2C128 XC2C256 XC2C384 XC2C512
Macrocells 32 64 128 256 384 512
Max I/O 33 64 100 184 240 270
TPD (ns) 3.8 4.6 5.7 5.7 7.1 7.1
TSU (ns) 1.9 2.0 2.4 2.4 2.9 2.6
TCO (ns) 3.7 3.9 4.2 4.5 5.8 5.8
FSYSTEM1 323 263 244 256 217 179
(MHz)
Looking The fourth generation cell phones are already being referred to as Software Defined
Forward to 4G Radio (SDR), because so many things can be more easily (in theory) changed with
software. Processor speeds in the gigahertz range result in swift, agile flexibility.
However, as mentioned earlier, software cannot “grow” a camera. Software cannot
add in a bus interface to Compact Flash +. Software cannot grow another radio
channel. Only hardware can do some things, and when developers know neither
when nor what the next new "thing" will be, only programmable logic can solve their
development quandary. CoolRunner-II CPLDs provide the future proofing to help
drive 4G cell phones.
Conclusion We have focused, at a high level, on requirements of cell phones and on the capabilities
of CoolRunner-II CPLDs for meeting those requirements. Given the current trend
toward packing as much functionality as possible into handsets without increasing
their power consumption, CoolRunner-II is an ideal choice for building phones that
need to quickly adapt to new applications still on the horizon.
Product differentiation will ultimately result in winning designs. If developers want to
cinch their winning positions, they must ensure that their designs have distinctive,
useful applications that outdo those of their competitors. Using CoolRunner-II CPLDs
to plan for future feature changes can contribute enormously to speedy and cost-
effective introduction of such applications.
Further Reading The following links provide information useful for handset and CoolRunner-II design.
Application Notes
Select the link below for a complete list of links to over 75 CoolRunner-II Application
Notes. The list includes notes on the PicoBlaze Microcontroller, Keypad Scanners,
Level Translation, Bus Controllers, Memory Interfaces, and Handheld Designs.
CoolRunner-II Application Notes
If you are looking at a printed copy of this document, go to www.xilinx.com and go to
the documentation link.
Revision The following table shows the revision history for this document.
History
Date Version Revision
06/30/03 1.0 Initial Xilinx release.
07/04/05 1.1 Update of specifications in Table 1.
R
Implementing Keypad Scanners with
CoolRunner-II
XAPP512 (v1.1) May 6, 2005
Summary This application note provides a functional description of Verilog source code for a keypad
scanner. The code is used to target the lowest density, 32-macrocell CoolRunnerTM-II
XC2C32A CPLD device in a CP56 package (6 mm x 6 mm). The keypad accommodated in this
design has 8 rows and 8 columns. The design can easily be scaled to target keypads with more
or less rows/columns. For instance, a keypad with 7 rows and 7 columns would allow the design
to fit in the smallest QFG32 package (5 mm x 5 mm). To obtain the Verilog source code
described in this document, see “Verilog Code,” page 174, for instructions.
Introduction As handheld devices such as cell phones pack more and more features into them, they require
more effective ways of entering data. Most cell phones, for example, use the standard DTMF
style keypad and a multi-tap process to enter alphanumeric data; however, for larger amounts
of data multi-tapping becomes cumbersome. More and more high-end phones are therefore
employing QWERTY keypads that make entering data easier and quicker.
Going from a DTMF to a QWERTY keypad requires more I/O. For instance, a DTMF keypad
might have 4 rows and 3 columns, where a QWERTY keypad might have 8 rows and 8
columns. This can vary depending on the requirements.
Typically, a processor (or ASIC) is used to interface to the keypad’s rows and columns. The
processor scans the rows and monitors the columns for a logic change. When a change occurs,
it indicates that one of the buttons in that column was pressed. By knowing which row was
being scanned, and which column changed state, the processor can deduce which specific
button was pushed. Additional functions such as debounce are also typically employed.
Figure 1 shows how a simple 4 x 4 keypad uses 8 GPIO of a processor.
Expanding I/O
Expanding I/O Designers faced with accommodating a keypad requiring more I/O might find their existing
processor (or ASIC) does not have enough GPIO ports. One solution is to use a CPLD as an
I/O expander that reduces the I/O requirement of the processor.
Figure 2 shows a CPLD interfacing to the keypad rows/columns on one side, and the
processor’s available GPIO on the other. In this example, an 8 x 8 keypad requires the same
number of processor GPIO ports as the 4 x 4 keypad (actually one less) when a CPLD is used.
Without a CPLD, the processor would require 16 GPIO ports instead of 7.
Scanning and Besides reducing the processor’s GPIO requirements, the CPLD also scans the rows and
Encoding monitors the columns for a change in state. When a key is pressed, the CPLD stops scanning
and immediately sends an encoded word out to the processor. The encoded word indicates
which key was pressed.
In the example shown in Figure 2, there are six bits used to represent the encoded word. Six
bits provides 26 or 64 different values each representing a different key. However, one value
needs to be used to represent the state when no keys are pressed. Therefore, only 63 keys can
be represented in this example.
All 64 keys most likely would not be needed in a typical application. If they were, there are many
options with a programmable CPLD. For instance, a CPLD could generate an enable signal to
the processor that would indicate when a key is being pressed (that is, when the encoded value
was valid). This would require one more GPIO on the processor.
The processor is still required to monitor for changes on its GPIO, only it would not have to
deduce which key was pressed since this information is encoded in the six bit word. Debounce
will also be required. This can be performed in the CPLD or the processor. Performing this in
the processor would keep the size of the CPLD to a minimum.
CPLD Design Note: The following details describe how the available Verilog reference design is implemented. The
concept and design are relatively simple. Additional functionality can be added depending on specific
Details design requirements.
To scan the keypad rows, a barrel shift register is initialized with all ones except for one bit
preset to a zero. Each bit of the shift register drives a CPLD output pin that is connected to a
row of the keypad. As the shift register is clocked the zero shifts through the barrel shifter and
scans the rows by driving them low one at a time.
The columns are inputs to the CPLD. Each input is pulled up with an internal pull up resistor.
When no keys are pushed, all column inputs to the CPLD are passively pulled up to a logic high
state. All column inputs are AND’d together. A logic one at the output of the AND gate indicates
no keys are pressed. The output of the AND is used as an enable to the shift register.
When a key is pressed, a connection between a row and column is made. The column with the
key being pressed will be driven low by the row associated with that key. The output of the AND
will go low and disable the shift register for how ever long the key is pressed.
At this point the shift register is driving the row of the key being pressed to a low, and the
column of that key is also at a low. Two encoders are used, one for the row bits (outputs of the
shift register), and another for the column inputs. The outputs of the two encoders are grouped
together to form the resulting encoded word that is presented to the processor. Figure 3 shows
a block diagram of these functions.
Implementation The reference design is implemented in Verilog. A Xilinx ISETM software project is zipped up,
and Verification including the Verilog source file, Verilog testbench, and UCF file. If you do not have Xilinx
software, you can obtain ISE WebPACKTM for free from the Xilinx website. WebPACK will give
you all the tools you need to complete any CPLD project.
The UCF file shows how to initialize the barrel shifter with a pattern of ones and a zero. It also
shows how to program the column inputs with internal pull up resistors.
The testbench can be evoked from within Project Navigator, which will automatically run a
custom ModelSim .do file. The .do file will compile the source code, open a waveform window
to view signals, and run the simulation.
The testbench generates a clock for stimulus and also simulates the pressing of buttons by
periodically connecting a row with a column. This is done until all possible combinations of rows
and columns are simulated, and then repeats.
Verilog Code THIRD PARTIES MAY HAVE PATENTS ON THE CODE PROVIDED. BY PROVIDING THIS
CODE AS ONE POSSIBLE IMPLEMENTATION OF THIS DESIGN, XILINX IS MAKING NO
REPRESENTATION THAT THE PROVIDED IMPLEMENTATION OF THIS DESIGN IS FREE
FROM ANY CLAIMS OF INFRINGEMENT BY ANY THIRD PARTY. XILINX EXPRESSLY
DISCLAIMS ANY WARRANTY OR CONDITIONS, EXPRESS, IMPLIED, STATUTORY OR
OTHERWISE, AND XILINX SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF
MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR A PARTICULAR PURPOSE,
THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY
WARRANTY OR REPRESENTATION THAT THE IMPLEMENTATION IS FREE FROM
CLAIMS OF ANY THIRD PARTY. FURTHERMORE, XILINX IS PROVIDING THIS
REFERENCE DESIGN "AS IS" AS A COURTESY TO YOU.
XAPP512 - http://www.xilinx.com/bvdocs/appnotes/xapp512__verilog.zip
Conclusion Since the CPLD is reprogrammable, adding a control line, changing the mapping of the
encoded word, or accommodating different keypads is possible with the same device.
Additionally, other “glue” functions can be absorbed into the CPLD, such as voltage translators.
A specific CPLD device (i.e., part number) can be used to accommodate different keypads and
even different applications because it's programmable. This helps boost the volume (lowers
cost), and reduces risk since changes can be made even after it's soldered down.
Coolrunner-II also is designed for low power, making it a good choice for battery powered
applications, such as cell phones, PDAs, and other portable devices. They also have additional
features that augment its low power. Multiple I/O banks can be used for voltage translation,
which is another typical application in devices with a mixture of technologies.
Revision The following table shows the revision history for this document.
History
Date Version Revision
04/04/05 1.0 Initial Xilinx release.
05/06/05 1.1 NAND gate references on page 3 changed to AND gates.
R
Level Translation Using Xilinx
CoolRunner-II CPLDs
XAPP785 (v1.0) June 22, 2005
Summary As electronic design has advanced over the years, more and more I/O standards have been
created. Since the days when the 5V CMOS and TTL standards were the prevalent standards
with which to design logic circuits, there have been a lot of changes. Today, there are many
voltage standards operating at different voltages with different thresholds. This application note
explains how to use a Xilinx CoolRunnerTM-II CPLD to translate between different voltage
levels.
Introduction A typical electronic system will no longer operate at only one voltage. The most popular
voltages used to interface between components on a board are 3.3V, 2.5V and 1.8V. However,
more frequently, devices need to interface to ’unusual’ voltages.
Since the introduction of the CoolRunner-IIA parts (XC2C32A and XC2C64A), all Xilinx
CoolRunner-II devices have multiple I/O banks. The XC2C32A, XC2C64A, XC2C128, and
XC2C256 have two banks each, and the XC2C384 and XC2C512 have four banks each. This
means that the VCCIO rail (the power supply for the device I/O) is split, enabling I/O in different
banks to be powered at different voltage levels. Each I/O bank can support one VCCIO voltage
at a time. The supported I/O standards for the CoolRunner-II device can be seen in Table 1
below.
Table 1: Supported I/O Standards in CoolRunner-II Family
Board
IOSTANDARD Input(1) TerminationVoltage
Attribute Output VCCIO Input VCCIO VREF VTT
LVTTL 3.3 3.3 N/A N/A
LVCMOS33 3.3 3.3 N/A N/A
LVCMOS25 2.5 2.5 N/A N/A
LVCMOS18 1.8 1.8 N/A N/A
LVCMOS15(2) 1.5 1.5 N/A N/A
HSTL_1(3) 1.5 1.5 0.75 0.75
SSTL2_1(3) 2.5 2.5 1.25 1.25
SSTL3_1(3) 3.3 3.3 1.5 1.5
1. For information on assigning Vref pins, see XAPP399
2. LVCMOS15 requires use of Schmitt-trigger inputs.
3. HSTL_1, SSTL2_1 and SSTL3_1 are supported on XC2C128 and larger
The I/O characteristics of each standard can be found in the device specific CoolRunner-II
Datasheets, for example XC2C128. More information about each of the I/O standards can be
found in XAPP382. For information about interfacing to 5V, see XAPP429.
© 2005 Xilinx, Inc. All rights reserved. XILINX, the Xilinx logo, and other designated brands included herein are trademarks of Xilinx, Inc.
All other trademarks are the property of their respective owners.
Configuring I/O The designer specifies which I/O standard to use at the time of design entry. I/Os can be
to Use I/O configured to operate at different I/O standards in a number of ways.
Standards Default
The default I/O Standard can be set in the process properties for the Fit process in the ISE
software. The use of the default I/O Standard will set all I/O used in the design to the I/O
standard specified. This is useful if all the I/O are powered at the same voltage. However, this
application note is discussing interfacing between different voltages, so another I/O standard
assignment method is required.
PACE
The Xilinx Pinout Area and Constraints Editor (PACE) tool can be used to assign a variety of
constraints, including pin locations, slew rate, Schmitt trigger and I/O standard. The package
diagram distinguishes between I/O banks by using different colors.
The Design Object List then enables you to assign I/O standards to the I/O pins in the design.
If the banking rules are broken, then PACE will issue a message that the I/O standard is not
VCCIO compatible.
UCF
The final method of assigning I/O standards in the software is to enter them directly into the
User Constraint File (UCF). The syntax for entering I/O standard constraints into the UCF is as
follows:
NET "user_net" IOSTANDARD = xx ;
Where xx is one of the permissible values: LVCMOS33, LVCMOS25, LVCMOS18,
LVCMOS15, LVTTL, and for devices of 128 macrocells and above, HSTL_1, SSTL2_1 and
SSTL3_1.
Xilinx recommends the use of the Default assignment in co-operation with PACE to get the
optimum results, since PACE has the design rules check that the UCF entry method lacks.
Using the CPLD In addition to knowing of how to configure the I/O of the CPLD at different voltages, it is also
as a Level necessary to have an understanding of how to use the device as a level shifter. It is possible to
have this device act as a route-through to simply shift, for example, 1.8V inputs to 3.3V outputs.
Shifter This would simply require a logical assignment of the input bus to the output bus, and would
use one pin per input/output, and one product term and one macrocell per output.
Even in the smallest device in the CoolRunner-II family, the XC2C32A, performing this
translation on an 8-bit bus would utilize less than one quarter of the resources. As the input
signals must go through the central interconnect switch, they can be assigned to any output pin
required by user. This makes the CPLD perfect for performing additional functions such as bit-
swapping of the input bus, or changing from little-endian to big-endian format. CoolRunner-II
CPLDs have a very fast TPD (propagation delay), as fast as 3.8 ns in the XC2C32A -4, so very
little delay will be incurred by using a CPLD in this situation. It is also important to note that, due
to the uniform nature of the architecture, all signals going through a similar path in the device
will incur a similar delay and will, therefore, have minimal skew from each other.
While this is a perfectly legitimate use for a CPLD, there are a lot of other resources available
that can be used to perform operations on the incoming data.
interfaces for use in electronic systems (USB, SPI, I2C), several of which can fit into a Xilinx
CPLD. Figure 1 shows a generic example that builds on the previous example. Here the 1.8V
input bus goes into the device, has a few operations performed on it, such as shifting left or
right, checksum calculation, parallelization, serialization, interrupt handling, and so on, and
emerges from the device at 3.3V.
CoolRunner-II CPLD
Figure 1: Using CoolRunner-II as a Level Shifter Interface
A few examples of common interfaces can be found in other application notes on the Xilinx
website.
• XAPP341 UARTs in Xilinx CPLDs
• XAPP354 Using Xilinx CPLDs tp Interface to a NAND Flash Memory Device
• XAPP384 Interfacing to DDR SDRAM with Xilinx CoolRunner-II CPLDs
Conclusion
conditions, the I-V plots for the I/O are needed. These can be seen in the device specific
CoolRunner-II datasheets. Figure 2 is taken from the XC2C32A datasheet.
Conclusion Xilinx CoolRunner-II CPLDs are perfectly suited to perform level translation operations on
signals. They offer split VCCIO rails on all devices providing at least two I/O banks. Signals can
enter the device at one voltage and be output from the device at another voltage without
introducing any skew on the signals. This application, which previously required a dedicated IC,
can now be incorporated into the CoolRunner-II, which can also be performing other system
functions.
Revision The following table shows the revision history for this document.
History
Date Version Revision
06/22/05 1.0 Initial Xilinx release.
R
CoolRunner-II Character LCD Module
Interface
XAPP904 (v1.0) August 22, 2005
Summary CoolRunnerTM-II CPLDs can be used to control dot-matrix liquid crystal display (LCD)
modules. The low-power characteristics of LCD modules make them an ideal complement to
the CoolRunner-II family. These displays typically require 3.3V signals. However, this is not of
concern because CoolRunner-II devices are 3.3V tolerant. Thus, it is possible to achieve ultra-
low power at a 1.8V core voltage while using 3.3V at the I/O.
© 2000-2003, 2005 Xilinx, Inc. All rights reserved. XILINX, the Xilinx logo, and other designated brands included herein are trademarks of Xilinx, Inc.
All other trademarks are the property of their respective owners.
CPLD Implementation
(})
8 8
db
8 8
lcd_db
C0
Data
C
N
T Power_up
R `0' lcd_rw
ready
counter
done
16
ready
lcd_rs
C
N
Main State Machine
T
W R lcd_e
clk
reset
CoolRunner-II CPLD
CPLD Implementation
The LCD Controller implementation is comprised of two state machines - a Power_Up State
Machine, and an LCD Controller Main State Machine. These two blocks are discussed in the
following sections.
Table 1 defines the primary inputs/outputs of this LCD Controller design.
CPLD Implementation
every power-up or reset. All timing requirements will be met, assuming a 1.8 MHz external
clock frequency.
8
Reset Data
15
Counter_Enable Count
Clk Done
Figure 4 shows a block diagram of the Power_Up module. This Power_Up module utilizes a
terminal counter to insure that data is held for the appropriate amount of time, as specified in
Figure 3. As shown, the largest wait time required by the LCD is 15 ms (during the Power_ON
sequence). Thus, to simplify the design, data is held for 16 ms in every subsequent block.
Since this design assumes a 560 ns clock period (1.8 MHz), a terminal count value of 30,000
is used. Alter this terminal count if a different clock frequency will be used.
An internal ’Done’ signal is output by this Power_Up module to let the main LCD State Machine
know when the Power_Up sequence has completed.
Resource Summary
Resource This design uses a total of only 40 macorcells, allowing it to fit into an XC2C64A device.
Summary ************************* Mapped Resource Summary ********************
Macrocells Product Terms Function Block Registers Pins
Used/Tot Used/Tot Inps Used/Tot Used/Tot Used/Tot
40/64(62%) 64/224(29%) 61/160(38%) 26/64(41%) 23/33(70%)
Conclusion The LCD Interface presented in this application note is simple and straightforward. Additionally,
CoolRunner-II devices are ideal candidates for driving LCDs due to their low cost, low power
and ease of use.
Revision History
Revision The following table shows the revision history for this document.
History
Date Version Revision
08/22/05 1.0 Initial Xilinx release.
R
Using Xilinx CPLDs to Interface to a
NAND Flash Memory Device
XAPP354 (v1.1) September 30, 2002
Summary This application note describes the use of a Xilinx CoolRunner™ CPLD to implement a NAND
Flash memory interface. CoolRunner CPLDs are the lowest power CPLD available and the
ideal target device for memory interface applications. The code for this design may be
downloaded from the Xilinx web site, refer to section HDL Code, page 204. This design fits
XCR3032XL CooRunner or XC2C32 CoolRunner-II CPLDs.
Introduction The flash memory market has been rapidly growing over the past several years due in part to
increasing demands of portable and embedded devices. This market is driven by embedded
code storage and bulk data storage applications. Flash technology has been optimized to meet
the needs of these two target applications.
NAND Flash is a sequential access device appropriate for mass storage applications, while
NOR Flash is a random access device appropriate for code storage applications. NAND
technology organizes cells serially to achieve higher densities. This reduces the number of
contacts needed in the memory array. The trade-off between the two technologies is NAND
Flash data must be accessed sequentially compared with NOR Flash which offers fast random
access.
NAND Flash memory offers low cost per bit, high performance, and the highest density non-
volatile memory available. NAND Flash is ideal for applications ranging from MP3 players and
digital cameras to applications requiring mass storage of data, especially when the data is
packetized, or sequentially arranged.
This application note describes the design of a basic NAND Flash interface. The NAND devices
used for testing this interface include the AMD UltraNAND™ Flash and the Samsung NAND
Flash memory.
The AMD UltraNAND flash memory (AM30LV0064D) is a 64 Mbit storage device. This memory
device utilizes a multiplexed command/data/address bus as well as other control signals for
read, erase and program commands. This memory device has an initial page read access time
of 7 μs, with subsequent byte access times of less than 50 ns per byte.
The Samsung K9F4008W0A is a 512K x 8-bit NAND Flash memory device. The command,
data, and address are multiplexed through an 8-bit I/O port. This memory device supports a 32-
byte frame read, with random access times of 15 μs and sequential access times of 120 ns.
NAND Interface The NAND interface described here is implemented in a CoolRunner CPLD. The NAND
interface design can interact with both AMD and Samsung NAND memory devices.
Figure 1 shows the overall system diagram for a single AMD UltraNAND Flash or Samsung
memory device. The CoolRunner CPLD reads the 4 least significant bits in the system address
© 2002 Xilinx, Inc. All rights reserved. All Xilinx trademarks, registered trademarks, patents, and further disclaimers are as listed at http://www.xilinx.com/legal.htm. All other
trademarks and registered trademarks are the property of their respective owners. All specifications are subject to change without notice.
NOTICE OF DISCLAIMER: Xilinx is providing this design, code, or information "as is." By providing the design, code, or information as one possible implementation of this fea-
ture, application, or standard, Xilinx makes no representation that this implementation is free from any claims of infringement. You are responsible for obtaining any rights you may
require for your implementation. Xilinx expressly disclaims any warranty whatsoever with respect to the adequacy of the implementation, including but not limited to any warran-
ties or representations that this implementation is free from claims of infringement and any implied warranties of merchantability or fitness for a particular purpose.
in order to decode the flash interface commands. The interface signals to the Flash device are
asserted by writing to a specific port of the CPLD.
CE#
RE#
ADDR[3:0] I/O[7:0]
WE# AMD UltraNAND
WRITE# (AM30LV0064D)
CoolRunner SE#
READ# or
XPLA3 CPLD ALE
CE# Samsung
CLE (K9F4008W0A)
RESET
WP#
RY/BY# RY/BY#
X354_02_082701
RY/BY#
CE#
X Decoder
RE# State Machine
WE# Memory Array
Address Register
Status Register
I/O Register & Buffer I/O 7-0
VCC
VCCQ
VSS
X354_03_082701
Table 2 describes the AMD UltraNAND command set and functionality. The command register
does not occupy any addressable memory location. This register holds the command, along
with any address and data information needed to execute the command. Programming data
into the Flash array is a two step process. The data to be programmed is loaded into the data
registers using the "Input Data" command. After the data is loaded, the "Page Program"
command is performed to write data from the data registers to the Flash array.
is 128 blocks (or 4 MB). Data is programmed via the Frame Register which holds 32 bytes of
data. Figure 3 is a block diagram of the Samsung K9F4008W0A.
4M Bit
NAND Flash ARRAY
A0 - A6 Y-Buffers Latches 32Byte x 4Frames x 4096Rows
& Decoders
CE Control Logic
RE & High Voltage
Generator I/O0
WE Global Buffers
I/O7
CLE ALE WP
X354_04_082701
All address and command instructions are multiplexed through the 8 I/O lines. Similar to the
AMD UltraNAND, data is latched on the rising edge of WE# when CE# is low. The address is
latched in when ALE = ’1’ and CLE = ’0’ and the command is latched when ALE = ’0’ and CLE
= ’1’. Table 3 describes the Samsung NAND Flash memory command set.
CPLD Design
For more information on the ABEL implementation of the CoolRunner CPLD design, refer to
AMD Application Note # 22363 (see References, page 205). The design described here and
available on the web is implemented in both VHDL and Verilog (see "HDL Code" on page 204
for more information).
The CPLD design decodes system address commands to interface with the AMD UltraNAND
and Samsung Flash memory devices. The CPLD is responsible for the following functions:
• Decode read or write from address bus
• Interpret system address bus commands
• Assert interface signals to UltraNAND Flash device
• Monitor RY/BY# output from Flash memory device
The CPLD is configured to decode address 00h through 0Fh from a base address. The CPLD
logic outputs are determined by the system writing to each port address. The port addresses for
the CPLD are shown in Table 4 with a functional description of each.
Table 4 is described in more detail in the AMD Application Note #22363 for the design
implementation in ABEL. Refer to References, page 205 for more information.
Figure 4 is a block diagram of the VHDL/Verilog implementation of the NAND interface. All port
signals (shown in Table 4) are decoded from the system address when CE# is asserted.
The ALE_SIG process asserts the ALE signal on a write to PORT2 and clears ALE on a write
to PORT3. The SEN_SIG process asserts the SE# signal upon a write to PORT4 and clears
SE# upon a write to PORT5. The OUTCE_SIG process asserts the OUTCE# signal upon a
write to PORT8 and clears OUTCE# upon a write to PORT9. The WPN_SIG process asserts
the WP# signal upon a write to PORT6 and clears WP# upon a write to PORT7. The
READY_SIG process assigns the RY/BY# signal from the Flash device to the ready output
signal. Otherwise, the ready signal is 3-stated.
RESET
SE_N_INT
SEN_SIG
PORT4
PORT5
WRITE_N
OUTCE_N_INT
OUTCE_SIG
PORT5
PORT9
PORT2
LE_SIG
PORT3
ALE_INT
WP_N_INT
WPN_SIG
PORT5
PORT7
B1
WP_N
ALE
READY
PORT0
READY_SIG
PORT1 PORT1
READ_N OUTCE_N
RY_BYN PORTA
SE_N
B5 CLE
PORT_ADDR[3:0]
PORTB
CE_N
PORTC
COM_LAT_N
PORTE
WE_N
PORTD
RE_N
X354_05_082701
The CLE signal is asserted on any access to PORT1. The RE# signal is asserted to the Flash
device when a read is performed on PORT0. The WE# signal is asserted to the Flash device
when a write is performed on PORT0 or PORT1.
CPLD The NAND flash interface was implemented in VHDL and Verilog as described above; and in
Implementation ABEL as described by AMD. Xilinx Project Navigator was used for design compilation, fitting,
and simulation in a CoolRunner XPLA3 CPLD. Xilinx Project Navigator, which includes the
ModelTech simulation tool, is available free-of-charge from the Xilinx website at
www.xilinx.com/products/software/webpowered.htm. The design was targeted for a 3.3V, 32
macrocell CoolRunner XPLA3 CPLD (XCR3032XL-VQ44). The design utilization is shown in
Table 5. This utilization was achieved using certain fitting parameters, actual results may vary.
Design Verification of the NAND interface was performed using the Xilinx WebPACK Project Navigator
Verification VHDL output timing model. The timing model was imported and compiled by Model Technology
ModelSim. A test bench was utilized to instantiate the memory device (AMD UltraNAND or
Samsung Flash) and the CPLD interface design as shown in Figure 5. The AMD UltraNAND
and Samsung devices were instantiated using Denali Memory Maker.
NAND_FLASH_TB
FAIL_FLAG
I/O[7:0]
PORT_ADDR[3:0]
CE_N
WRITE_N
RE_N
READ_N
NAND_INTERFACE WE_N AM30LV0064D or
RESET
SE_N K9F4008W0A
CPLD_CEN XPLA3 Flash
Interface ALE Denali Memory
COM_LAT_N
CLE Model
WP_N
RY_BYN
X354_06_082701
Figure 5 illustrates the operational flow used to test the Denali memory model. Figure 6
describes the test flow for the AMD UltraNAND device. The test flow for the Samsung Flash
memory model was modified slightly to match Samsung command cycles.
START
Enable Flash Device: Assert OUTCE# (low) Issue a "Read Status" Command:
Write 00h to PORTADDR8 Write 70h to PORTADDR1
Yes
Enable Spare Area: Assert SE# (low)
Write 00h to PORTADDR4
Protect Flash Device: Set WP# (low)
Write 00h to PORTADDR6
Program No
Operation Return Program
Passed? Failed
Write Address: Set ALE (high)
Write 00h to PORTADDR2
Yes
Return Program
Load Page Address: Successful
Write ADDR to PORTADDR0
Flash No
Buffer
Full?
Yes
Figure 8 illustrates how to change any signal name requirements in the MemMaker tool.
Once all signal name and timing requirements have been specified, the VHDL or Verilog
source code can be generated. To generate VHDL source code, select Options | Simulation
Environment | VHDL | Model Technology ModelSim (Windows). The VHDL code can then be
saved for use in a test environment as shown in Figure 9.
ModelSim Implementation
Note:
Please refer to XAPP338: Using Xilinx WebPack and ModelTech ModelSim Xilinx Edition as a guide
to using ModelSim with Project Navigator. The ModelSim Quick Start demo provides a good first step
for getting familiar with ModelSim.
Model Technology ModelSim was the target simulator in this design. The test bench created for
the CPLD design generates the necessary system address cycles. A separate test bench
environment was used to test the AMD UltraNAND device and the Samsung Flash memory.
This is due to the data buffer size during a program cycle and differences in command codes.
The Denali MemMaker model is loaded in ModelSim as illustrated by the ModelSim script.
vcom -reportprogress 300 -work work{../amd_flash_tb.vhd}
# Model Technology ModelSim XE vcom 5.3d Compiler 2000.03 Mar 30 2000
# -- Loading package standard
# -- Loading package std_logic_1164
# -- Loading package numeric_std
# -- Loading package pkg_convert
# -- Compiling entity amd_flash_tb
# -- Compiling architecture behavior of amd_flash_tb
# -- Loading entity am30lv0064d
# -- Loading package pxa_pkg
# -- Loading entity nand_int
vsim work.amd_flash_tb
# vsim work.amd_flash_tb
# Loading C:/Modeltech_xe/win32xoem/../std.standard
# Loading C:/Modeltech_xe/win32xoem/../ieee.std_logic_1164(body)
# Loading C:/Modeltech_xe/win32xoem/../ieee.numeric_std(body)
# Loading work.pkg_convert(body)
# Loading work.pxa_pkg
# Loading work.amd_flash_tb(behavior)
# Loading work.am30lv0064d(behavior)
# Loading C:\Denali\denali.dll
# *Denali* History enabled for Denali Memory Modeler.
# *Denali* Debug information will also be saved.
# *Denali* Trace function enabled for Denali Memory Modeler.
# *Denali* Denali Memory Model Version 2.900-0005
# *Denali* Copyright (c) Denali Software, Inc., 1996-2001, All Rights
Reserved.
# *Denali* Class: flash_nand Instance: "/den_model" Size: 8192Kx8
# *Denali* Class: internal Instance: "/den_model(spare)" Size: 256Kx8
# Loading work.nand_int(structure)
# Loading work.pxa_bufif2(behavioral)
Figure 10 illustrates loading the page address to the UltraNAND. Notice the ALE signal is high
and WE# is asserted for each portion of the address write.
Figure 11 illustrates the completion of the "Page Program" command. Notice the RY/BY#
signal is asserted, representing that the flash device is busy with an operation. After the "Page
Program" command is sent to the flash, a "Read Status" command is sent. The "Read Status"
command is used to read the device status. When I/O6 is equal to ’1’, the device is ready for the
next command. To check if an operation is successful, reading I/O0 will determine the pass/fail
status. When I/O0 is equal to ’0’, the operation passed and when equal to ’1’, the operation
failed. Notice where the simulation is highlighted in Figure 11, the program operation was
successful.
HDL Code THIRD PARTIES MAY HAVE PATENTS ON THE CODE PROVIDED. BY PROVIDING THIS
CODE AS ONE POSSIBLE IMPLEMENTATION OF THIS DESIGN, XILINX IS MAKING NO
REPRESENTATION THAT THE PROVIDED IMPLEMENTATION OF THIS DESIGN IS FREE
FROM ANY CLAIMS OF INFRINGEMENT BY ANY THIRD PARTY. XILINX EXPRESSLY
DISCLAIMS ANY WARRANTY OR CONDITIONS, EXPRESS, IMPLIED, STATUTORY OR
OTHERWISE, AND XILINX SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF
Conclusion Xilinx CoolRunner XPLA3 CPLDs are the perfect target device for interfacing with system
memory devices. This NAND Flash interface can be modified to support multiple memory
banks and suit any application requirements. CoolRunner CPLDs are ideal for any memory
interface needs in portable and handheld devices. CoolRunner CPLDs are low power and easy
to design with using the WebPOWERED software tools.
References The web sites shown here are valid as of the publication date of this note.
1. Samsung Flash Memory Devices
(http://samsungelectronics.com/semiconductors/Flash/Flash.htm)
2. Denali Software, Inc. (http://www.denalisoft.com/)
3. eMemory (http://www.ememory.com/)
Revision The following table shows the revision history for this document.
History
Date Version Revision
08/30/01 1.0 Initial Xilinx release.
09/30/02 1.1 Minor changes.
R
Cell Phone Security Demoboard
On The Fly Reconfiguration Technique
XAPP430 (v1.0) July 8, 2003
Summary This document describes the operation of the cell phone demo board, and provides a simple
example of OTF operability of CoolRunner™-II CPLDs.
Introduction This demo board was created specifically to demonstrate the unique ability of the CoolRunner-
II device's capability of performing On The Fly (OTF) operations. This particular application
illustrates a cell phone that utilizes a SIM card identification system.
In some parts of the world, cell phones are mated with SIM cards for operation. The SIM card
contains the account information for the user. A user may insert their card into any phone to
make a call. While this allows for a high degree of flexibility in terms of ease of hardware
interchangeability, it also opens the cell phone up to a high risk in terms of theft. Unfortunately,
an intelligent, resourceful and dedicated thief typically is successful. However, if the cost of
stealing and modifying the phone is increased such that it is more expensive than just
purchasing a phone outright, the economics of the theft should result in a reduction of this
particular crime.
This demo board is not meant to be a solution to cell phone theft. It is a proof of concept to
illustrate to engineers how the advanced features of the CoolRunner-II CPLDs might assist in
cell phone security. Obviously additional techniques would need to be used in conjunction with
this demo, such as package selection (ball grid), mounting techniques, PCB layout (such as
burying JTAG lines), or even "chip on board" technology. The cell phone security issue is a
complex one, and this demo illustrates how Xilinx CPLDs can add some margin of flexibility to
the solution.
Demonstration Important: Read all instructions carefully on the following pages before use in order to avoid
Overview damaging the cell phone.
The demo board comes with two small 'SIM' cards that can be inserted into the reverse side of
the 'phone'.
3) The front display will either show a circular 'chasing' pattern, or will scroll out CodE? The
chasing pattern is indicative of the normal operation of the phone. This is just a simple 'I am
alive' pattern, indicating that the SIM card that is in the phone is mated to the phone.
4) If the front display shows CodE? Enter in the user code, which is 5,7,9,3. It will ask for the
code again. Enter in 5,7,9,3. This will program the onboard EE to accept the new SIM card.
The phone should now show the chasing pattern on the LCD.
5) Once the phone has been reprogrammed to accept the new SIM, put in the other SIM, so
that the CodE? Starts again. Enter in a four digit code that is not the master code. Enter this
code in again. The display should turn off. At this point the CPLD has erased itself and the
© 2003 Xilinx, Inc. All rights reserved. All Xilinx trademarks, registered trademarks, patents, and further disclaimers are as listed at http://www.xilinx.com/legal.htm. All other
trademarks and registered trademarks are the property of their respective owners. All specifications are subject to change without notice.
NOTICE OF DISCLAIMER: Xilinx is providing this design, code, or information "as is." By providing the design, code, or information as one possible implementation of this fea-
ture, application, or standard, Xilinx makes no representation that this implementation is free from any claims of infringement. You are responsible for obtaining any rights you may
require for your implementation. Xilinx expressly disclaims any warranty whatsoever with respect to the adequacy of the implementation, including but not limited to any warran-
ties or representations that this implementation is free from claims of infringement and any implied warranties of merchantability or fitness for a particular purpose.
phone is useless. Attach the phone to the Impact tool, and perform a 'Blank Check' to illus-
trate that the phone is completely dead.
6) If two dissimilar codes are entered, such as 2345, and then 2346, the phone will keep
requesting CodE? Until two matching codes are entered. It will then either accept the new
SIM (if the codes were both 5,7,9,3) or erase the CPLD if the codes were something else.
Setup Batteries
The phone runs on two lithium coin cell batteries. Any 20mm 3V cell will work. I have run about
30 demos so far on one set of batteries, and they are still working fine, but keep some spares
on hand, as the lithium cells do droop fairly quickly. Important! The phone does not have
reverse polarity protection. Make sure that the batteries are stacked so that the + side of the
batteries are 'up'. Refer to Figure 1 for an illustration.
On / Off:
Turning on power is accomplished by moving the jumper next to the battery to the lower two
pins. The upper two pins provide an 'off' position jumper holder. This below picture indicates
the phone is in the 'off' position. Refer to Figure 2.
JTAG Cable:
The board is not marked for the JTAG cable. The header on the board is in the order of the
flying lead cable that is provided with the Xilinx download cables. In order from the top of the
phone: VCC, GND, TCK, TDO, TDI, TMS. See the below picture, Figure 3, for details.
Caution
The mounting of the board to the faceplate is fragile. When removing the leads from the board,
make sure that you hold onto the PCB and not the faceplate when disconnecting the cable.
Refer to Figure 4.
A foreign (non-mated) SIM card will result in the phone requesting a code and then the
confirmation of that code to be entered as shown in Figure 7.
Miscellaneous Details
The only buttons that have impact on the operation of the phone are the number keys and the
* buttons. The asterisk is a system reset button and may be pushed if the phone exhibits
unusual behavior.
Do not push in any of the other buttons as it may result in the rubber keypad becoming
dislodged.
Always put the power jumper in the 'off' position when not being used.
Phone operable
Perform Scroll
Y N
Phone operable
SIM Match?
Perform Scroll
Y N
Accept New Perform Self
Code Match?
SIM Erase
X_09_062603
The phone idles in a small loop that operates the display in a chasing pattern. Once every loop
cycle, it accesses the SIM card address and compares it to an onboard EE memory device to
ensure that the correct card is inserted. As long as the phone recognizes the card, it stays in
this normal operation loop.
If the card is not recognized, the phone breaks from the idle loop and queries the user with a
user code request. The phone reads the keyboard for 4 key presses, and stores this value. It
then queries for a confirmation of the user code, and compares it to the first 4 digits. If the user
codes match, then the entered user code is compared against the known user code stored in
memory. If the user codes mismatch, then the user is asked to re-enter the user codes again.
Upon receipt of two matching user codes, the phone compares this value to an internal stored
user code value. If the user codes match the internal value, the new SIM card is programmed
into EE and the phone enters the normal operation idle loop.
If the user codes do not match the master user code, then the phone enters into a state
machine that performs an OTF erase of the CPLD.
Conclusion This demoboard provides an illustration of the power of OTF operations by applying simple
OTF reconfiguration techniques in a Cell Phone security demonstration. Requiring only 27
macrocells to implement the self erase algorithm portion of the design, this function will fit into
any Xilinx CoolRunner-II CPLD
Revision The following table shows the revision history for this document.
History
Date Version Revision
07/08/03 1.0 Initial Xilinx release
R
Using CoolRunner-II with OMAP, XScale,
i.MX & Other Chipsets
XAPP905 (v1.0) August 25, 2005
Level Interfacing two chips of different voltage standards is a common problem. Every type of
Translation memory is not made at every voltage standard, and microprocessors are offered at many
voltages. Matching standards can be as simple as introducing level translators, but they are
expensive and take more area than might be desired. Using a CPLD is a better solution, and
offers substantially greater flexibility. All Xilinx CoolRunner-II CPLDs are capable of translating
between two voltages, and some can handle as many as four.
CoolRunner-II CPLD I/O banks easily translate between voltages ranging from 1.5 to 3.6V, in a
single chip. But, this totally disregards the programmability of the devices. You get the
translation as part of the whole package, which means you get a bundle of logic, flip flops,
power reduction resources, and I/O buffers frequently priced below level translator chips!
XAPP785 explains the details on how you can take advantage of this powerful feature, to
expand the capabilities of your OMAP, XScale or i.MX designs.
VCC1 VCC2
Bank1
Bank2
TI Fabric
OMAP
CoolRunner-II CPLD
© 2000-2003, 2005 Xilinx, Inc. All rights reserved. XILINX, the Xilinx logo, and other designated brands included herein are trademarks of Xilinx, Inc.
All other trademarks are the property of their respective owners.
Pin Expansion
Pin Expansion High pin count ASICs are more expensive than low pin count ASICs, in general. If your logic
needs dictate a low capacity, but your I/O requirements dictate a high capacity, you may be
paying for logic you will never use, to gain the pins. One solution to this is adding a
CoolRunner-II CPLD to operate as a “pin expander”. The basic idea is to identify GPIO pins that
typically operate at a slow speed. Then, rather than assign ASIC pins to them, attach
CoolRunner-II CPLD pins to the slow moving GPIO signals, serialize the signals and import
them to the ASIC on fewer net pins.
Serializing/deserializing is done through simple, efficient shifting, and can drop the pin counts
dramatically on expensive ASICs. XAPP799 shows how to do this through an I2C port, but
other methods can be used.
As an alternate viewpoint, OMAP, XScale and i.MX processors provide specific pin mixes to
support the applications their vendors deem appropriate. This doesn’t mean that you must
agree, as a designer. CoolRunner-II pin expansion permits you to create your own GPIO pins,
of assorted voltages and additional capabilities (pulsing, PWM, individually 3-stated).
Increasing the effectiveness of your solution is our goal.
INTEL
Logic
PXA 850 Fabric
XScale
CoolRunner-II CPLD
Figure 2: CoolRunner-II Pin Expansion of XScale Processor
Pin Swizzling CPLDs offer the ability to rearrange your pinouts when PCB layout errors occur. This valuable
quality is key to keeping you on schedule and within financial and power budgets.
Correcting misconnections on a board, without having to re-spin the PCB can shave weeks to
months out of product schedules. CoolRunner-II CPLDs are built from powerful logic blocks
using Programmable Logic Arrays, that can reassign pin logic “at will.” You will be amazed at
how well these devices retain pinouts through multiple edits, yet permit re-assigning a design
onto different pins as needed. The CoolRunner-II Family data sheet explains the architecture
and points you to application notes that give all the detail you will need to understand the value
of PLAs.
Power Control Quick power up is one of the strengths of CPLDs. Containing their own configuration cells
permits CoolRunner-II CPLDs to power up and direct the activities of other chips, as they
subsequently arise. This includes some power regulators, which may be sequenced by the
Coolrunner-II CPLDs, as well as other controlling signals that need to be well defined early in
board operation. XAPP436 describes some of these capabilities.
Power XScale, OMAP and i.MX based chipsets all include some version of the ARM microprocessor.
Reduction This is not a surprise. Advanced RISC Machines started early with developing low power
methods to operate microprocessors, and subsequently, the licensing vendors have all added
their own methods to further reduce processor power. Typical power reduction operations are:
clock gating, voltage throttling and on board memory management to reduce transfers within
the device. These are sometimes referred to as run, wait, doze, sleep, hibernate, and so on.
Also, operating systems like Symbian have added “power awareness” to the mix, so that
Logic Consolidation
unused resources can be parked in the lowest power mode possible for the current tasks being
executed. This all works well and lowers processor power. However, lowering power in the rest
of the system exceeds the scope of these methods. Enter CoolRunner-II CPLDs.
CoolRunner-II CPLDs are designed to be inherently low power parts. That is important, but
alone is not enough. CoolRunner-II special features also can be used to lower the power in
other devices. Using clock dividers and Xilinx’s patented DataGATETM technology can reduce
power in many (if not all) of the chips on your design. XAPP378 shows how to do this, and
WP227 shows just how much power you can save with DataGATE. Blocking power to other
chips can also reduce electromagnetic fields being propagated on your board and emanating
from your system. This powerful signal blocking technique can pay off in many ways!
EPROM SRAM
i.MX
Processor CoolRunner-II DRAM
I/O
DataGATE Blocking
Figure 3: DataGATE Blocking Extraneous Switching to Various Devices
Logic Having three, two input AND gates, two three input OR gates and a Schmitt buffer package on
Consolidation your board can burden your bill of materials (BOM), eat away at your power and cost budgets,
and lower your reliability. Collecting all that stray logic into a consolidated, low power
CoolRunner-II not only solves these problems, but stores additional unused logic right there, on
your board – ready to use with future improvements/edits. WP214 shows what you can expect
from collecting logic gates/flip flops into CoolRunner-II CPLDs. Table 1 summarizes the “burn
rate” for logic.
Additional Information
Conclusion - CoolRunner-II CPLDs are quickly becoming the standard for low power, low cost, high volume,
The Future handheld consumer products. This application note has focused on how these powerful
products can make life easier when building systems with OMAP, XScale and i.MX processors,
but CoolRunner-II works just as well with many other processors, to add functionality, save
power and get products to market fast.
Revision The following table shows the revision history for this document.
History
Date Version Revision
08/25/05 1.0 Initial Xilinx release.
R
Connecting Intel PXA27x Processors to
Hard-Disk Drives with a CoolRunner-II
XAPP914 (v1.0) January 15, 2006 CPLD
Summary With the increasing functionality of modern handheld devices, greater storage capacity
requirements become very important. The Intel PXA27x Processor Family is very popular and
is used in many high end cell phones and PDAs. In order to support the higher storage capacity
associated with hard-disk drives (HDD), Intel published the application note, Connecting the
Intel PXA27x Processor Family to a Hard-Disk Drive via the VLIO Memory Interface.
The Variable Latency I/O (VLIO) interface solution only requires a small number of additional
components and produces low-cost and efficient Direct Memory Access (DMA) performance.
The Xilinx CoolRunner-IITM CPLD is the ideal solution to bridge the Intel processor to an HDD
without the need of other components.
Introduction The Intel application note provides detailed suggestions for connecting a CompactFlash, true
IDE mode, parallel ATA, HDD to a PXA27x processor using a VLIO memory interface.
Configurations using Programmed I/O (PIO) and flow-through DMA are presented. The HDD in
this application note is assumed to be using 3.3V logic. The PXA27x processor is assumed to
be running a 1.8V memory bus, so level shifting is used to buffer logic to and from the HDD
interface logic.
With the introduction of the XC2C32A and XC2C64A CPLDs, the Xilinx CoolRunner-II Family
becomes the ideal solution to address the need of the level shifting for this application. The
XC2C32A, XC2C64A, XC2C128, and XC2C256 CPLD devices have two banks each, and the
XC2C384 and XC2C512 devices have four banks each. This means that the VCCIO can be
powered at 3.3V on one bank to interface to the HDD, and at 1.8V on the other bank to interface
to PXA27x processor. The supported I/O standards for the CoolRunner-II device can be seen
in Table 1 below. More information about level translation using Xilinx CoolRunner-II CPLDs
can be found in XAPP785.
PXA27x
CompactFlash
PXA27x CoolRunner-II XC2C64A Connector
#ATASEL GND
#CSEL
D[15..0] Level D[15..0] GND
Shifter A[10..3]
VCC HDD_VCC
A[3..1] A[2..0]
#WE
nOE #IORD
nPWE #IOWR
Level #DMACK
Shifter
A4 Glue DMARQ
#CS0 #IOCS16
Logic
nCS5 #CD2
#CD1
Glue #VS1
Logic #CS1
A5 #VS2
#DASP
nRESET_OUT #RESET #PDIAG
IORDY
GPIOx INTRQ
This design uses two address lines and nCS5 of the PXA27x to get the two chip select signals
the HDD needs. Table 2 shows the relationship of the PXA27x processor nCS5 memory
mapping to the HDD CS0# and CS1# signals.
Table 2: Memory Mapping
nCS5 A4 A5 CS0# CS1# R/W Field Address
0 0 1 0 1 Task File Register 0x1400_0020
0 1 0 1 0 CTL Register 0x1400_0010
0 1 1 1 1 DMA 0x1400_0030
1 x x 1 1 N/A N/A
Timing Considerations
The PXA27x VLIO interface is designed to interface to high speed memory devices, such as
Flash and SRAM. This capability requires attention to timing parameters. Analysis of HDD
vendor devices shows that the “CS Valid to IIORD/IOWR” is close to the specified limits of the
PXA27x processor. It may be necessary to perform timing analysis and use glue logic to adjust
the timing to meet the HDD timing requirements.
As you can see from Figure 1, the glue logic for memory mapping and level shifting functions
can be easily integrated into a single XC2C64A CPLD. And the CoolRunner-II family’s
Conclusion
programmable logic array can be flexibly designed and programmed to meet the timing
requirements for this application.
Conclusion Xilinx CoolRunner-II CPLDs are the ideal solution for applications requiring level translation.
This application connects Intel’s PXA27x processor to a hard disk drive. integrating level
shifting and glue logic for memory mapping into a single XC2C64A CPLD.
Revision The following table shows the revision history for this document.
History
Date Version Revision
01/15/06 1.0 Initial Xilinx release.
Revision History
R
A Low-Power IDE Controller Design
Using a CoolRunner-II CPLD
XAPP939 (v1.0) May 30, 2006
Summary This document details a Verilog implementation of an IDE controller using a Xilinx
CoolRunner-II CPLD. CoolRunner-II CPLDs are the lowest power CPLDs available, making
them the perfect target device for handheld applications. This design fits in an XC2C256-
CP132 CPLD.
Introduction IDE controllers are asynchronous parallel data links that are standard across many CPUs. This
IDE controller design has been implemented on a CoolRunner-II CPLD. A high level block
diagram is shown in Figure 3. The CPU chosen for this IDE controller implementation is the
Intel PXA270 CPU, but the code can be easily modified for other CPUs by changing the CPU
interface block in the IDE controller.
IDE Background
There are two modes of operation of an IDE controller, PIO mode and DMA mode. Data is
transferred in blocks using either PIO or DMA protocols. For more details and timing diagrams,
please refer to the ATA/ATAPI5 specification document.
PIO data transfers occur when the BSY bit is cleared to zero and the DRQ bit is set to one in the
device status register of an IDE device. These transfers are usually 16-bit. Data is transferred
in blocks of one or more bytes known as a DRQ blocks. Chip select signals CS0- and CS1- are
used to select the device command or control block registers. Device address signals DA [2:0]
access the device registers or data port. DIOR- or DIOW- determine the direction of the data
transfer. Read Cycle and Write Cycle waveforms for the PIO mode are shown in Figure 1.
Figure 1: Read Cycle and Write Cycle Waveforms for the PIO Mode
DMA transfers are always 16-bit. Each assertion of DMACK- by the host defines a DMA data
burst. A DMA data burst is two or more bytes. The DMARQ and DMACK- signals are used to
© 2006 Xilinx, Inc. All rights reserved. All Xilinx trademarks, registered trademarks, patents, and further disclaimers are as listed at http://www.xilinx.com/legal.htm. PowerPC is
a trademark of IBM Inc. All other trademarks and registered trademarks are the property of their respective owners. All specifications are subject to change without notice.
NOTICE OF DISCLAIMER: Xilinx is providing this design, code, or information "as is." By providing the design, code, or information as one possible implementation of this feature,
application, or standard, Xilinx makes no representation that this implementation is free from any claims of infringement. You are responsible for obtaining any rights you may
require for your implementation. Xilinx expressly disclaims any warranty whatsoever with respect to the adequacy of the implementation, including but not limited to any warranties
or representations that this implementation is free from claims of infringement and any implied warranties of merchantability or fitness for a particular purpose.
signify when a multi-word DMA transfer is to be executed. The DMARQ and DMACK- signals
are also used to control the data flow of a multi-word DMA data transfer.
When a device is ready to transfer data associated with a multi-word DMA transfer, the device
shall assert DMARQ. The host shall then respond by negating CS0- and CS1-, asserting
DMACK-, and beginning the data transfer by asserting, then negating, DIOW- or DIOR- for
each word transferred. CS0- and CS1- shall remain negated as long as DMACK- is asserted.
The host shall not assert DMACK- until the device has asserted DMARQ. The host shall initiate
DMA read or write cycles only when both DMARQ and DMACK- are asserted. Having asserted
DMARQ and DMACK-, these signals shall remain asserted until at least one word of data has
been transferred.
The device may pause the transfer for flow control purposes by negating DMARQ. The host
shall negate DMACK- in response to the negation of DMARQ. The device may then reassert
DMARQ to continue the data transfer when the device is ready to transfer more data and
DMACK- has been negated by the host.
The host may pause the transfer for flow control purposes by either pausing the assertion of
DIOW- or DIOR-pulses ,or by negating DMACK-. The device may leave DMARQ asserted if
DMACK- is negated. The host may then reassert DMACK- when DMARQ is asserted and
begin asserting DIOW- or DIOR- pulses to continue the data transfer.
When the multi-word DMA data transfer is complete, the device shall negate DMARQ and the
host shall negate DMACK- in response.
DMARQ shall be driven from the first assertion at the beginning of a DMA transfer until the
negation after the last word is transferred. This signal shall be released at all other times.
DMA Read Cycle and Write Cycle waveforms are shown in the Figure 2.
Figure 2: Read Cycle and Write Cycle waveform for the DMA mode of transfer
CoolRunner-II CoolRunner-II CPLD implementation of the IDE Controller supports the following features:
IDE Controller • Intel PXA270 CPU Static Memory Interface in 16-bit VLIO mode
Implementation • ATA PIO mode 0
• ATA Multi Word DMA mode 0, 1 and 2
• External SRAM interface for data buffering
• Data throughput
♦ Maximum data throughput achieved with 16-bit CPU interface and SRAM access time
of 55 ns is 6.4 Mbytes/sec
♦ Maximum data throughput achieved with 16-bit CPU interface and SRAM access time
of 10 ns is 7.4 Mbytes/sec
♦ Maximum data throughput possible with 32-bit CPU interface and SRAM access time
of 10 ns is 10 Mbytes/sec
• Only one hard disk interface
Signal Descriptions
The I/O signals of the CPLD IDE controller are described in the following tables
Table 1: CPU Interface Signals
Name Input/Output Description
104 MHz clock input to CPLD; connected to SDCKx
CPU_CLK_I I
line of the PXA270 CPU
Active Low asynchronous reset signal; connected to
CPU_RST_N_I I
the nRESETOUT line of the PXA270 CPU
Active Low chip select signal; connected to the nCSx
CPU_CS_N_I I
line of the PXA270 CPU
Address signals from CPU, which are used to decode
CPU_ADDR_I [9:0] I the device register access and the SRAM access;
connected to the MA[10:1] lines of the PXA 270 CPU
Data bus between the PXA270 CPU and the core;
CPU_D_IO [15:0] I/O
connected to the MD [15:0] lines of the PXA 270 CPU
Active Low write enable input; connected to the nPWE
CPU_WE_N_I I
line of the PXA270 CPU
Active Low read enable input; connected to the nOE
CPU_OE_N_I I
line of the PXA270 CPU
Interrupt from the CPLD to CPU; connected to the
CPU_INTR_O O
GPIOx line of the PXA 270 CPU
Ready signal to insert the wait state; connected to
CPU_RDY_O O
RDY line of the PXA270 CPU
Block Diagram
The block diagram of the IDE controller as shown in Figure 3 is broken into four major blocks:
CPU interface and register,SRAM controller, PIO state machine, and the DMA state machine.
CPU_CLK_I
CPU_RST_N_I
CPU_ADDR_I[9:0] ATA_RESET_N_O
PIO
CPU_D_IO[15:0] STATE ATA_CS_N_O[1:0]
CPU MACHINE
INTERFACE ATA_DA_O[2:0]
CPU_WE_N_I
AND
CPU_OE_N_I REGISTER ATA_DD_IO[15:0]
BLOCK DMA
CPU_CS_N_I STATE ATA_DIOR_N_O
MACHINE
CPU_INTR_O
IDE ATA_DIOW_N_O
INTERFACE
CPU_RDY_O
ATA_INTRQ_I
SRAM Interface
ATA_DMACK_N_O
SRAM_ADDR_O[13:0]
ATA_DMARQ_I
SRAM_DD_IO[15:0]
SRAM
SRAM_WE_N_O CONTROLLER
SRAM_OE_N_O
SRAM_CS_N_O
2:1 Timing Mode R/W 00 Selects the timing mode for the DMA
mode of transfer
00--Mode 0 (Cycle Time--480 ns)
01--Mode 1 (Cycle Time--150 ns)
10--Mode 2 (Cycle Time--120 ns)
Command Register
Command Register is used to select between read and write operation on IDE interface.
Table 8: Command Register
Command Register Address offset: [3:1] = b011
Bit Bit Name R/W Default Description
15:2 - - 0 Reserved
0 Read Command R/W 0 When set, this bit initiates a read from IDE
device. In DMA mode, the Read Command
has to be cleared by the user after the
completion of the read cycle.
0--No command
1--Read from IDE device
3 SRAM Status Bit This register is used to enable the SRAM Status
Interrupt Enable bit interrupt towards the CPU.
0- SRAM Status bit interrupt is not enabled
1- SRAM Status bit interrupt is enabled
SRAM Controller
A 16-bit asynchronous SRAM will be used to store the data from the CPU/IDE device for the
DMA Transfer. The SRAM is broken into 2 blocks, buffer1 and buffer2. SRAM location 0 to 255
is called buffer1. SRAM location 256 to 511 is called buffer2.
rst_n ==1’b0
IDLE
cpu_oe or
cpu_we or
dma_oe
dma_we
READ WRITE
Writing or reading data to/from the SRAM will be performed by the state machine, which has
three states. The states are explained below.
When the DMA State Machine is accessing the SRAM, if the CPU requests an SRAM access,
the ready signal to the CPU will be held Low to extend the CPU cycle. After the DMA access is
completed, asserting the READY signal completes CPU access. DMA is given higher priority to
access the SRAM than the CPU.
IDLE:
Default state when there is no read or write operation to SRAM. In this state ,write enable, read
enable, and chip select signals to the SRAM are de-asserted. A 3-bit counter is used for SRAM
read/write cycle access time. The counter is reset to 0.
READ:
The state machine jumps from IDLE state to this state when there is read request from either
the CPU or the DMA state machine. In this state, the Count value is incremented by one on the
positive edge of the clock. SRAM Read Enable and SRAM Chip Select are asserted. Stable
SRAM Address is driven for the full SRAM read cycle. Read data from SRAM will be latched
when the Count value becomes 5 and the state machine moves to IDLE state.
WRITE:
The state machine jumps from the IDLE state to this state when there is a write request from
the DMA state machine or CPU. In this state the Count value is incremented by one on the
positive edge of the clock pulse. Write Enable and Chip Select to SRAM are asserted, and data
to be written will be driven on the SRAM data bus. Once the Count value becomes 5, the state
machine will jump to the IDLE state.
rst_n ==1’b0
Wr_cmd/Rd_cmd
IDLE SETUP_START
Count>0
END SETUP
HOLD PULSE_START
Count>0
HOLD_START PULSE
Count>0
Count==0
This mode transacts with the register block to perform data read and write operations with the
IDE device. It has only one mode of operation. In this mode, the cycle time is 614 ns.
The state machine has eight states. The function performed in the each state is explained
below.
IDLE:
Default state when there is no data transfer between the CPU and the device. On reset the
state machine will be in this state. In this state the DIOW_N and DIOR_N signals will be in the
High state. If a read or write command is issued from the CPU by setting the Command
Register, then the state machine will jump to the SETUP_START state.
SETUP_START:
In this state, Count is loaded with 0x8 for address valid to the DIOR_N/DIOW_N Setup value
(77ns). In this state DIOR_N and DIOW_N will be in High state. This state is maintained for only
one clock cycle.
SETUP:
This state is maintained until the address to DIOR_N/DIOW_N Setup is valid. In this state,
every positive edge of the clock count value is decremented. Once the count value becomes
zero, it will jump to the PULSE_START state. In this state ,DIOR_N and DIOW_N will be in High
state.
PULSE_START:
In this state, Count is loaded with 0x1D for DIOR_N/DIOW_N pulse width (297 ns). If the Write
command bit in the Command Register is set, DIOW_N is asserted Low; else, if the Read
command in the Command Register is set, DIOR_N will be asserted. The state machine will be
in this state for only one clock cycle before it jumps to the PULSE state.
PULSE:
This state is maintained until the DIOR_N/DIOW_N pulse width value is valid. In this state, for
each clock cycle the Count value is decremented. Once the Count value becomes zero, it will
jump to the HOLD_START state.
In this state, during the Write cycle, write data from the processor will be driven on the IDE data
bus; during the Read cycle, when DIOR_N goes High, data from the IDE bus will be latched and
written to the PIO Read/Write Data Register.
HOLD_START:
In this state, Count is loaded with 0x15 for DIOR_N/DIOW_N to address a valid hold (144ns).
In this state ,DIOR_N and DIOW_N is driven High. The state machine will be in this state for
only one clock cycle, and then jumps to HOLD state. In this state DIOR_N and DIOW_N will be
in High state.
HOLD:
This state is maintained until DIOR_N/DIOW_N to address a valid hold. For each clock cycle,
the Count value is decremented by one. Once the Count value becomes zero, it will jump to the
END state. In this state, DIOR_N and DIOW_N will be in High state.
END:
In this state DIOR_N and DIOW_N will be in High state. The next state will be the IDLE state
((Wr_cmd) &&( (sram status bit1==1’b0)||
(sram status bit0==1’b0)))| |((Rd_cmd)
&&( (sram status bit1==1’b1)|| (sram
status bit0==1’b1)))&&DMA_req SETUP_START
Count>0
rst_n ==1’b0
SETUP
IDLE
count == 0
PULSE_START
Count>0
PULSE
count == 0 count == 0
HOLD_START
Mode0 || Mode 2
END Mode1 DELAY
HOLD Count>0
HOLD_LAST
Mode1||
Mode2
((Wr_cmd) &&( (sram status bit1==1’b0)||
(sram status bit0==1’b0))) ||((Rd_cmd)
&&( (sram status bit1==1’b1)|| (sram Mode 0
status bit0==1’b1)))&&DMA_req
DELAY_LAST
DMA mode has a DMA timing module that will give different timing performance according to
the user configuration. This DMA mode state machine will transact with the register block and
SRAM controller to perform data read and write operations with the IDE device.
The DMA state machine has three modes of operation. They are Mode 0, Mode1, and Mode2.
The state machine has 11 states. The function performed in the each state is explained below.
IDLE:
This is the default state when there is no data transfer between the CPU and the device. On
reset, the state machine will be in this state. In this state, DIOR_N and DIOW_N and
DMACK_N signals will be in the High state.
In this state, if the device asserts DMARQ, and DMA mode is enabled, the state machine
checks whether the read or write command is set in the Command Register. If the write
command bit in the Command Register is set, and the SRAM status bit is set, a read enable is
sent to the SRAM controller. Once data is available, the SRAM state machine will move to the
SETUP_START state. If a read command bit in the Command Register is set, and the SRAM
status bit is zero, the state machine moves to the SETUP_START state.
SETUP_START:
In this state, Count is loaded for the DMACK_N to DIOR_N/DIOW_N Setup with a value
corresponding to each mode of transfer. The DMACK_N signal is asserted in this state. If the
write command bit is set and the SRAM status bit is High, a read enable is sent to the SRAM
controller. If read address is the last location of buffer1, SRAM status bit0 is reset to zero. If the
read address is the last location of buffer2 , the SRAM Status bit1 is reset to zero. The state
machine will be in this state for only one clock cycle and will then move to SETUP state.
SETUP:
This state is maintained until the address to DMACK_N to DIOR_N/DIOW_N Setup time is
valid. In this state, each clock cycle count value is decremented. Once the count value
becomes zero, the state machine will jump to the PULSE_START state.
PULSE_START:
In this state, Count is loaded for DIOR_N/DIOW_N pulse width with the value corresponding to
each mode of transfer. If the write command bit in the Command Register is set, DIOW_N will
be asserted; else, if the read command bit in the Command Register is set, DIOR_N will be
asserted. The state machine will be in this state for only one clock cycle and then jump to the
PULSE state.
PULSE:
This state is maintained until the DIOR_N/DIOW_N pulse width value is valid. In this state, each
clock cycle count value is decremented. Once the count value becomes zero, the state
machine will jump to the HOLD_START state.
In this state, during the write cycle, write data will be placed in the IDE data bus; during the read
cycle, when DIOR_N goes High, data on the IDE data bus will be latched, and write enable to
SRAM controller will be asserted. If the write location in SRAM is the 256th location the SRAM,
status bit0 in Register will be set. If the write location in SRAM is the 512th location the SRAM,
status bit1 in Register will be set.
HOLD_START:
This state will be valid for one clock cycle. The DIOW_N and DIOR_N signals will be pulled
High in this state. For Mode2, the next state will be the HOLD_LAST state; for other modes of
transfer the next state will be the HOLD state.
HOLD:
This state is also maintained for one clock cycle. In this state, DIOR_N and DIOW_N will be in
the High state. The next state will be HOLD_LAST.
HOLD_LAST:
In this state, the state machine checks whether DMARQ from the device is still asserted. If
DMARQ is asserted and the write command bit in the Command Register is set, and an SRAM
status bit is High, the state machine will move to DELAY_START. If DMARQ is asserted and the
read command bit in the Command Register is set, and an SRAM status is Low, the state
machine will move to DELAY_ START. If any of the above conditions are not true, the state
machine will move to the END state. In this state, DIOR_N and DIOW_N will be in High state.
DELAY_START:
For DMA mode 0 transfer, the next state will be the DELAY state. For all other DMA modes, the
next state will be the SETUP_START state. In this state, the count will be loaded with the value
0x15 (144ns) for mode 0. In this state, DIOR_N and DIOW_N will be in High state.
DELAY:
This state is maintained until the count value becomes zero. Once the count value becomes
zero, it will jump to the SETUP_START state. In this state, DIOR_N and DIOW_N will be in High
state.
END:
The DMACK_N signal will be de-asserted in this state. This state is maintained for only one
clock cycle. The next state will be the IDLE state. In this state, DIOR_N and DIOW_N will be in
High state.
Operational The flow of the interface between the CPU and the IDE Controller is detailed in the following
Flow Diagram flow charts. These flow charts are meant to be a guide for using the IDE Controller.
Begin
NO Is
Transmit Empty bit
is set
Yes
Is NO
Transmit Empty bit
is Set
Yes
END
Begin
NO Is
Receive Full bit
is set
Yes
END
Begin
Is
Sram status bit0 No
Sram status bit1
is clear
is clear
Yes Yes
Write the data to the Write the data to the
Buffer1 of the sram Buffer2 of the sram
No Was it the
Last Sector
Yes
No
Sram status bit0
& sram status bit1
are cleared
Yes
END
Begin
Yes Yes
Read the data from the Read the data from the
Buffer1 of the sram Buffer2 of the sram
Yes Yes
clear the sram status bit0 of Clear the sram status bit1 of
the interrupt status register the interrupt status register
No Was it the
Last Sector
Yes
END
Verilog Test A Verilog test bench has been developed that verifies the IDE Controller implementation. This
Bench and test bench contains a CPU BFM that emulates the bus cycles of the PXA270 CPU, has a BFM
of a IDE device, and an SRAM model, and will provide a user-friendly environment which can
Functional be used to run test cases so as to test the IDE Controller.
Simulation The details of the test bench and BFM implementation are explained in a test plan document.
Each test case is supported, and the way of running each test case is explained in the test case
document.
The test environment for the IDE Controller with SRAM of 55 ns is available in the IDE-
Simulation-55ns.zip file. You can unzip this file for functional simulation purposes. The
test environment for the IDE Controller with SRAM of 10 ns is available in IDE-Simulation-
10ns.zip file. You can unzip this file for functional simulation purposes.
The ModelSim command file, func_sim.do, can be used to open the correct waveform
window and run the simulation.
The test bench files are:
1. ATA_tb.v is the top module which will instantiate the Processor BFM, Sram BFM , IDE
device BFM and ATA Top module
2. cpu_mem_cntrl.v is the CPU BFM.
3. cpu_task.v is task file for CPU read and CPU write operations.
4. cy62126dv.v is the SRAM BFM.
5. ata_device.v is an ide device BFM
6. define.v will contain the define statements used in BFMs.
Cool Runner II The top level file for the IDE Controller is ATA Block, which has been entered as a hierarchical
CPLD Verilog file showing the interconnection between the ata_cpu_if block, the ata_sram_interface
block, the ata_pio_sm block and the ata_dma_sm block. The codes for the IDE Controller with
Implementation SRAM access time of 55ns, along with the full project is available in the IDE-Synthesis-
55ns.zip file. You can unzip this file to get the Verilog files of the various modules of the IDE
Controller. The codes for the IDE Controller with SRAM access time of 10 ns, along with the full
project is available in the IDE-Synthesis-10ns.zip file. You can unzip this file to get the
Verilog files of the various modules of the IDE Controller.
The IDE Controller design has been targeted to a CoolRunner-II 256 macrocell device using
the Xilinx Project Navigator. The speed grade chosen is dependent on the system clock
frequencies and should be analyzed by the designer to determine which speed grade is
required.
The Verilog Files are: -
1. ATA.v is the top module of the IDE Controller module
2. ata_cpu_if.v is the CPU Interface module
3. ata_sram_interface is the SRAM Interface module
4. ata_pio_sm is the PIO State Machine module
5. ata_dma_sm is the DMA State Machine module
An IDE Controller with SRAM access time of 55 ns utilizes 227 of the 256 macrocells available
in the device.
Table 11: CoolRunner-II CPLD 256-Macrocell Utilization for IDE Controller with SRAM
Access Time of 55 ns
Resource Available Used Utilization
Macrocells 256 227 89%
P-terms 896 747 84%
Registers 256 166 65%
I/O Pins 106 93 88%
Function Block Inputs 640 549 86%
IDE Controller with SRAM access time of 10ns utilizes 233 of the 256 macrocells available in
the device.
Table 12: CoolRunner-II CPLD 256-Macrocell Utilization for IDE Controller with SRAM
Access Time of 10 ns
Resource Available Used Utilization
Macrocells 256 233 91%
P-terms 896 705 78%
Registers 256 165 64%
I/O Pins 106 93 88%
Function Block Inputs 640 570 89%
Note: The following properties have to be selected, in order, as shown below, before running synthesis
in Xilinx Project Navigator. All other properties should be set to their default values.
Synthesis Properties: - Set advanced
Synthesis Options: -
Optimization Goal: Speed
Fitting Properties: - Set Advanced
Fitting: -
Implementation Template: Optimize Balance
I/O Voltage Standard: LVTTL
Collapsing Input Limit: 20
Collapsing P-term Limit: 30
Function block Input Limit: 40
Timing Report:
Make sure the UCF (User Constraint File) file is attached to the project. The name of the UCF
file is ATA.ucf.
The implementation details for the IDE Controller with SRAM access time of 55 ns are available
in the IDE-Synthesis-55ns.zip file.
The implementation details for the IDE Controller with SRAM access time of 10ns are available
in the IDE-Synthesis-10 ns.zip file.
Post-Fit Timing The Xilinx Project Navigator software package outputs a timing Verilog model of the fitted
Simulation design. This post-fit Verilog was simulated with the original Verilog test bench to ensure design
functionality using ModelSim. Please note that all verification of this design has been done
through simulations.
The user of this design is strongly encouraged to thoroughly inspect the timing report for this
design to insure that the design meets the timing specification of the system. The user is also
strongly encouraged to perform post-fit timing simulations as well.
The details of test bench and BFM implementation are explained in the test plan document.
Each test case is supported, and the way of running each test case is explained in the test case
document.
The test environment for the IDE Controller with SRAM 55 ns is available in the IDE-
Simulation-55ns.zip file. You can unzip this file for timing simulation purposes. The test
environment for the IDE Controller with SRAM 55 ns is available in the IDE-Simulation-
10ns.zip file. You can unzip this file for timing simulation purposes.
Limitations
The ModelSim command file, time_sim.do, can be used to open the correct waveform
window and run the simulation.
Source Code To obtain the Verilog source code for the IDE Controller, and all the accompanying modules,
please
Conclusion This document details the design of an IDE Controller using a CoolRunner-II CPLD.
Revision The following table shows the revision history for this document.
History
Date Version Revision
05/30/06 1.0 Initial Xilinx release.
R
Using a Xilinx CoolRunner-II CPLD as a
Data Stream Switch
XAPP944 v1.0 June 14, 2006
Summary This application note shows how a Xilinx CoolRunnerTM-II CPLD can be used as a simple
logical switch that can quickly and reliably select between different MPEG video sources. The
source code for the design is available on the Xilinx website, and is linked from the “VHDL
Code” section. The code can be expanded by the user to perform additional operations using
the remaining CPLD resources.
Introductions As consumer electronics become more complex, we are seeing a significant increase in the
number of formats used to transfer data. Video and audio both come in a multitude of different
formats, and often from different sources. Managing this data and ensuring the right data
arrives at the right destination at the right time is a challenge.
In our example, we use a CoolRunner-II CPLD to select between three MPEG-2 video sources;
these could be Satellite, Cable and Terrestrial television. The selected data source can then be
sent to a decoder to be streamed to a display, stored on a Hard Disk Drive (HDD), as would
happen in a Digital Video Recorder (DVR), or sent over a serial link to another piece of
equipment.
MPEG-2 Data The MPEG-2 encoded data from the different sources arrives in Transport Streams (TS). The
Sources Transport Stream consists of 8 bits of data (TS_DATA) and 3 control bits (TS_CLK, TS_SYNC
and TS_VAL). This example requires that each data source can be selected with a physical
input, so three select inputs are required. If you want to have an electronically generated select
signal, only two select signals will be necessary. Finally, the example also requires that the
outputs of the multiplexer can be put into a 3-state condition to isolate them from the system.
This is easy to achieve in the CoolRunner-II architecture.
CPLD Before implementing even a simple design inside a Xilinx CoolRunner-II CPLD, it is important
Background to understand the architecture. CPLDs are rich in logical resources. The logical array in the
CoolRunner-II architecture is a 40x56 PLA – 40 input signals to the logical array can be used to
create up to 56 Product (AND) Terms. Product Terms can then be used in any of the 16
Macrocells, containing registers, which are associated with each logical array. The I/O of the
CoolRunner-II CPLD can operate at 1.5V, 1.8V, 2.5V and 3.3V by simply changing an attribute
when coding the design.
More information on the CoolRunner-II architecture can be found in data sheets and application
notes on the www.xilinx.com website.
© 2006 Xilinx, Inc. All rights reserved. All Xilinx trademarks, registered trademarks, patents, and further disclaimers are as listed at http://www.xilinx.com/legal.htm. PowerPC is
a trademark of IBM Inc. All other trademarks and registered trademarks are the property of their respective owners. All specifications are subject to change without notice.
NOTICE OF DISCLAIMER: Xilinx is providing this design, code, or information "as is." By providing the design, code, or information as one possible implementation of this feature,
application, or standard, Xilinx makes no representation that this implementation is free from any claims of infringement. You are responsible for obtaining any rights you may
require for your implementation. Xilinx expressly disclaims any warranty whatsoever with respect to the adequacy of the implementation, including but not limited to any warranties
or representations that this implementation is free from claims of infringement and any implied warranties of merchantability or fitness for a particular purpose.
The design requires 37 input pins and 11 output pins. Using Table 1 below, you can see that
the appropriate device/package is the XC2C64A-VQ100.
Table 1: CoolRunner-II Package/I/O Matrix
XC2C32A XC2C64A XC2C128 XC2C256 XC2C384 XC2C512
I/O Banks 2 2 2 2 4 4
QFG32 (21)
QFG48 (33)
VQ44 (33) VQ44 (33)
PC44 (33) PC44 (37)
CP56 (33) CP56 (45)
Packages and
VQ100 (64) VQ100 (80) VQ100 (80)
User I/O
CP132 (100) CP132 (106)
TQ144 (100) TQ144 (118) TQ144 (118)
PQ208 (173) PQ208 (173) PQ208 (173)
FT256 (184) FT256 (212) FT256 (212)
FG324 (240) FG324 (270)
XC2C64A CPLD
TS2_DATA,, TS2_CLK, TS2_VAL, TS2_SYNC Output Transport Stream
MPEG Multiplexer
Select Enable
3 bits
Figure 1: MPEG Multiplexer
All the I/O pins in this design are configured to the LVCMOS33 3.3V I/O standard. Depending
on the state of the select lines, one of the three Transport Streams, TS1, TS2 and TS3, will be
directed to the output of the device. When a logic 0 is applied to the enable signal, the outputs
of the CPLD will be put into 3-state mode regardless of the condition of the select signals. This
example is intended to supply data to an MPEG-2 receiver and decoder, and then directly to a
display. The MPEG-2 Transport Stream uses short (188 byte) packet lengths. As broadcast
environments can be prone to error and the loss of one or more packets, receiver devices are
usually able to correct small errors. Hence losing one or two bits of data while changing
between sources will not matter. If the MPEG-2 sources were to be stored, such as when used
in a DVR, the user could use the remaining resources in the CPLD to register the data to
ensure that no bits are lost.
Performance This is a simple design that only passes through a small amount of logic. Hence, if implemented
and Utilization in the slowest speed grade, the XC2C64A-7, the pin to pin combinatorial delay is only 14.8ns.
As the MPEG-2 standard often has clock and data speeds of 27 MHz, this is easily handled. All
similar signals travel through the same path in the CPLD, so they will emerge from the other
side with negligible skew, because of to the deterministic nature of the timing model and
architecture.
Table 2 shows the resource utilization of the implemented design. It is clear that the limiting
factor in choice of device is the number of I/O. It is also evident that there are plenty of logic and
register resources available if the user wants to expand the functionality of the design.
Table 2: Device Utilization
Function Block
Macrocells Product Terms Inputs Registers Pins
Used/Total Used/Total Used/Total Used/Total Used/Total
12/64 (19%) 35/224 (16%) 37/160 (23%) 0/64 (0%) 48/64 (75%)
For the sake of simplicity, we ran the simulation with randomly generated data rather than
properly formatted MPEG-2 data.
VHDL Code To obtain the VHDL code for this application note, please use the following link:
XAPP944 - http://www.xilinx.com/products/xaw/coolvhdlq.htm
Conclusion Due to their flexibility, Xilinx CoolRunner-II CPLDs are found in a variety of digital consumer
products. Multiplexing of MPEG-2 Transport Streams can easily be performed by a
CoolRunner-II CPLD with resources to spare for performing further operations. The VHDL
design supplied with this application note shows the simplest form of multiplexing between
such data sources. If the user requires further functionality, there are many resources available
in the CPLD in which to create it.
Revision The following table shows the revision history for this document.
History
Date Version Revision
06/14/06 1.0 Initial Xilinx release.
Revision History
R
Supporting Multiple SD Devices with
CoolRunner-II CPLDs
XAPP906 (v1.0) June 10, 2006
Summary There has been an increasing demand to add multiple Secure Digital (SD) devices in a single
system. Whether the system application calls for a combination of SD memory ports, 802.11
SDIO cards or any other SDIO expansion cards, there is no question that the SD protocol is
currently hitting its stride. The problem, however, is that most host devices (i.e. Intel PXA270, TI
OMAP, or Qualcomm MSM processors) only provide a single SD interface. Fortunately,
CoolRunner-II CPLDs can be used to allow host devices to support any number of SD devices.
This application note details a scalable, auto-sensing bidirectional multiplexer based design.
SD
Device
1.8V 3.3V
Host Controller CoolRunner-II
(ASIC or μP) CPLD
SD
Device
Select Lines
This implementation is extremely flexible and scalable, meaning that the number of SD ports
can be increased or decreased as desired. The design also supports any of the defined SD
card modes -- SPI, 1-bit, or 4-bit data modes.
While the primary purpose of using a CoolRunner-II device in this type of application is to
provide additional SD ports to the host controller, secondary benefits include level translation
and logic isolation between the host and the SD card. Figure 2 shows the case where the host
is 1.8V, but the SD Devices are 3.3V. CoolRunner-II CPLDs provide negligible standby current
and ultra low dynamic power consumption. Hence, incorporating a CoolRunner-II CPLD will not
have a significant impact upon your power budget.
© 2006 Xilinx, Inc. All rights reserved. All Xilinx trademarks, registered trademarks, patents, and further disclaimers are as listed at http://www.xilinx.com/legal.htm. PowerPC is
a trademark of IBM Inc. All other trademarks and registered trademarks are the property of their respective owners. All specifications are subject to change without notice.
NOTICE OF DISCLAIMER: Xilinx is providing this design, code, or information "as is." By providing the design, code, or information as one possible implementation of this feature,
application, or standard, Xilinx makes no representation that this implementation is free from any claims of infringement. You are responsible for obtaining any rights you may
require for your implementation. Xilinx expressly disclaims any warranty whatsoever with respect to the adequacy of the implementation, including but not limited to any warranties
or representations that this implementation is free from claims of infringement and any implied warranties of merchantability or fitness for a particular purpose.
CPLD Design
CLK
CLK
VDD
VDD
VSS SD Memory
VSS Card (A)
D0-3(A) D0-3, CMD
CMD(A)
CLK
VDD
VSS SD Memory
Card (B)
D0-3(B) D0-3, CMD
CMD(B)
This reference design is fully compliant with the SDA Specification. The following section will
show you how to satisfy the above requirements while supporting any number of SD devices
using a controller with a single bus.
CPLD Design
and allows data to flow accordingly (either from the host to the SD card or from the SD card to
the host). A directional control pin is not required, thereby making this design easy to use.
SD Select 1
SD Select 2
SD Bus 1
CMD
DAT0
DAT
A 0
SD 1
SD Host Controller
DAT1
DAT
A 1
Bidirectional MUX
CLK
DAT2
DAT
A 2
SD Bus DAT3
DAT
A 3
CMD
DAT0
DAT1
DAT2
DAT3 SD Bus 2
CMD
DAT
A 0
DAT0
CLK DAT
A 1
DAT1 SD 2
DAT
A 2
DAT2 CLK
DAT
A 3
DAT3
CoolRunner-II
The host can access each SD device individually without affecting the state of the other when
the multiplexer is switched accordingly. If neither the host nor the SD is driving data, the
CoolRunner-II CPLD allows the system to be in the default high impedance with weak pull-up
state. The primary purpose of this circuit is to provide additional SD capability to the host, but
this circuit can also be used to provide level translation and/or logic isolation.
Implementation Details
Figure 5 shows the actual logic circuit for a 1:2 bidirectional multiplexer design, which can be
found described using VHDL (see “VHDL Download”). In the initial condition or idle state, the
Host and SD Cards should be high impedance with a weak pull-up. Hence, the circuit in
Figure 5 is designed to tristate the CoolRunner-II device’s output buffers, thereby allowing the
external pull-up resistors to take effect. Register A (A_REG) and Register B (B_REG) are both
designed to be initialized to logic ’0’ upon power-up.
The SD Cards are selected via the ’Select’ inputs to the CPLD. When ’Select’ is logic ’0’, SD1
is chosen and when ’Select’ is logic ’1’, the SD1 device is chosen. For simplicity while
describing this circuit, let us assume in the following discussion that the Host is only choosing
to communicate with SD1.
The autodirectional control aspect of this design is implemented in the following manner -- A
transaction is initiated when either the host or SD1 drives low. For example, if the host wants to
send data to the SD1 device, the host would begin by driving the A side low. Upon driving low,
the logic in the circuit detects the low going edge and responds by enabling the ’B’ output buffer,
but continues to keep the ’A’ output buffer disabled. Specifically, when A is driven low, a rising
edge is delivered to the clock input of A_REG. After clocking, A_REG’s Q output becomes logic
’1’ and therefor prevents B_REG from receiving a clocking event. In parallel with the A_REG
clocking and triggering, gate B1 outputs a logic ’1’ when A goes low. This enables the ’B’ Output
Buffer and, ultimately, B will follow A and drive low.
Design Verification
Conversely, when it is driven from low to high, gate B1 outputs a low and tristates the B output
buffer. This forces B to go high (via the external pull-up resistor). Once the A and B sides are
both high, A_REG and B_REG are reset to 0. This process is repeated indefinitely. The reverse
happens when SD1 attempts to drive data toward the host. Additionally, if the host wishes to
communicate with the SD2 device, the ’Select’ inputs to the circuit are set to a logic ’1’ and the
sequence of events are similar to the above.
B1
SD1
D Q
SEL
A
R
Q D
R SEL
B2
SEL
SD2
D Q
SEL
Device Utilization
critical nature of this circuit, a -4 speed grade CoolRunner-II device is required (See Table 3).
Figure 6 shows some simulation results.
In the first part of Figure 6, the Select input is held low. A dotted white line denotes a "Weak 1"
condition, or, in other words, represents a pulled up state. In the first transaction, the host
attempts to drive data toward SD1, and SD1 follows accordingly. Immediately after, the SD1
device attempts to drive data toward the host, and the host follows. Similar events happen when
the Select input is driven low. The host drives data toward the SD2 device, then the SD2 device
drives data toward the host.
Device Table 3 shows device utilization statistics for various implementations. As stated in the SDA
Utilization specification, there are three signaling modes defined for SD cards: SPI Mode, 1-bit SD Data
Transfer Mode, and 4-bit SD Data Transfer Mode. This design can be easily adapted for any
chosen mode. The design can also accommodate any number of SD expansion ports. A -4
speed grade is required, due to certain timing critical paths in the design.
Voltage and The SDA Specification contains stringent voltage and current requirements for SD cards.
Current CoolRunner-II devices are ideal for this application because they are extremely low power and
have features such as I/O Banking. The CoolRunner-II I/O’s can be configured as 1.5V, 1.8V,
Considerations 2.5V or 3.3V allowing them to interface to any SD device. CoolRunner-II CPLDs also contain
I/O Banks, which allow for voltage translation capabilities between the processor and SD card.
The extremely low power nature of the CoolRunner-II family allows for standby operation as low
as 15 μA. The addition of a CoolRunner-II device in a system will minimally impact the current
budget.
VHDL The VHDL files to compile and simulate these designs are located at:
Download http://www.xilinx.com/products/xaw/coolvhdlq.htm
Conclusion
Conclusion As SD devices gain in popularity, the need will increase for ways to support more than one SD
device with host controllers. This application note provides a verified solution to the problem at
hand. This solution will give designers the flexibility to implement two or more SD devices into
a system.
Revision The following table shows the revision history for this document.
History
Date Version Revision
06/10/06 1.0 Initial Xilinx release.
Chapter 2
Chapter 2
© 2005 Xilinx, Inc. All rights reserved. XILINX, the Xilinx logo, and other designated brands included herein are trademarks of Xilinx, Inc.
All other trademarks are the property of their respective owners.
Introduction No other CPLD approaches specified standby current without using external logic to
block switching inputs. Adding external logic increases system power and cost. Data
sheet statements about static current are simply incomplete, and potentially useless or
dangerous. You cannot measure static current without external modification. This has
little value, in real world circuits, except to state: If all inputs were stopped, then current
drawn would be X microamps.
Unfortunately, for real world designs this statement has little meaning. To gain the
benefits of low static current may require massive design changes. DataGATE gives
you additional power reduction using no external resources.
VCCINT Current The current savings on VCCINT are substantial, as shown in Table 1.
Savings
Table 1: Current Drawn on VCCINT from Switching Inputs with/without DataGATE at 50
MHz.
Current Drawn on VCCINT (mA)
Inputs Switching No DataGATE With DataGATE Savings
0 0.02 0.02 0%
1 0.82 0.02 97%
2 1.62 0.02 98%
3 3.09 0.02 99%
4 5.40 0.02 99%
Figure 1, Figure 2, Figure 3, and Figure 4 graphically show how VCCINT current
savings increase versus input signal frequency.
0.9
0.8
1.8
1.6
1.4
Iccint (mA)
1.2
1 Iccint (Datagate)
0.8 98% Iccint (No Datagate)
0.6
0.4
0.2
0
0 20 40 60
Frequency (MHz)
3.5
3
2.5
Iccint (mA)
2 Iccint (Datagate)
1.5 99% Iccint (No Datagate)
1
0.5
0
0 20 40 60
Frequency (MHz)
5
Iccint (mA)
4
Iccint (Datagate)
3
99% Iccint (No Datagate)
2
0
0 20 40 60
Frequency (MHz)
What about At this point, we have established that a ‘Standby Current’ specification is relatively
VCCIO Current? useless. No real design can operate with zero inputs toggling. We have also
established that CoolRunner-II is the only CPLD in the world that allows a user to
approach standby current without physically disconnecting all inputs. But all
discussion thus far has concentrated on current drawn through the VCCINT rail. What
about current drawn through VCCIO?
The entire industry avoids discussing current drawn through VCCIO. No PLD
manufacturer provides any specification whatsoever regarding how much current the
I/Os will draw. Examine any CPLD data sheet. You will find that all ICC versus
Frequency graphs are specific to VCCINT current. No reference is ever made to VCCIO.
Why? This is primarily because current drawn through the I/Os is difficult for
manufacturers to determine because it is dependent upon too many external variables
(capacitive loading, frequency, current requirements, input rise time, and so on). In
addition, as VCCIO current can be significant (so significant that it can invalidate a
device’s low power message), most manufacturers have tended to avoid it.
Let’s examine the effect of simply switching a few inputs. This time, instead of looking
at VCCINT, let’s look at VCCIO. How much current does that draw, and, can DataGATE
do anything to reduce VCCIO current?
As can be seen in Table 2, this VCCIO current can be quite large. However, with
DataGATE asserted, the CoolRunner XC2C128 device can essentially shut down the
internal I/O buffers and accomplish 99% power savings on the VCCIO rail. Figure 5,
Figure 6, Figure 7, and Figure 8 show VCCIO current savings versus input switching
frequency.
10
9
Vccio Current (mA)
8
7
6 Iccio (Datagate)
5
4 99% Iccio (No Datagate)
3
2
1
0
0 20 40 60
Frequency (MHz
16
14
30
25
Vccio Current (mA)
20
Iccio (Datagate)
15
99% Iccio (No Datagate)
10
0
0 20 40 60
Frequency (MHz)
40
35
We have already demonstrated one of the greatest kept secrets in the CPLD world --
although VCCINT dynamic current can be quite low, VCCIO current can exceed VCCINT
current by as much as 4x! It is no wonder that manufacturers do not specify VCCIO
current. Instead, they focus on what appears to be an extremely low standby current,
which is basically useless. They focus on dynamic VCCINT current, which is
substantially less than VCCIO current.
Other devices may appear to be low power, but only one device actually is low power.
CoolRunner-II devices are the only CPLDs providing 99% savings on VCCINT and 99%
power savings on VCCIO.
Conclusion Table 1 and Table 2 understate the problem. Data was taken with simple buffers,
showing the effect of blocking inputs into the chip. If those inputs connected to
multiple sites within the CPLD, additional power would be drawn, driving the
capacitance of the additional connections. Hence, the more complex the design, the
more power is saved by blocking inputs. Because we cannot anticipate how much
logic your inputs will drive, it is difficult to estimate how much current will be saved
for a particular design. However, one thing is certain: CoolRunner-II is the leading low
power device not only because it has low dynamic power consumption, but also
because it is the only CPLD that allows a design to approach standby current during
full operation.
Additional Xilinx has invested considerable time in developing the best ways to reduce power in
Resources digital systems that use our parts. The following documents give an idea of the many
ways to approach the problem, so please become familiar with them as you select the
methods that work best for you.
XAPP 395 describes how DataGATE works and outlines a general approach for
reducing your power. Briefly, you simply create your design as you wish and measure
your power (typically ICC). Then, you identify signals that may be blocked, and
redefine your design to block them with the DataGATE signal. You then measure your
current and see if enough reduction occurs. If it works correctly and you wish to
remove more current, block some more signals. Keep blocking and measuring to
reduce current. If you block signals to the extent that the design no longer works,
simply go back one step to the last point that worked. There are other approaches, but
this one works well.
XAPP378 shows how to drive the design software to take advantage of the
CoolRunner-II advanced features. DataGATE is one of many such features, as are
advanced clocking (division, DualEDGE), Schmitt trigger inputs, and slew rate
control.
XAPP436 shows how a CoolRunner-II CPLD can reduce power in other chips, along
with the CPLD itself. This approach uses DataGATE to block switching signals that are
not needed in the other chip, and contributes to the overall system power usage. If you
are using CoolRunner-II as a level translator, you get DataGATE power management
for free on devices of 128 macrocells and above. This application note explains how.
XAPP 377 shows a set of low power design practices, including DataGATE. There are
many ways to reduce power, and Xilinx CPLDs show more ways to do that than any
other competitor.
If you are not interested in measuring power, XAPP 317 shows how to apply the
CoolRunner-II power equation to arrive at a reasonable estimate of your application’s
power usage. Just working with the equation factors can provide insight into ways to
reduce it, as well.
Finally, if you want to understand the deeper workings, U.S. Patent #6,172,518 goes
through the original approach for DataGATE. It was originally invented for the Xilinx
XC9500/XL/XV family of CPLDs, but was only used in the CoolRunner-II Family,
where dramatic power reduction would be most appreciated.
Revision The following table shows the revision history for this document.
History
Date Version Revision
05/30/05 1.0 Initial Xilinx release.
R
Power Evaluation Equation for
CoolRunner-II CPLDs
XAPP317 (v1.0) September 23, 2003
Summary This application note provides a quick and simple method for estimating power consumption of
CoolRunner-II CPLDs. As an alternative to XPower, power can be quickly and easily computed
using the provided equation and coefficients as described in this application note.
Introduction Many times, users wish to evaluate the potential value of using a low power device such as the
CoolRunner-II CPLD prior to designing the system. This precludes using XPower as a power
evaluation tool since the system design is usually not a point that is useful to XPower. It is often
that design engineers are simply evaluating devices early in the design cycle to determine
which is best regarding not only power, but pricing, density, features, etc. It is in these cases
that a simple method of evaluating power consumption can be useful. The designer does not
often have time early in the design cycle to complete a full power evaluation. Using a simple
equation, as described below, will greatly assist the designer during this evaluation period.
CoolRunner-II CPLDs are supported in XPower starting with FISE 6.1i or ISE WebPACK 6.1i.
Derivation The equation given in this application note was derived first by breaking down the capacitive
elements of the device. All CMOS logic devices consume power in two basic ways: Static
current, and dynamic current.
Static Current
Static current is the current which exists as current flows through the PMOS and NMOS
transistors in a logic element when either of these transistors is turned off. This is an artifact of
CMOS structures since these devices leak small amounts of current when one of these
transistors is in the off state. Summing these leakages over the complete structure of the device
will yield static current for the entire device. The equation represents this current as ICCSB.
In addition, static current in CoolRunner-II CPLDs contains a component due to other circuitry
active in the background that is not accessible to the user.
In CoolRunner-II CPLDs, static current is consistent regardless of design and therefore is not a
calculated value.
Dynamic Current
Dynamic current is realized when the logic gates change states. Current flows momentarily
through the P and N channel transistor in a logic gate when both are turned on at the same
time. Figure 1 shows a non-inverting buffer where through current is denoted as Transition
Current, commonly known as crowbar current. Transition current is a minor portion of dynamic
current due to fast edge rates within the CoolRunner-II CPLD and is therefore considered
negligible.
In addition, dynamic current is comprised of other effects of a switching logic gate. Specifically,
charge must enter or leave the gate of the next logic element in the chain and is supplied using
© 2003 Xilinx, Inc. All rights reserved. All Xilinx trademarks, registered trademarks, patents, and further disclaimers are as listed at http://www.xilinx.com/legal.htm. All other
trademarks and registered trademarks are the property of their respective owners. All specifications are subject to change without notice.
NOTICE OF DISCLAIMER: Xilinx is providing this design, code, or information "as is." By providing the design, code, or information as one possible implementation of this feature,
application, or standard, Xilinx makes no representation that this implementation is free from any claims of infringement. You are responsible for obtaining any rights you may
require for your implementation. Xilinx expressly disclaims any warranty whatsoever with respect to the adequacy of the implementation, including but not limited to any warranties
or representations that this implementation is free from claims of infringement and any implied warranties of merchantability or fitness for a particular purpose.
Derivation
the P channel transistor or is removed using the N channel transistor of the first logic gate, as
shown in Figure 1. Similarly, the routing between gates consists of a capacitive element that
must also be charged or discharged in a similar manner.
If the logic gate is the last in the chain of logic and is driving an external load, this load will also
have a capacitive element to its structure. For example, this external load can be the printed
circuit board (PCB) trace capacitance and the input capacitance of subsequent devices.
Charge
Transition
Discharge
X317_01_092203
Using this method, CMOS logic elements can therefore be modeled as simple capacitors. The
basic equation to calculate dynamic current consumed in a capacitor is:
I = C⋅ V⋅ f
where:
• I = current, in Amperes
• C = capacitance, in Farads
• V = voltage, in Volts
• f = frequency, in Hz
Summing these capacitive elements over the entire structure of the CMOS device, total
dynamic current can be calculated. In the simple equation given below, total capacitance is
assumed to be lumped as one capacitive element to simplify the task of deriving the equation.
Over the entire device, dynamic current can further be broken down into several categories to
attempt to gain granularity in the calculation: core, I/O and load currents. The core current is
comprised of the logic gates which make up the total user functional design. I/O current is
derived from I/O logic switching, which is simply the I/O buffer. Load current is found when the
I/Os must charge and discharge the external load capacitive elements. These three elements
will toggle based on the user/system supplied frequency.
Data Source
The equation in this application note requires the user to insert numbers for some coefficients.
These coefficients are included in Table 1 below and are derived in the laboratory.
The Equation
16 bit up/down binary counters only have 2 product terms per macrocell, and half of these
product terms do not toggle when using the counter in either direction. Also, all product terms
and macrocells do not toggle at the same time, reducing the amount of total logic that changes
states at any one time. Effectively, 12.5% of macrocells in each counter toggles over time where
the MSBs toggle very infrequently with respect to the clock. This type of characterization
method is, therefore, not a good benchmark for programmable logic devices. Unfortunately, the
PLD industry has selected the 16 bit binary counter as the prime design for comparison.
With this in mind, it is important to understand that the equation and coefficients given below
will yield a "ball park" estimate, and are by no means to be considered accurate or a prime
standard. XPower was designed to provide a much more accurate representation of power
consumption in CoolRunner-II CPLDs. Again, this equation is intended to provide the system
designer with an early taste of power consumption in CoolRunner-II CPLDs during the device
selection phase of the design process.
The Equation Below is the equation for calculating total current in the CoolRunner-II CPLD. Again, this
equation is intended to provide an evaluation value for current consumption and is simply a "ball
park" estimate.
C L ⋅ V L⎞
I CC = I CCSB + MC TOG ⋅ f MC ⋅ MC ⋅ A + IO TOG ⋅ f IO ⋅ IO ⋅ ⎛ B ⋅ V CCIO + -------------------
-
⎝ 1000 ⎠
where:
ICC = total device current, in mA
ICCSB = quiescent current, in mA
MC = total number of non-I/O macrocells used in design
IO = total number of bi-directional or output macrocells used in design
fMC = maximum clock frequency of non-I/O macrocells, in MHz
fIO = maximum clock frequency of I/O macrocells, in MHz
MCTOG = average non-I/O macrocell toggle rate, usually 12.5% (as a fraction, e.g. 0.125)
IOTOG = average I/O macrocell toggle rate, usually 12.5% (as a fraction, e.g. 0.125)
VCCIO = I/O power supply voltage, in V
Conclusion
For CoolRunner-II CPLDs where the I/Os are operated in SSTL or HSTL modes, add 2mA per
I/O configured in this manner.
Toggle rate is based on the percentage of edges the average macrocell toggles with respect to
the clock active edge. It is typical to specify a number of 12.5% which is derived from the 16 bit
binary counter example. In this example, the LSB toggles on 100% of the rising edges of the
clock, yielding 1/2 the frequency of the clock at the output of the register. The next significant bit
toggles at 50% of the rising clock edges resulting in 1/4 the clock frequency at the register
output. Evaluating all 16 bits in this manner yields an average of 12.5% toggle rate for all
registers in the counter. It is up to the user to determine the average toggle rate of the
macrocells or I/Os based on the intended design. As a quick reference 12.5% may be useful,
but toggle rate will vary with different designs.
To obtain power in mW, use the above equation as modified below:
2
⎛ 2 C L ⋅ VL
P = V CC ⋅ ( I CCSB + MC TOG ⋅ f MC ⋅ MC ⋅ A ) + IO TOG ⋅ f IO ⋅ IO ⋅ ⎜ B ⋅ V CCIO + -------------------
-
⎝ 1000
where:
P = total device power, in mW
Vcc = core voltage, in V
For CoolRunner-II CPLDs where the I/Os are operated in SSTL or HSTL modes, there is 2mA
adder per I/O configured in this manner. Therefore, add to the results VCCIO times 2mA per pin
with this configuration.
Conclusion The equation given in this application note provides the designer with an easy method for
evaluating the future use of CoolRunner-II CPLDs in a proposed system. This equation
provides a value that is reasonable compared to the actual characteristics of the device, but
should not be considered an accurate number. XPower should be used to obtain more accurate
numbers if this is desirable.
Revision History
Revision The following table shows the revision history for this document.
History
Date Version Revision
09/23/03 1.0 Initial Xilinx release.
Revision History
R
Low Power Design with CoolRunner-II
CPLDs
XAPP377 (v1.0) May 8, 2002
Summary CoolRunner™-II CPLDs are the only CPLD to combine both high performance and low power
to form the next generation CPLD. This application note describes the design methodologies
that can be employed to obtain the lowest power possible using the CoolRunner-II CPLD by
utilizing its unique power saving features.
Introduction CoolRunner-II CPLDs continue to employ the features of Fast Zero Power™ (FZP) technology
as found in the earlier CoolRunner CPLD generations. But due to unique Xilinx design
techniques, smaller geometries, and state of the art process technology, FZP technology has
further advanced CoolRunner-II CPLDs as the low power standard. Other CPLD
manufacturers have attempted to reproduce the FZP true CMOS technology of the CoolRunner
CPLDs, but have not been able to meet the CoolRunner benchmark. For the first time in the
CPLD industry, CoolRunner-II devices deliver both true high performance and low power at the
same time, along with the lowest standby current in the industry without the use of power down
modes. In addition, these devices offer unique power saving features such as CoolCLOCK,
DataGATE, and DualEDGE flip-flops.
Traditional CPLDs use sense amp type product terms to provide fast propagation delay times.
Sense amp product terms are biased in a manner to detect a small change in voltage levels on
the word line which indicates a change in the logic state of the product term. The transistor
biasing constantly draws current, even at standby. With this in mind, these types of CPLDs
cannot provide a low power solution, as can CoolRunner-II CPLDs. As sense amp type device
sizes become larger in macrocell count, power grows significantly since there are many more
product terms to consume power.
As process technology shrinks, sense amp type CPLDs will inherently consume more power to
maintain performance. Smaller process technology demands lower power supply voltages
thereby reducing the gain of the sense amp. Further, product term transistors leak more with
the smaller geometries. To maintain performance, a sense amp CPLD will need to be designed
such that its biasing compensates for the leakage and boosts gain to detect the smaller voltage
swing of the word line. Higher biasing will cause more current to flow through the bias network,
thereby increasing total power consumption. Other CPLD manufacturers that use sense amp
based technology will inevitably go through a learning process to re-design their current
products to compensate for the effect of ever shrinking process technology.
CMOS product terms, as used in the FZP technology, inherently consume less power when not
switching states. Since CMOS logic exhibits low standby current, CoolRunner-II CPLDs use
this technology to reap the benefits of low power. Additionally, CMOS technology benefits from
smaller geometries where the device consumes less power and becomes faster.
Power Saving New architectural features have been added to the CoolRunner-II product line to enhance the
Features power saving capabilities of the FZP technology. This section describes these features and
how they can be used to save power.
© 2002 Xilinx, Inc. All rights reserved. All Xilinx trademarks, registered trademarks, patents, and further disclaimers are as listed at http://www.xilinx.com/legal.htm. All other
trademarks and registered trademarks are the property of their respective owners. All specifications are subject to change without notice.
NOTICE OF DISCLAIMER: Xilinx is providing this design, code, or information "as is." By providing the design, code, or information as one possible implementation of this fea-
ture, application, or standard, Xilinx makes no representation that this implementation is free from any claims of infringement. You are responsible for obtaining any rights you may
require for your implementation. Xilinx expressly disclaims any warranty whatsoever with respect to the adequacy of the implementation, including but not limited to any warran-
ties or representations that this implementation is free from claims of infringement and any implied warranties of merchantability or fitness for a particular purpose.
All new features described below are available with the XC2C128 and larger devices. The
smaller devices, XC2C32 and XC2C64, do not include some features, specifically DataGATE,
Clock Divider, and CoolCLOCK.
DataGATE
Many times devices are connected to a data bus which are not being addressed by the master
device. When a CPLD is in this situation, it will use more power than necessary since the data
on the bus is not useful to the CPLD, but the data lines continue to toggle, which subsequently
toggles the internal logic of the CPLD. Any logic that changes state within the CPLD will
consume power. Therefore, it follows that disconnecting the CPLD from the data bus when the
device is not addressed conserves power, as highlighted in this example.
DataGATE solves this issue by disconnecting external signal activity from the internal logic,
consequently reducing power consumption of the device. This is achieved by using a unique,
software enabled, CoolRunner-II pass gate at the I/O pin (when configured as an input) which
is controlled by the DataGATE global net. This control net originates from a specific
pin/macrocell and can be driven by either an external signal or an internally developed signal
using logic elements. When the pass gate on the input pin is disabled by the DataGATE control
net, an internal latch drives the CPLD logic network maintaining the same logic level that was
present on the input pin just prior to asserting the DataGATE control net. This preserves the
current logic state internal to the CPLD while external data changes states.
For example, a CoolRunner-II CPLD that shares a data bus with other devices will most likely
have its own address and typically will not be addressed continuously. Two options exist to
disconnect the data bus from the CoolRunner-II CPLD when not addressed. First, if the device
is addressed using a chip select signal, this signal can be assigned to the DataGATE control
pin and used to isolate the inputs from the data bus. Second, if using an address bus, the
address of the device can be decoded internally to the CPLD which can then be used to enable,
via DataGATE, the data bus inputs to receive data when addressed. When the CPLD is not
addressed, DataGATE would disconnect the external data bus signals using address decoding
internally to the CPLD. In this case, the result of the internal decoding is routed to the
DataGATE pin to disconnect the toggling bus.
DataGATE can be configured to affect any or all I/O pins, with the exception of JTAG pins and
the DataGATE pin itself. The above example discusses DataGATE configured to affect a few
macrocell I/O pins. It may be beneficial in other applications to disconnect the system clock or
clocks from the CPLD. The two elements that consume the most power are output buffers and
the clock tree. If the CPLD is not needed for a specific amount of time, the DataGATE feature
could be used to gate the clock. Doing so will dramatically reduce power consumption.
However, caution must be exercised when gating a clock since undesired logic transitions may
occur.
There are other cases where the unique CoolRunner-II DataGATE feature is useful to reduce
power. Also, DataGATE is flexible such that the entire device or only parts of the device can be
isolated from external signals, depending on the application. For example, it can be used in
CoolRunner-II CPLDs to enhance board troubleshooting procedures.
Schmitt Trigger
CoolRunner-II Schmitt trigger inputs are useful for applications that require hysteresis on the
inputs. A useful application might be where noise is an issue on specific pins. Hysteresis
provides added noise immunity. Another application could implement an oscillator circuit which
is constructed external to the CPLD, but CPLD logic is used to implement portions of the
oscillator circuit.
To ensure the lowest power consumption in the CoolRunner-II CPLDs, disable the Schmitt
trigger inputs since these types of buffers consume more power than the regular input buffer. It
is important to design and operate the system in a low noise environment when Schmitt triggers
are disabled to prevent inadvertent transitions on the CPLD inputs.
Clock Divider
Global clock networks tend to be the largest power consuming elements in CPLDs. Any effort
to reduce the frequency of the global clock network greatly benefits the system with respect to
power consumption. Therefore, CoolRunner-II devices have been designed to include a clock
divider network on global clock, GCK2. Without introducing additional clock delays, the clock
divider has the capability of dividing the system clock by even integers ranging from 2 to 16, as
shown in Figure 1.
¸2
¸4
¸6
GCK2 Clock ¸8
¸10
In
¸12
¸14
¸16
Synch Rst
CDRST X377_01_041102
Some systems use state machines, for example, that do not require the full speed of the
external system clock. A clock divider is the perfect tool to reduce system power in this case.
The clock divider provides an excellent alternative to adding a user defined clock divider built
from logic, which would waste logic otherwise usable for more features in the design. A lower
frequency on the global clock network, provided by the clock divider, will reduce the power
consumed by the CoolRunner-II CPLD.
Generally speaking, designing with the slowest system clock possible will reduce power
consumption. To this end, the clock divider provided in the CoolRunner-II architecture will
greatly assist the designer.
DualEDGE Registers
By utilizing both edges of the clock signal, the macrocell can do twice the work when configured
as a DualEDGE flip-flop. Figure 2 displays the macrocell configured as a DualEDGE flip-flop. A
system without the aid of the DualEDGE flip-flop would need to provide a clock at twice the
frequency to obtain the same work output at the macrocell. Since the macrocells with
DualEDGE flip-flops operate on both the rising and falling edges of the clock, the clock network
is used more efficiently. Consequently, power consumption is reduced when the global clock
net is operating at a lower frequency.
D/T Q
PTC CE FIF
Latch
CK ✓DualEDGE
GCK0
GCK1
CTC GCK2
PTC
x377_02_041102
DualEDGE flip-flops further enhance the functional possibilities of the clock divider and
therefore improve power savings. The global clock can be effectively divided by odd integers of
3, 5, and 7 if used with the DualEDGE flip-flop. For example, if a divide by 3 clock is desired for
the design, the Clock Divider can be set to a divide by 6 and then effectively doubled by the
DualEDGE flip-flop resulting in a divide by 3 characteristic. This is important to note since,
again, lower clock frequencies always save power. The DualEDGE flip-flop effectively adds
more functionality to the clock divider network.
Perhaps the design contains two state machines. One state machine can efficiently operate at
1/4th the system clock frequency, yet the other state machine can much more efficiently
operate at 1/8th the system clock frequency. DualEDGE flip-flops can be employed in
conjunction with the clock divider to obtain such a scenario. The state machine running at 1/8th
the system clock frequency can simply use the clock divider configured as divide by 8. Enabling
the DualEDGE flip-flop on macrocells assigned to the other state machine and assigning the
divide by 8 clock divider to those macrocells as well will yield an effective clock frequency that
is 1/4th the system clock frequency. This means that the single clock divider can obtain virtual
dual functionality of a divide by 8 and a divide by 4 counter. Notice that both clocks are
synchronized with each other and the system clock so that the two state machines operate
concurrently.
Summarizing the previous discussion, when utilizing the CoolRunner-II clock divider and/or the
DualEDGE flip-flops, it is possible to obtain clock divisors of 2, 3, 4, 5, 6, 7, 8, 10, 12, 14 and 16.
Additionally, when a group of macrocells use the clock divider and some of those macrocells
use DualEDGE flip-flops, the clock divider network can effectively deliver two clock frequencies
of divisors 1-2 (using CoolCLOCK described later), 2-4, 3-6, 4-8, 5-10, 6-12, 7-14, and 8-16.
When DualEDGE flip-flops are used with the clock divider, lower power is achieved while more
efficiently operating the design.
CoolCLOCK
CoolRunner-II CPLDs are equipped with a unique feature, CoolCLOCK, to further reduce the
power consumption of the global clock network without affecting the speed of the clock. Note
that CoolCLOCK does not impose additional clock delays. As explained earlier, any efforts to
reduce the clock frequency of the global clock net will significantly reduce power consumption.
CoolCLOCK reduces power consumed by the global clock net by dividing the external clock
frequency by 2 before it is applied to the global clock network. This clock division occurs early
in the clock tree near the clock input buffer so that the divided clock affects the majority of the
clock network. Since the global clock network contains a relatively large amount of internal
capacitance, a slower frequency will significantly reduce power consumed by this net, GCK2.
This divided clock signal is then effectively doubled at the macrocell using the DualEDGE
clocking feature of the flip-flops in the macrocell, shown in Figure 3. This ensures that the
original clock frequency is applied to the macrocell as intended by the external system. Only
macrocells that require the original clock frequency will be configured to utilize the DualEDGE
flip-flop feature. Other macrocells can be configured to use the divided clock frequency to
further reduce power when those macrocells don’t require clocking at full speed.
D/T Q
PTC CE FIF
Latch
GCK0 CK ✓ DualEDGE
GCK1
CTC GCK2
PTC
÷2
÷4
÷6
GCK2 Clock ÷8
÷10
In
÷12
÷14
÷16
Synch Rst
Synch Reset
X377_03_041102
Slew Rate
This is a feature of the I/O structure that regulates the rate at which the output buffer changes
states. There are two modes: FAST and SLOW. Designers concerned with reducing reflections
on circuit board traces, minimizing RFI or minimizing EMI should specify a SLOW slew rate.
Most design engineers considering low power designs will usually be designing slower speed
systems and therefore will not be as concerned with reflections. In a case such as this, the
system will benefit from a lower power perspective when slew rate is specified to be FAST.
Although an I/O is configured as an output, the input buffer is still connected to the pin and
therefore senses changes in voltage on that pin. If the output is configured with a SLOW slew
rate, the output voltage switches states less quickly, thereby lingering longer between standard
logic levels. The input buffer will therefore be driven in the linear region (the input voltage
between standard logic levels) for a longer period of time than if the output was configured in
the FAST slew rate mode. Current will flow through the input buffer P and N channel transistors
for a longer period of time resulting in higher power consumption. It is therefore recommended
to configure the output with a FAST slew rate whenever reflections are not a concern.
Power Saving Several rules of thumb should be followed when designing any circuit with CMOS devices to
Techniques reduce power consumption. A basic understanding of power consumption must be reached
prior to discussing these rules of thumb. Therefore, a derivation of the current equation for
CMOS devices is necessary. Once the mathematical model of current is understood, it
becomes easy to follow the theory of the rules of thumb. To maximize power savings, the
designer should apply these concepts when implementing any CMOS device.
I = C ⋅ dV ⋅ f
Since the voltage for capacitive structures in CMOS devices changes as a square wave with
discontinuities between logic HighHigh and Low and is ideally rail to rail, we can further simplify
the equation. For example, in a system of supply voltage, V, the change in voltage, dV, is V to
0V as shown and reduced here:
dV = V 2 – V 1
dV = V – 0
dV = V
I = C⋅ V⋅ f
where:
• I = current in Amperes
• C = the capacitance of the capacitive structure in Farads
• V = the system voltage in Volts
• f = the toggle frequency of the capacitive structure in Hz
Dynamic device current is the summation of all capacitive structures toggling over time. Voltage
remains the same for all equations and can be assumed to be a constant. A device of n
capacitive structures can be represented as follows:
n
I Dynamic = V ⋅ ∑ Ci ⋅ fi
i=1
To obtain total device current, static current must be added to the dynamic current:
n
I Total = I Static + V ⋅ ∑ Ci ⋅ fi
i=1
For illustrational purposes, it may be easier to discuss total current using a simplified version of
this equation:
I CC = I CCQ + C ⋅ V ⋅ f
where:
• ICC = total device current in Amperes
• ICCQ = quiescent device current in Amperes
• C = the lumped capacitance of the device in Farads
• V = the system voltage in Volts
• f = the average device toggle frequency in Hz
Recall that to obtain power, multiply current by voltage to yield Watts.
Bus Terminations
A different case where pull down resistors are necessary is when shunt bus termination is
required to reduce reflections in high speed designs. These terminations are usually designed
to be pull down resistors whose value equals the equivalent impedance of the data bus
transmission line and are positioned as close to the load pin as possible. Whenever the output
buffer is driving a transmission line with shunt resistors, the P channel transistor will source
current into the load and therefore will raise power consumption.
It may be possible to avoid using shunt termination resistors by using a very short transmission
line. The rule of thumb for a short transmission line is one whose length is less than one-sixth
the electrical length of the rise time, and is described using the following equation:
1 Trise
Length « --- ⋅ ------------
6 LC
where:
• Length = maximum line length in inches
• Trise = rise time in seconds
• L = the line inductance in Henries/inch
• C = the line capacitance in Farads/inch
By using the CoolRunner-II CPLD slew rate feature configured to SLOW, the rise time becomes
longer. Using the above equation, it can be determined if the length of the transmission line can
be effectively long enough to avoid reflections altogether. If by using the SLOW slew rate
feature, the length of the transmission line is short by the above rule of thumb, shunt bus
termination resistors can be avoided thereby saving power.
If either method is not an option, insert a series termination resistor positioned at the source pin
with the same value as the transmission line impedance. This option will avoid excessive power
consumption (since there is no shunt load) and eliminate reflections at the source. However, a
series termination resistor will allow one reflection at the load (since the load impedance does
not match the transmission line impedance) which implies that any component mid way
between the source and the load will see two transitions: the incident wave and the single
reflected wave created at the load.
Resistive loading is usually found when devices with a resistive element to their impedance is
attached to the bus. For example, a pull down resistor attached to a PCB trace will allow for
current to flow from the CMOS device power rail, through the P channel of the output buffer
transistor, through the resistor, and to ground, increasing observed power consumption at the
CMOS device power pins. Reducing resistive loads will reduce power consumption.
Keep in mind that many components are comprised of more than one type of impedance
element. For example, capacitors also have resistive and inductive elements, albeit small.
Conclusion For the first time in the CPLD industry, CoolRunner-II products combine true high speed logic
with ultra low power. Unique features of the CoolRunner-II CPLD, such as CoolCLOCK and
DataGATE, allow the designer to further reduce power consumption. By using these features
combined with good design practice, as outlined in this document, designers can be assured
that their design will experience optimal low power benefits without sacrificing high speed.
References 1. Johnson H. and Martin G. (1993): High-Speed Digital Design: A Handbook of Black Magic
Prentice Hall PTR
Revision The following table shows the revision history for this document.
History
Date Version Revision
05/08/02 1.0 Initial Xilinx release.
Chapter 3
4. Generate a netlist.
EDIF is the industry-wide standard for netlists; many others exist, including vendor-
specific ones such as the Xilinx Netlist Format (XNF). Once you have the design netlist, you
have all you need to determine what the circuit does.
Design Flow
STAT_MAC
Specification
clock CLK AUG amber_light
Libraries Counter
CLOCK COUNT (3.0)
RESET
Schematic
Capture Design Schematic
Netlist
101010101001110101010101
010101011110001110100111
101010101001110101010101
010101011110001110100111
101010101001110101010101
010101011110001110100111
101010101001110101010101
010101011110001110100111
Design Netlist
The example on the previous pages is obviously very simplistic. Let’s describe a more
realistic design of 10,000 equivalent gates. The typical schematic page contains about 200
gates, contained with soft macros. Therefore, it would require 50 schematic pages to create
a 10,000-gate design! Each page needs to go through all the steps mentioned previously:
adding components, interconnecting the gates, adding I/Os, and generating a netlist. This
is rather time-consuming, especially if you want to have a 20,000, 50,000, or even larger
design.
Another inherent problem with using schematic capture is the difficulty in migrating
between vendors and technologies. If you initially create your 10,000- gate design with
FPGA vendor X and then want to migrate to a gate array, you would have to modify every
one of those 50 pages using the gate array vendor’s component library.
would have to be loaded, positioned on the page, and interconnected, with I/O buffers
added. That would be about three days of work.
The HDL implementation, which is also 6,000 gates, requires eight lines of text and can be
done in three minutes. This file contains all the information necessary to define our 16 x 16
multiplier. So, as a designer, which method would you choose? In addition to the
tremendous time savings, the HDL method is completely vendor-independent. This opens
up tremendous design possibilities for engineers.
$ESIGN &LOW
3PECIFICATION
,IBRARIES
3CHEMATIC
#APTURE
.ETLIST
$ESIGN 3CHEMATICS
/2
ENTITY -5,4 IS
PORT ! " IN STD?LOGIC DOWNTO
9 OUT STD?LOGIC DOWNTO
END -5,4
ARCHITECTURE "%(!6% OF -5,4 IS
BEGIN
9 !