Global Sources
EE Times-India
Stay in touch with EE Times India
 
EE Times-India > Power/Alternative Energy
 
 
Power/Alternative Energy  

STR71x ADC driving an analog keyboard

Posted: 08 Dec 2004     Print Version  Bookmark and Share

Keywords:analog keyboard 

(ADC) to read inputs from an analog keyboard.

/PDF document

AN1809/0104 1/8

Rev. 1.0

AN1809

APPLICATION NOTE

STR71x ADC

DRIVING AN ANALOG KEYBOARD

INTRODUCTION

This application note gives an example of how to use the STR71x Analog to Digital Converter

(ADC) to read inputs from an analog keyboard. The purpose is to decode a number of keys

through only one analog I/O port pin, this has the advantage of reducing the number of pins

used compared to a traditional matrix keyboard which requires a large number of I/O port pins.

1

2/8

I2C COMMUNICATION BETWEEN STR71X AND M24CXX EEPROM

1 HARDWARE CONFIGURATION

To reach the goal of this application note we need to connect an analog keyboard to one of the

analog inputs of the STR71x ADC.

When a key is pressed, the voltage at the ADC input is given by the activated voltage divider.

This analog voltage is converted by the ADC and the digital value is used to determine which

switch is closed.

Figure 1. STR71x ADC and analog keyboard configuration

1.1 STR71X ADC

The STR71x analog to digital converter is a 12-bit Sigma-Delta converter with an input range

between 0 and 2.5V. It has up to 4 multiplexed analog input channels.

It offers two conversion modes:

s Round-robin: Repeats the conversion process for each of the four channels continuously in

turn.

s Single channel: Converts only the selected analog input.

Enabling or Disabling the converter is done by setting or clearing the ADC_EN bit in the

BOOTCONF register.

The STR71x ADC provides four 16-bit data registers to store the conversion result for each

channel. The availability of the conversion result in the data register is shown by the four

DA[3:0] flags in the Control Status Register (CSR).

An interrupt is generated depending on the conversion mode, to confirm the end of conver-

sion. In Single channel mode, an interrupt is generated if the interrupt bit and Data Available

flag in the CSR are set, corresponding to the selected channel. In Round robin mode, an in-

terrupt will be generated if all interrupt bits and all data available flags in the CSR are set.

STR71x

V3.3

ADC

AINx

AVss

AVdd

Vss

R0

R1

R13

R14

Rup key0

key1

key14

key15

Vdd

Vss

Keyboard

2.5v

2

3/8

I2C COMMUNICATION BETWEEN STR71X AND M24CXX EEPROM

The clock configuration of the STR71x converter is used to define the oversampling fre-

quency which clocks the modulator of the Sigma-Delta converter. This frequency is pro-

grammed basing on the fPLCK2 frequency and the Sampling frequency. The oversampling rate

is obtained by configuring the 6 bit of the prescaler register.

The value to write in the Converter prescaler register is:

PRESC = fPLCK2 / (SAMPLE_FREQ * 512 * 4)

The real factor, by which the input frequency will be multiplied to produce the oversampling

frequency, is twice the prescaler register value.

1.2 I/O CONFIGURATION

The STR71x Analog to digital converter provides four analog input pins for connecting dif-

ferent analog signals. These are internally multiplexed to use the same Sigma-Delta logic.

Depending on the conversion mode (Continuous or Single Channel), you can use either the

four analog inputs or only one selected pin. If you are using the Single Channel mode, you can

select a pin by writing the channel number in the AXT [1:0] bits in the control status register.

These pins are mapped on the pins of GPIO port 0 (P0.1, P0.2, P0.3, P0.4).

To use the port pins as analog inputs, you must configure them as High impedance-Analog In-

puts by writing the appropriate values in to the PC0, PC1 and PC2 registers of I/O Port 0.

1.3 ANALOG KEYBOARD

The analog keyboard is formed by a number of keys connected to resistive dividers; with a

pull-up resistor. In the Analog keyboard each key is associated with a voltage.

R0-->R14: Serial Resistor through which keys will be connected to the analog input.

Rup: The pull-up resistor by which the vkey is maintained to Vdd when no key is pressed.

R0

R1

R13

R14

Rup key0

key1

key14

key15

KeyboardTo Vdd

To Analog input

Vkey

To Vss

4/8

I2C COMMUNICATION BETWEEN STR71X AND M24CXX EEPROM

The associated voltage of the pressed key is given by:

If more than one key is pressed at the same time, the key detected will be the next key in the

chain closest to the ADC input. This means that the key recognition is managed by priority.

1.3.1 Key recognition

The number of keys which can be detected depends on the tolerance of the resistors used.

This mean that we must take a voltage range corresponding to each key when we convert the

result.

The resistor value and the equivalent voltage of each key are given by the following table.

Rup =1200

Table 1. Key decision

Key

Resistor

()

Voltage

(mV)

Key

Resistor

()

Voltage

(mV)

0 0 0 8 220 1121

1 56 111 9 270 1273

2 68 234 A 390 1442

3 82 366 B 560 1616

4 100 507 C 820 1788

5 120 654 D 1200 1946

6 150 810 E 1800 2084

7 180 966 F 2800 2200

V

Key

i

Vdd Vss-( ) Rj

j 0=

i 1-

R

up

R

j

j 0=

i 1-

+

----------------------------------------------------=

5/8

I2C COMMUNICATION BETWEEN STR71X AND M24CXX EEPROM

2 SOFTWARE CONFIGURATION

This software example manages the STR71x ADC configuration, and the key recognition

using the ADC software library.

After configuring the analog input as a high impedance analog input, the STR71x ADC has to

be enabled by setting the ADC_EN bit in the BOOTCONF register. This action is followed by

selecting the Single Channel conversion mode and the Channel to be converted by setting the

AXT bit and writing the channel number in the A[1:0] bits in the Control Status Register (CSR).

Next, the prescaler has to be configured. To wait for the availability of data in the corre-

sponding DATA register is done by looping on the Data Available flag (DAn) in CSR. After that,

we can get the conversion result which will be calibrated.

The next step is the key recognition. This part of the software consists of testing if the conver-

sion result belongs to the range of the value of each key voltage. This range is defined by the

lower voltage (min [key]) and the higher voltage (max [key]) that are considered as corre-

sponding to the typical voltage of the key (Val [key]). This range is due to the resistor toler-

ance.

The main program is given by the next flowchart.

6/8

I2C COMMUNICATION BETWEEN STR71X AND M24CXX EEPROM

Figure 2. Main program flowchart using ADC software library

The key recognition routine is shown in the next flowchart with:

max[key]: Higher voltage of the range corresponding to the typical voltage of the key.

min[key]: Lower voltage of the range corresponding to the typical voltage of the key.

val [key]: Typical voltage.

END

Configure the ADC input AINn as High

impedance Analog input

Enable the Converter

Configure the prescaler

Select the channel

Configure single channel mode

Get conversion result

Disable the converter

DA[n]=1?

yes

no

ADC12_ConversionStart();

ADC12_ChannelSelect(ADC12_CHANNEL1);

while (ADC12_FlagStatus (ADC12_DA1) == RESET);

{

...

...

}

ADC12_PrescalerConfig(500);

ADC12_ModeConfig (ADC12_SINGLE);

GPIO_Config (GPIO1, 0x0002, GPIO_HI_AIN_TRI);

Con_Res = ADC12_ConversionValue(ADC12_CHANNEL1);

ADC12_ConversionStop();

Recognize the Key //See the key recognition flowchart

Calibrate the conversion result //See the key recognition flowchart

BEGIN

7/8

I2C COMMUNICATION BETWEEN STR71X AND M24CXX EEPROM

Figure 3. Key recognition

X = conversion result

X = Val[0]

min[2] =< X =< max[2]

min[1] =< X =< max[1]

min[0] =< X =< max[0]

X = Val[2.5]

X = Val[1]

X = Val[2]

X = Val[E]

X = Val[D]

min[F] =< X =< max[F]

min[E] =< X =< max[E]

min[D] =< X =< max[D]

Return the typical value of the key

BEGIN

X = Val[F]

8/8

I2C COMMUNICATION BETWEEN STR71X AND M24CXX EEPROM

"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 express written approval of STMicroelectronics.

The ST logo is a registered trademark of STMicroelectronics.

All other names are the property of their respective owners

) 2004 STMicroelectronics - All rights reserved

STMicroelectronics GROUP OF COMPANIES

Australia - Belgium - Brazil - Canada - China - Czech Republic - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan -

Malaysia - Malta - Morocco - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States

www.st.com





Comment on "STR71x ADC driving an analog keyboar..."
Comments:  
*  You can enter [0] more charecters.
*Verify code:
 
 
Webinars

Seminars

Visit Asia Webinars to learn about the latest in technology and get practical design tips.

 

Go to top             Connect on Facebook      Follow us on Twitter      Follow us on Orkut

 
Back to Top