0% found this document useful (0 votes)
14 views

Experiment 6

The document outlines Experiment 6 for the Microprocessor and Interfacing Laboratory at United International University, focusing on Analog to Digital Converters (ADCs) and their applications. It explains the working principle of ADCs, specifically the Successive Approximation ADC, and provides details on the STM32F103C8 ADC features and configurations for controlling LED brightness using PWM signals. Additionally, it includes laboratory tasks involving ADC with polling and interrupt methods, along with circuit diagrams and output results.

Uploaded by

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

Experiment 6

The document outlines Experiment 6 for the Microprocessor and Interfacing Laboratory at United International University, focusing on Analog to Digital Converters (ADCs) and their applications. It explains the working principle of ADCs, specifically the Successive Approximation ADC, and provides details on the STM32F103C8 ADC features and configurations for controlling LED brightness using PWM signals. Additionally, it includes laboratory tasks involving ADC with polling and interrupt methods, along with circuit diagrams and output results.

Uploaded by

zahmed212008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

United International University (UIU)

Course Code: EEE 3404


Course Title: Microprocessor and Interfacing Laboratory
Experiment 6: ADC

Pre-Lab Reading
Consider a situation where you want to know the room temperature. There is a device on your
desk that is telling you that the temperature is 30o C today.
But how the device tells you the information! Simply put - There is a sensor (temperature sensor)
that senses the temperature and gives out to the screen. This sensor reads/senses the room
temperature and gives out an analog voltage (continuous in time, think of a sinusoid for example)
proportional to the room temperature, which is then further processed and is displayed. The
processing is done by some micro-controller. In fact, all sensors (Ex: micro-phone, pressure, light
etc.) output proportional analog voltage. Most signals are analog in nature and the electronic
sensors which we’re using for capturing these phenomena are also analog. All micro-controllers
(and processors) work with digital data. So, who is translating the equivalent digital data from
the available sensor analog data? – A separate module named “Analog to Digital Converter”
in-short ADC or, A/D converter.

What is an ADC?
An ADC (Analog-To-Digital) converter is an electronic circuit that takes in an analog voltage as
input and converts it into digital data, a value that represents the voltage level in binary code.

1011

Fig. 1 Analog to Digital Converter (ADC)


An ADC block samples the analog input whenever you trigger it to start conversion and performs
quantization so as to decide on the voltage level and the binary code gets pushed in the output
register. While an ADC (A/D) converts analog voltage to digital data the DAC (D/A) converts
digital voltage to the analog voltage on the output.
How does an ADC work?
Analog data is sampled by a ‘sample and hold’ circuit and then quantized by a ‘quantizer’ to a
digital data.
+5

Δ=10V/8=1.25

-5
Fig.2 Sampling and Quantization
Blue spikes show the sampled value while the corresponding 3-bit binary value is shown towards
the right in Figure -2. The whole analog signal is quantized in 8 levels which can be represented
by 3-bits in binary. Say, at t4, the 10V p-p sinusoid is at 2V (the green dot). This sample value is
at level 5 which gives out 101 in binary. The whole analog voltage range (also known as Full
Scale Range or, FSR) is divided into 8 levels. Each division is 1.25V. This is the resolution of the
ADC. The samples at t2, t3, t6, t7 are snapped to a defined level. If the binary values of these
samples are fed into a DAC, the result might be slightly different than the actual analog voltage.
Say, the real analog value at t2 is 3.5V, after sampling, the new snapped value is below 3.5V and
the quantized binary value is 110. Now, if this binary value was converted back to analog, the
result might be 3V. So, there is an error (quantization error) percentage at the output. This can be
reduced by increasing the number of levels (level = 2bit) which means a decrease in resolution.
So, Resolution = FSR/2n. For a 12-bit ADC and FSR=3.3V, Resolution =3.3V/212=0.8057 mV.

What are the types of ADC?


The popular types of ADC are shown below.

Fig. 3 Types of ADC


Working Principle of Successive Aprroximation ADC (Blue Pill uses this type)
A Successive Approximation ADC converts an analog signal into a digital signal using a binary
search algorithm. The conversion process is given below.
1.​ The input analog signal is sampled and held by a sample-and-hold circuit.
2.​ The most significant bit (MSB) of the digital output is set to 1, and all other bits are set to
0.
3.​ The digital value is converted back to an analog signal by a digital-to-analog converter
(DAC).
4.​ The output of the DAC is compared to the input analog signal by a comparator.
5.​ If the output of the DAC is greater than the input analog signal, the MSB is left at 1.
Otherwise, the MSB is set to 0.
6.​ The next bit is then set to 1, and the process is repeated until all bits have been determined.

Fig. 4 Successive Aprroximation ADC


The process of setting each bit to 1 and then comparing the output of the DAC to the input analog
signal is called successive approximation.

STM32F103C8 (Blue Pill) ADC at a glance


•​ 12 – bit resolution with 18 multiplexed channels allowing it to measure signals from
sixteen external and two internal sources.
•​ 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.
•​ Interrupt generation at End of Conversion, End of Injected conversion.
•​ Scan mode for automatic conversion of channel 0 to channel ‘n’.
•​ Self-calibration.
•​ Single, continuous, discontinuous and scan (for automatic) modes for conversion.
•​ Dual mode conversion (on devices with 2 ADCs or more).
•​ External trigger option.
•​ ADC conversion time: 1 µs at 56 MHz & 1.17 µs at 72 MHz.
•​ ADC supply requirement: 2.4 V to 3.6 V
•​ ADC input range: VREF– ≤ VIN ≤ VREF+
•​ DMA request generation during regular channel conversion.

STM32 ADC Read methods

Fig. 5 ADC read methods in STM32

Important functions related to ADC conversion and use sequence in STM32


Laboratory Tasks
Problem statement - Control the brightness of an LED in accordance with an input.
Solution - The input is a voltage across a potentiometer. The output is a PWM signal (duty cycle
controlling) to be applied across the LED. We have to build a system which reads the analog
input from the POT through ADC and configure a timer to generate PWM signals at the output
(LED pin) continuously.
Task - 1: ADC with Polling method
Configuration for ADC: Pinout & Configuration>Analog>ADC1
Enable Channel7 (IN7) & Set it to be triggered by software. (as shown, these are default
configurations). ‘PA7’ will be configured as ADC input.
Check the settings for Data Alignment, Enable Regular Conversion, External Trigger Conversion
Source, Channel and Sampling time.

Fig. 6 Configuration in CubeMX for ADC 1


Configuration for Timer 2: Pinout & Configuration>Timers>TIM2
Check the settings for Clock Source, Channel, Counter settings, auto-reload preload and mode
and PWM generation.
Fig. 7 Configuration in CubeMX for Timer 2
Configuration for Serial Communication: Pinout & Configuration>Connectivity>USART1

Fig. 8 Configuration in CubeMX for UART


Configuration for Clock: Clock Configuration
Pinout & Configuration: Check the RCC external clock source.
Clock Configuration: Check the system clock (72MHz), ADC pre-scaler (/6).
Fig. 9 RCC from System Core

Fig. 10 Clock configuration


Now generate code by saving the configuration.
Code snippets ( Read comments for better understanding )
Add the following at the beginning:
Add the following before ‘while loop’:

Add inside while loop:

Circuit Diagram
Fig. 12 Circuit diagram in Proteus
Outputs

Fig. 13 Output from oscilloscope


At TIME/DIV = 0.1m, VOLTS/DIV=2V.
For a duty-cycle of 75% (POT value): 1 cycle = 9.1 units ; ON-Time = 6.8 units
Duty-cycle from figure = 6.8/9.1 =74.7%
Fig. 14 Output from terminal shows transmission of MSG via UART1
Task – 2: ADC with interrupt method
Configuration for ADC:
Perform the configuration steps done in Task – 1. Additionally, enable global interrupt from
ADC1>NVIC Settings for this task.

Fig. 15 Configuration in CubeMX for ADC1 in Interrupt mode


Now generate code by saving the configuration.
Code snippets ( Read comments for better understanding )
Add the following at the beginning:

Add the following before ‘while loop’:


Add inside while loop:

Add callback function after main() function:

Circuit diagram & Outputs


Similar to Task – 1, Figure – 11, 12, 13, 14.

You might also like