0% found this document useful (0 votes)
10 views22 pages

252 - EEE 3403 - Lecture#07 - ADC - Part1

Discuss about Analog-to-Digital Converter in Polling and Interrupt mode

Uploaded by

Lutful Kabir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views22 pages

252 - EEE 3403 - Lecture#07 - ADC - Part1

Discuss about Analog-to-Digital Converter in Polling and Interrupt mode

Uploaded by

Lutful Kabir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

United International University

Summer-2025

EEE 3403
Microprocessor & Interfacing

Lecture-7
Analogue to Digital Conversion
(Part 1)
S. M. Lutful Kabir, PhD
Professor,
Dept. of EEE, UIU
Why Do We Need Analogue to
Digital Converter (ADC)?
• The need of converting analogue signals to digital data stems from the fact
that our computers/ controllers are digital ones.
• They just can’t handle the analogue signal and therefore, there should be a
device which converts the signal from analogue to digital domain (ADC).
• Most signals are analogue in nature and the electronic sensors which we’re
using for capturing these phenomena are also analogue.
• For example, the temperature sensor converts temperature in °C to an
analogue voltage that’s proportional to the value of temperature.
• So do the microphone, pressure sensor, light sensor and so on.
• Hence, we need a way to read analogue voltage and convert it to digital
values which we can program our computers/ controllers to manipulate it.
A Temperature Sensor, LM35
Analogue-To-Digital Converters
(ADC) Preface
• An ADC (Analog-To-Digital) converter is an electronic circuit that takes in an
analogue voltage as input and converts it into digital data, a value that
represents the voltage level in binary code.
• The ADC samples the analogue input whenever you trigger it to start
conversion.
• And it performs a process called quantization so as to decide on the voltage
level and its binary code that gets pushed in the output register.
• The ADC does the counter operation that of a DAC, while an ADC (A/D)
converts analogue voltage to digital data the DAC (D/A) converts digital
numbers to the analogue voltage on the output pin.
How does ADC work?
• The basic structure of an ADC consists of an S/H circuit.
• Followed by a quantizer which is actually the working horse for
the analogue to the digital conversion process.
• The type of ADC depends on how it’s performing the
quantization process, it can be analogue integration, digital
counter, successive approximation, or even direct conversion as
in Flash ADC types.
• Finally, the digital
output data is served
to the CPU or gets
directly stored in
memory.
Successive Approximation ADC
• The Successive Approximation ADC uses a comparator to
successively narrow a range that contains the analogue input voltage.
• At each successive step, the converter compares the input voltage to
the output of an internal DAC which might represent the midpoint of a
selected voltage range.
• At each step in this process, the approximation is stored in the
successive approximation register (SAR).
STM32 ADC Brief
• The STM32F103C8 (Blue Pill) has a 12-bit ADC which is a successive
approximation analogue-to-digital converter.
• It has up to 18 multiplexed channels allowing it to measure signals from
sixteen external and two internal sources.
• The result of the ADC is stored in a left-aligned or right-aligned 16-bit
data register.
• The ADC input clock is generated from the PCLK2 clock divided by a
Pre-scaler and it must not exceed 14 MHz.
ADC Features
• 12-bit resolution • External trigger option for both
• Interrupt generation at End of regular and injected conversion
Conversion, End of Injected conversion • Discontinuous mode
• Single and continuous conversion • Dual-mode (on devices with 2 ADCs
modes or more)
• Scan mode for automatic conversion of • ADC conversion time: 1 µs at 56
channel 0 to channel ‘n’ MHz (1.17 µs at 72 MHz)
• Self-calibration
• ADC supply requirement: 2.4 V to
• Data alignment with in-built data
3.6 V
coherency
• Channel by channel programmable • ADC input range: VREF– ≤ VIN ≤ VREF+
sampling time. • DMA request generation during
regular channel conversion.
Channels
External Channels:
The STM32F103C8T6 microcontroller has a total of 16 external ADC channels. The
Blue Pill board breaks out 10 of these channels to easily accessible pins:
PA0 to PA7 (8 channels)
PB0 and PB1 (2 channels)
The remaining 6 external channels (PC0 to PC5) are available on the microcontroller
but not wired to a pin header on the standard Blue Pill board.
Internal Channels:
The internal temperature sensor: This allows the microcontroller to monitor its own
die temperature.
The internal reference voltage (VREFINT​): This allows for ratiometric measurements
and can be used to improve ADC accuracy by compensating for fluctuations in the
power supply voltage.
So the total of 18 channels comes from the 16 external possibilities (10 on the board, 6
not) plus the 2 internal sensors.
Conversion Modes
The ADC offers various conversion modes to suit different application
needs:
Single-Channel, Single-Conversion:
•Measures a single channel once and then stops.
Single-Channel, Continuous-Conversion:
• Continuously measures a single channel.
Multi-Channel, Single-Conversion:
• Measures a sequence of multiple channels once.
Multi-Channel, Continuous-Conversion:
• Continuously measures a sequence of multiple channels.
Triggering
You can trigger an ADC conversion in several ways:
Software Trigger:
• A command in your code initiates the conversion.
Hardware Trigger:
• An external event, such as a timer or an external pin signal, can
automatically start a conversion.
STM32 ADC Read Methods
1 Polling
• In the polling method, we start an ADC conversion and stop the CPU at this
point to wait for the ADC conversion completion.
2 Interrupts
• We can trigger the ADC in order to start a conversion and the CPU
continues executing the main code routine. Upon the completion of the
conversion, the ADC fires an interrupt.
• Despite being an efficient way, the interrupt method can add so much
overhead to the CPU and cause very high CPU loading. Especially when
you’re doing so many conversions per second.
3 DMA
• The third method is using the DMA unit that can directly transfer the ADC
result from the peripheral to the memory without any CPU intervention.
ADC Resolution
• The number of levels of an ADC indicates the number of discrete values
it can produce over the range of analog values.
• The resolution Q depends on both the number of bits ”n” generated by
the quantizer and also the FSR (full-scale range) for the analog
reference voltage line.
• FSR indicates the range of voltage the ADC can convert.
• Here is the formula to calculate the resolution of quantization Q which is
basically a division for the FSR voltage by the number of levels 2n.
• Hence,
– Resolution = FRS/2n.
• For a 12-bit ADC and FSR=3.3V, Resolution =3.3V/212=0.8057mV
Setting the Reference Voltage, VREF
1. Internal VREF (Default Configuration)
• By default, the STM32F103C8T6 uses the internal reference voltage (VREF) of
3.0V or 3.3V (depending on your chip's supply voltage).
• To use the internal VREF, you don't need to configure anything specifically
unless you need to change settings related to the voltage reference.
16-bit ADC Register
Right or Left Align

0 1 1 1 0 0 1 1 1 0 0 1
Left Align
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

Right Align 0 1 1 1 0 0 1 1 1 0 0 1

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

15
An Example of Polling Method
• The objective of the first exercise is to control the brightness of an LED in
accordance with an input.
• The input is a voltage across a potentiometer.
• The output is a PWM signal to be applied across the LED.
• We have to build a system that initializes the ADC with an analogue input pin.
• And also configure a timer module to operate in PWM mode with output on the
pin (LED pin).
• Therefore, we can start an ADC conversion and map the result to the PWM
duty cycle and repeat the whole process over and over again.
• Open STM32CubeIDE.
• Choose The Target MCU & Save with a Project Name (maybe ADC_POLL)
• Configure The ADC1 Peripheral, Enable Channel7 & Set it to be triggered by
software. (as shown, these are default configurations).
• Other settings are for Data Alignment, Enable Regular Conversion, External
Trigger Conversion Source. Channel and Sampling time.
ADC Settings
Clock Setting
• Set the RCC external
clock source
• Go to the Clock
Configuration and set
the system slock to be
72MHz.
• The ADC peripherals
will be assigned a
default clock of
12MHz.
Displaying Floating Point Numbers

19
Vref=3.3;
Resolution=Vref/4096;
while (1)
{
// Start ADC Conversion
uint32_t AD_RES=0; HAL_ADC_Start(&hadc1);
char MSG[35]; // Poll ADC1 Peripheral & TimeOut = 1mSec
float X=0.0; HAL_ADC_PollForConversion(&hadc1, 7);
// Read The ADC Conversion Result
AD_RES = HAL_ADC_GetValue(&hadc1);
X = AD_RES*Resolution*100;
sprintf(MSG, "Temp = %5.2f\r\n", X);
HAL_UART_Transmit(&huart1, MSG, sizeof(MSG), 100);

ADC HAL_Delay(1000);
/* USER CODE END WHILE */

Polling /* USER CODE BEGIN 3 */


}
Proteus Diagram
[Link] 01/2
[Link] 0

Thanks

You might also like