AN979 STMICROELECTRONICS | Alldatasheet
Document overview
- Manufacturer or author: Provided By ALLDATASHEET.COM(FREE DATASHEET DOWNLOAD SITE)
- PDF pages: 14
Technical content
1 INTRODUCTION
Digital Converter (ADC) of the ST7. tion note is based on ST72F324 which has an embedded 10-bit ADC.
2 ST7 / KEYBOARD INTERFACE
low voltage references as shown in Figure 1. Figure 1. ST7 / keyboard interface set-up
3 ST72324 CONFIGURATION
datasheet for more details on configuring the ST72F324.
3.1 I/O CONTROL
DRIVING AN ANALOG KEYBOARD WITH THE ST7 ADC F (PF0, PF4), and Port C (PC0, PC1, PC5, PC7). The I/O port pins used by the ADC must be configured as floating inputs to avoid conflicts in alternate function mode. Refer to the Data Sheet for information on configuring the I/O ports.
3.2 ANALOG TO D IGITAL CONVERTER
The ST7 ADC is a 10-bit successive approximation converter, with internal sample and hold- circuitry.
3.2.1 ADC control
You control the ADC using the ADC Control Status Register (ADCCSR). The EOC bit is the end of conversion bit: - When this bit is set, the conversion is done and result can be read from the ADC Data Registers (ADCDRL & ADCDRH). - When the bit is reset, the conversion is not complete. The SPEED bit: - When this bit is set, f ADC = fCPU / 2. - When this bit is reset, fADC = fCPU / 4. The ADON bit: - Enable ADC and start conversion when this bit is set. - Disable ADC and stop conversion when this bit is reset. CH3-CH0 bits: - They are used to select which analog input to convert. In the ST72324 there are 12 analog pins.
3.2.2 Characteristics
The conversion time is 15 ADC cycles including a sampling time of 4 ADC cycles. The ADC is linear and the digital result of the conversion is given by the formula: Digital Result =
3.2.3 Process
First the analog input pins must be configured as floating inputs (see Section 3.1). CH0CH1CH2CH30ADONSPEEDEOC 1023*Input Voltage Reference Voltage
Then select the SPEED of conversion. Setting the ADON bit will switch the converter on. Figure 2. Flowchart: initialization of the ADC Once enabled, conversions will run continuously until the peripheral is disabled.
Figure 3. Flowchart: conversion process
4 ANALOG KEYBOARD
4.1 PRINCIPLE
ated with a voltage. The description of an analog keyboard is given by Figure 4. Figure 4. Hardware description of a keyboard with 16 keys R up is a pull-up resistor. So, when no key is pressed, Vkey is equal to VDD .
DRIVING AN ANALOG KEYBOARD WITH THE ST7 ADC When ‘key i’ is pressed (where i is in the range 1 to 15), the resistor Ri-1 is connected to Vss. Then we have a resistive divider and Vkey is given by the formula: So the corresponding voltage of each key is given by the values of the resistors. An equal dis- tribution of voltage between VDD and VSS is usually recommended. To recognize a key, the user will measure Vkey and will be able to decide which key was pressed.
4.2 PRACTICAL LIMITATIONS
Theoretically, with an 10-bit ADC, 1023 keys can be decoded. But potential errors must be taken into account. They can come from the power supply, the key resistivity, the resistor tol- erance, the ADC conversion errors. The resistor tolerance is the main limitation as usually 5% tolerance resistors are used. It is advised to use a 1% tolerance resistor for the pull-up. Changing this resistor greatly improves the keyboard as the pull-up has an influence on every key. The ADC total unadjusted error (TUE) for the device is specified as 4 LSB. So, it has to be taken into account to avoid any key decision error. These parameters will reduce the number of keys that can be efficiently decoded. V key i = (VDD - VSS ) R up + i - 1 Σ j = 0 R j i - 1 Σ j = 0 R j
5 KEY DETECTION
The ST7 is a digital microcontroller. It uses its ADC to measure Vkey. It is then coded in 10 bits. The digital values of the keys after conversion are given in Table 2. subsequent typical values, which gives the best noise margin between keys. The software uses the lower limits to make its decision. They are given in Table 2. Table 1. Example of resistor values for 16 keys
Table 2. Key Values
6 DRIVING AN ANALOG KEYBOARD WITH THE ST7 ADC
6.1 GENERAL DESCRIPTION
A 16-key keyboard is connected to the ST72F324 through the AIN0 pin on Port D. A LED is connected to an output pin (PC0) to indicate to the user that a key is detected. Figure 5. Application circuitry First the software initializes the I/Os and the ADC. When a conversion is done, the software decides if a key was pressed or not. If not, it waits before analyzing the result of a new conversion.
6.2 FLOWCHARTS
itialization routine is presented in Figure 2. Figure 6. Flowchart: main program
Figure 7. Flowchart: key detection
Figure 8. Flowchart: key process
6.3 EXTENSION FOR WAKE UP
Figure 9. Keyboard with wake-up circuitry. is switched to interrupt input with pull-up mode.
DRIVING AN ANALOG KEYBOARD WITH THE ST7 ADC
6.4 SOFTWARE
All the source files in assembly code as well as in C code are given in the zip file with this ap- plication note. The C code uses software library (ST7 software library version 1.1). The source files are for guidance only. STMicroelectronics shall not be held liable for any di- rect, indirect or consequential damages with respect to any claims arising from use of this soft- ware.
DRIVING AN ANALOG KEYBOARD WITH THE ST7 ADC THE PRESENT NOTE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT OF SUCH A NOTE AND/OR THE USE MADE BY CUSTOMERS OF THE INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.” Information furnished is believed to be accurate and reliable. However, STMicroelectronics assumes no responsibility for the consequences of use of such information nor for any infringement of patents or other rights of third parties which may result from its use. No license is granted by implication or otherwise under any patent or patent rights of STMicroelectronics. Specifications mentioned in this publication are subject to change without notice. This publication supersedes and replaces all information previously supplied. STMicroelectronics products are not authorized for use as critical components in life support devices or systems without the express written approval of STMicroelectronics. The ST logo is a registered trademark of STMicroelectronics 2003 STMicroelectronics - All Rights Reserved. Purchase of I2C Components by STMicroelectronics conveys a license under the Philips I2C Patent. Rights to use these components in an I2C system is granted provided that the system conforms to the I2C Standard Specification as defined by Philips. STMicroelectronics Group of Companies Australia - Brazil - Canada - China - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan Malaysia - Malta - Morocco - Singapore - Spain - Sweden - Switzerland - United Kingdom - U.S.A. http://www.st.com