Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
162
Добавлен:
01.03.2016
Размер:
3.56 Mб
Скачать

Analog/digital converter (ADC)

RM0016

 

 

24.4ADC pins

Table 72.

ADC pins

 

Name

 

Signal type

Remarks

 

 

 

 

VDDA

 

Input, Analog

Analog power supply. This input is bonded to VDD in

 

supply

devices that have no external VDDA pin.

 

 

VSSA

 

Input, Analog

Ground for analog power supply. This input is bonded to

 

supply ground

VSS in devices that have no external VSSA pin.

 

 

 

 

 

The lower/negative reference voltage for the ADC,

VREF-

 

Input, Analog

ranging from VSSA to (VSSA + 500 mV).

 

Reference negative

This input is bonded to VSSA in devices that have no

 

 

 

 

 

external VREFpin (packages with 48 pins or less)

 

 

 

 

 

 

 

The higher/positive reference voltage for the ADC,

VREF+

 

Input, Analog

ranging from 2.75 V to VDDA. This input is bonded to VDDA

 

Reference positive

in devices that have no external VREF+ pin (packages with

 

 

 

 

 

48 pins or less)

 

 

 

 

AIN[15:0]

 

Analog input signals

Up to 16 analog input channels, which are converted by

 

the ADC one at a time.

 

 

 

 

ADC_ETR

 

Digital input signals

External trigger.

 

 

 

 

24.5ADC functional description

24.5.1ADC on-off control

The ADC can be powered-on by setting the ADON bit in the ADC_CR1 register. When the ADON bit is set for the first time, it wakes up the ADC from power down mode. To start conversion, set the ADON bit in the ADC_CR1 register with a second write instruction.

At the end of conversion, the ADC remains powered on and you have to set the ADON bit only once to start the next conversion.

If the ADC is not used for a long time, it is recommended to switch it to power down mode to decrease power consumption. This is done by clearing the ADON bit.

When the ADC is powered on, the digital input and output stages of the selected channel are disabled independently on the GPIO pin configuration. It is therefore recommended to select the analog input channel before powering on the ADC (see Section 24.5.3: Channel selection).

24.5.2ADC clock

The clock supplied to the ADC can by a prescaled fMASTER clock. The prescaling factor of the clock depends on the SPSEL[2:0] bits in the ADC_CR1 register.

416/454

Doc ID 14587 Rev 9

RM0016

Analog/digital converter (ADC)

 

 

24.5.3Channel selection

There are up to 16 external input channels that can be selected through CH[0:3] bits of the ADC_SR register. The number of external channels depends on the device (refer to the product datasheets).

If the channel selection is changed during a conversion, the current conversion is reset and a new start pulse is sent to the ADC.

24.5.4Conversion modes

 

The ADC supports five conversion modes: single mode, continuous mode, buffered

 

continuous mode, single scan mode, continuous scan mode.

Note:

ADC1 AIN12 channel cannot be selected in ADC scan mode or with analog watchdog.

 

Values converted from AIN12 are stored only in the ADC_DRH/ADC_DRL registers. Refer

 

to product datasheet for AIN12 availability.

Single mode

In Single conversion mode, the ADC does one conversion on the channel selected by the CH[3:0] bits in the ADC_CSR register. This mode is started by setting the ADON bit in the ADC_CR1 register, while the CONT bit is 0.

Once the conversion is complete, the converted data are stored in the ADC_DR register, the EOC (End of Conversion) flag is set and an interrupt is generated if the EOCIE bit is set.

Continuous and buffered continuous modes

In continuous conversion mode, the ADC starts another conversion as soon as it finishes one. This mode is started by setting the ADON bit in the ADC_CR1 register, while the CONT bit is set.

If buffering is not enabled (DBUF bit = 0 in the ADC_CR3 register), the converted data is stored in the ADC_DR register and the EOC (End of Conversion) flag is set. An interrupt is generated if the EOCIE bit is set. Then a new conversion starts automatically.

If buffering is enabled (DBUF bit =1) the data buffer is filled with the results of 8 or 10 consecutive conversions performed on a single channel. When the buffer is full, the EOC (End of Conversion) flag is set and an interrupt is generated if the EOCIE bit is set. Then a new set of 8 or 10 conversions starts automatically. The OVR flag is set if one of the data buffer registers is overwritten before it has been read (see

Section 24.5.5).

To stop continuous conversion, reset the CONT bit to stop conversion or reset the ADON bit to power off the ADC.

Single scan mode

This mode is used to convert a sequence of analog channels from AIN0 to AINn where ‘n’ is the channel number defined by the CH[3:0] bits in the ADC_CSR register. During the scan conversion sequence the CH[3:0] bits are updated by hardware and contain the channel number currently being converted.

Single scan mode is started by setting the ADON bit while the SCAN bit is set and the CONT bit is cleared.

Doc ID 14587 Rev 9

417/454

Analog/digital converter (ADC)

RM0016

 

 

Note:

When using scan mode, it is not possible to use channels AIN0 to AINn in output mode

 

because the output stage of each channel is disabled when it is selected by the ADC

 

multiplexer.

 

 

A single conversion is performed for each channel starting with AIN0 and the data is stored

 

in the data buffer registers ADC_DBxR. When the last channel (channel ‘n’) has been

 

converted, the EOC (End of Conversion) flag is set and an interrupt is generated if the

 

EOCIE bit is set.

 

 

The converted values for each channel can be read from the data buffer registers. The OVR

 

flag is set if one of the data buffer registers is overwritten before it has been read (see

 

Section 24.5.5).

 

 

Do not clear the SCAN bit while the conversion sequence is in progress. Single scan mode

 

can be stopped immediately by clearing the ADON bit.

 

 

To start a new SCAN conversion, clear the EOC bit and set the ADON bit in the ADC_CR1

 

register.

 

 

Continuous scan mode

 

 

This mode is like single scan mode except that each time the last channel has been

 

converted, a new scan conversion from channel 0 to channel n starts automatically. The

 

OVR flag is set if one of the data buffer registers is overwritten before it has been read (see

 

Section 24.5.5).

 

 

Continuous scan mode is started by setting the ADON bit while the SCAN and CONT bits

 

are set.

 

 

Do not clear the SCAN bit while scan conversion is in progress.

 

 

Continuous scan mode can be stopped immediately by clearing the ADON bit. Alternatively

 

if the CONT bit is cleared while conversion is ongoing, conversion stops the next time the

 

last channel has been converted.

 

Caution:

In scan mode, do not use a bit manipulation instruction (BRES) to clear the EOC flag. This is

 

because this performs a read-modify-write on the whole ADC_CSR register, reading the

 

current channel number from the CH[3:0] register and writing it back, which changes the last

 

channel number for the scan sequence.

 

 

The correct way to clear the EOC flag in continuous scan mode is to load a byte in the

 

ADC_CSR register from a RAM variable, clearing the EOC flag and reloading the last

 

channel number for the scan sequence

 

24.5.5

Overrun flag

 

 

The OVR error flag is set by hardware in buffered continuous mode, single scan or

 

 

continuous scan modes. It indicates that one of the ten data buffer registers was overwritten

 

by a new converted value before the previous value was read. In this case, it is

 

 

recommended to start a new conversion.

 

Note:

Setting the ADON bit automatically clears the OVR flag.

 

418/454

Doc ID 14587 Rev 9

Соседние файлы в папке Минимум документации STM8_1