Lab 7 ADC

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

Lab 7.

ADC
AVR microcontroller
Features
• 10-bit Resolution
• 0.5 LSB Integral Non-linearity
• ±2 LSB Absolute Accuracy
• 13 - 260 µs Conversion Time
• Up to 15kSPS at Maximum Resolution
• 8 Multiplexed Single Ended Input Channels
• 7 Differential Input Channels
• 2 Differential Input Channels with Optional Gain of 10x and 200x
• Optional Left adjustment for ADC Result Readout
• 0 - VCC ADC Input Voltage Range
• Selectable 2.56V ADC Reference Voltage
• Free Running or Single Conversion Mode
• ADC Start Conversion by Auto Triggering on Interrupt Sources
• Interrupt on ADC Conversion Complete
• Sleep Mode Noise Canceler
Overview
The ATmega32A features a 10-bit successive approximation ADC. The ADC is connected to an 8-channel
Analog Multiplexer which allows 8 single-ended voltage inputs constructed from the pins of Port A. The
single-ended voltage inputs refer to 0V (GND).
The device also supports 16 differential voltage input combinations. Two of the differential inputs
(ADC1, ADC0 and ADC3, ADC2) are equipped with a programmable gain stage, providing amplification
steps of 0 dB (1x), 20 dB (10x), or 46 dB (200x) on the differential input voltage before the A/D
conversion. Seven differential analog input channels share a common negative terminal (ADC1), while
any other ADC input can be selected as the positive input terminal. If 1x or 10x gain is used, 8-bit
resolution can be expected. If 200x gain is used, 7-bit resolution can be expected.
The ADC has a separate analog supply voltage pin, AVCC. AVCC must not differ more than ±0.3V from
VCC.
Internal reference voltages of nominally 2.56V or AVCC are provided On-chip. The voltage reference
may be externally decoupled at the AREF pin by a capacitor for better noise performance.
Analog to Digital Converter Block Schematic
ADC Auto Trigger Logic
ADC Prescaler
ADMUX – ADC Multiplexer Selection Register
Bit 7 6 5 4 3 2 1 0

MSB LSB EEDR


R/W R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0

• Bits [7:0] – EEDR7.0: EEPROM Data


For the EEPROM write operation, the EEDR Register contains the data to be written to the EEPROM in
the address given by the ADC Register. For the EEPROM read operation, the EEDR contains the data
read out from the EEPROM at the address given by ADC
ADMUX – ADC Multiplexer Selection Register
Bit 7 6 5 4 3 2 1 0

REFS1 REFS0 ADLAR MUX4 MUX3 MUX2 MUX1 MUX0 ADMUX


R/W R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0

Bit 7:6 – REFS1:0: Reference Selection


Bits These bits select the voltage reference for the ADC, as shown in Table If these bits are
changed during a conversion, the change will not go in effect until this conversion is complete
(ADIF in ADCSRA is set). The internal voltage reference options may not be used if an external
reference voltage is being applied to the AREF pin.
ADMUX – ADC Multiplexer Selection Register
• Bit 5 – ADLAR: ADC Left Adjust Result
The ADLAR bit affects the presentation of the ADC conversion result in the ADC Data Register.
Write one to ADLAR to left adjust the result. Otherwise, the result is right adjusted. Changing
the ADLAR bit will affect the ADC Data Register immediately, regardless of any ongoing
conversions.
ADMUX – ADC Multiplexer Selection Register
Bits 4:0 – MUX4:0: Analog Channel and Gain
Selection Bits
The value of these bits selects which combination
of analog inputs are connected to the ADC. These
bits also select the gain for the differential
channels. See Table for details. If these bits are
changed during a conversion, the change will not
go in effect until this conversion is complete (ADIF
in ADCSRA is set).
ADCSRA – ADC Control and Status Register A
Bit 7 6 5 4 3 2 1 0

ADEN ADATE ADIF ADIE ADPS2 ADPS1 ADPS0 ADCSRA


R/W R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0

Bit 7 – ADEN: ADC Enable


Writing this bit to one enables the ADC. By writing it to zero, the ADC is turned off. Turning the
ADC off while a conversion is in progress, will terminate this conversion.
Bit 6 – ADSC: ADC Start Conversion
In Single Conversion mode, write this bit to one to start each conversion. In Free Running
Mode, write this bit to one to start the first conversion. The first conversion after ADSC has
been written after the ADC has been enabled, or if ADSC is written at the same time as the ADC
is enabled, will take 25 ADC clock cycles instead of the normal 13. This first conversion
performs initialization of the ADC.
ADSC will read as one as long as a conversion is in progress. When the conversion is complete,
it returns to zero. Writing zero to this bit has no effect.
ADCSRA – ADC Control and Status Register A
Bit 5 – ADATE: ADC Auto Trigger Enable
When this bit is written to one, Auto Triggering of the ADC is enabled. The ADC will start a
conversion on a positive edge of the selected trigger signal. The trigger source is selected by
setting the ADC Trigger Select bits, ADTS in SFIOR.
Bit 4 – ADIF: ADC Interrupt Flag
This bit is set when an ADC conversion completes and the Data Registers are updated. The ADC
Conversion Complete Interrupt is executed if the ADIE bit and the I-bit in SREG are set. ADIF is
cleared by hardware when executing the corresponding interrupt handling vector. Alternatively,
ADIF is cleared by writing a logical one to the flag. Beware that if doing a Read-Modify-Write on
ADCSRA, a pending interrupt can be disabled. This also applies if the SBI and CBI instructions
are used.
Bit 3 – ADIE: ADC Interrupt Enable
When this bit is written to one and the I-bit in SREG is set, the ADC Conversion Complete
Interrupt is activated.
ADCSRA – ADC Control and Status Register A
Bits 2:0 – ADPS2:0: ADC Prescaler Select Bits
These bits determine the division factor between the XTAL frequency and the input clock to the
ADC
ADCL and ADCH – The ADC Data Register
Bit 15 14 13 12 11 10 9 8

- - - - - - ADC9 ADC8 ADCH


R/W R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0

Bit 7 6 5 4 3 2 1 0
ADLAR = 0
ADC7 ADC6 ADC5 ADC4 ADC3 ADC2 ADC1 ADC0 ADCL
R/W R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0

Bit 15 14 13 12 11 10 9 8

ADC9 ADC8 ADC7 ADC6 ADC5 ADC4 ADC3 ADC2 ADCH


R/W R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0

Bit 7 6 5 4 3 2 1 0
ADLAR = 1
ADC1 ADC0 - - - - - - ADCL
R/W R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0
SFIOR – Special FunctionIO Register
Bit 7 6 5 4 3 2 1 0

ADTS2 ADTS1 ADTS0 - ACME PUD PSR2 SFIOR SFIOR


R/W R/W R/W R/W R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0

Bit 7:5 – ADTS2:0: ADC Auto Trigger Source


If ADATE in ADCSRA is written to one, the value of these bits selects which source will trigger an ADC
conversion. If ADATE is cleared, the ADTS2:0 settings will have no effect. A conversion will be triggered by
the rising edge of the selected Interrupt Flag. Note that switching from a trigger source that is cleared to a
trigger source that is set, will generate a positive edge on the trigger signal. If ADEN in ADCSRA is set, this
will start a conversion. Switching to Free Running mode (ADTS[2:0]=0) will not cause a trigger event, even if
the ADC Interrupt Flag is set.
Single Conversion Mode
Auto Trigger Mode
Задание
Цель работы: изучить операции по работе с АЦП, режимы работы АЦП, настройка и выбор каналов АЦП,
регистры настройки и управления АЦП.
Необходимо разработать программу, в которой реализовать оцифровку данных, заданное количество
раз, с седьмого канала АЦП (циклическое или по требованию, в зависимости от варианта). Данные из
АЦП необходимо сохранить во внутреннюю память контроллера, и по требованию вывести поочередно
на индикаторы. Временную задержку между отображением данных реализовать с помощью таймера
(ТС0). Вар. Режим АЦП Запуск АЦП Адрес памяти Кол-во оцифровок Вывод данных

1 Однократный INT1 0x60 10 INT0

2 Циклический INT0 0x70 14 INT1

3 Однократный INT1 0x80 18 INT0

4 Циклический INT0 0x90 22 INT1

5 Однократный INT1 0xA0 18 INT0

6 Циклический INT0 0xA5 14 INT1

7 Однократный INT1 0x95 10 INT0

8 Циклический INT0 0x85 14 INT1

9 Однократный INT1 0x75 18 INT0

10 Циклический INT0 0x62 22 INT1

You might also like