ST AN979 APPLICATION NOTE

AN979
APPLICATION NOTE

DRIVING AN ANALOG KEYBOARD WITH THE ST7 ADC

By Microcontroller Division Applications

1 INTRODUCTION

The goal of this application note is to present a standard example of the us e of the Analog to Digital Converter (ADC) of the ST7.

2 ST7 / KEYBOARD INTERFACE

Connect the analog keyboard to one of the analog inputs of the ST 7 and connect the high and low voltage references as shown in Figure 1.

Figure 1. ST7 / keyboard interface set-up

KEYBOARD
ST7
ADC
V
DD
V
SS
analog
input
AINx
high voltage reference
low voltage reference
keyboard
output

3 ST72324 CONFIGURATION

The application has been tested with a ST72F324 configured as described below. Refer to the datasheet for more details on configuring the ST72F324.

3.1 I/O CONTROL

Depending on the num ber of pins av ailable on the device p ackage , th e S T7 theor etically al­lows up to 16 multiplexed analog inputs to the ADC, but in practice, on the ST72F324 device, there can be up to 12 analog inputs. They are alternate functions I/O Port D (PD0-PD5), Port
AN979/0303 1/14
1
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 DIGITAL CONVER TER

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).
CH0CH1CH2CH30ADONSPEEDEOC
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
- When this bit is reset, f
= f
ADC
CPU
= f
/ 2.
CPU
/ 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 s elect which analog i nput 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:
1023*Input Voltage
Digital Result =
Reference Voltage

3.2.3 Process

First the analog input pins must be configured as floating inputs (see Section 3.1).
2/14
DRIVING AN ANALOG KEYBOARD WITH THE ST7 ADC
Then the analog channel to c onvert must be s elected using CH3-CH0 bits of ADCCSR reg­sister.
Then select the SPEED of conversion. Setting the ADON bit will switch the converter on.
Figure 2. Flowchart: initialization of the ADC
KBD_init
I/O Initialization
Channel Selection
SPEED Selecti on
ADC ON
return
Once a conversion is done, the EOC bit is set by hardware. It will be r eset when the ADCDRH register is read.
Once enabled, conversions will run continuously until the peripheral is disabled.
3/14
DRIVING AN ANALOG KEYBOARD WITH THE ST7 ADC
Figure 3. Flowchart: conversion process
Conversion Process
KBD_init
no
EOC = 1 ?
yes
read ADCDRL
read ADCDRH

4 ANALOG KE YBOARD

4.1 PRINCIPLE

The purpose is to recognize a key when pressed. In an analog keyboard each key is associ­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

V
DD
V
key
(Keyboard Value)
R
up
R
0
key 0
key 1
R
1
Σ
with R
is a pull-up resistor. So, when no key is pressed, V
R
up
4/14
>> R
j
up
R
13
R
14
key 14
key 15
is equal to VDD.
key
V
SS
DRIVING AN ANALOG KEYBOARD WITH THE ST7 ADC
When ‘key i’ is pressed (where i is in the range 1 to 15), the resistor R
is connected to Vss.
i-1
Then we have a resistive divider and V
is given by the formula:
key
V
key i
=
(V
DD
R
- VSS)
+
up
i - 1
Σ
j = 0
i - 1
Σ
j = 0
R
R
j
j
So the corresponding voltage of each key i s given by the values of the r esistor s. An equal dis­tribution of voltage between V
To recognize a key, the user will measure V
and VSS is usually recommended.
DD
and will be able to decide which key was
key
pressed.

4.2 PRACTICAL LIMITATIONS

Theoretic ally, wi th an 10- bit ADC , 1023 key s can be decod ed. But po tenti al erro rs 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 toleran ce is the m ain limitati on as us ually 5% tole rance res istors a re us ed. It i s 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 AD C t otal u nad justed e rr or (T UE ) for th e devi ce is spec ifi ed a s 4 LS B. S o, it h as t o be taken into account to avoid any key decision error.
These parameters will reduce the number of keys that can be efficiently decoded.
5/14
Loading...
+ 9 hidden pages