Professional Documents
Culture Documents
Abstract The paper details the activities done in using and group. More interesting here is group conversion where
STML053R8T6 but to be used in Polling Mode. This entails the channels are specified to convert where channels are specified
discussion about the functions of HAL_ADC_START, to convert in round robin mode cycle through channels. Its up
HAL_ADC_PollForConversion, and HAL_ADC_GetValue. The to you how you collect data from register in time through
last part of this paper involves the usage of potentiometer, and a
conversion complete interrupt or using DMA. Conversion group
resistor to vary the analog voltage externally. The duty cycle can
be compared through the simulations and through the help of can be configured to cycle through maximum of 16 channels and
Analog Discovery. order of channels can be also programmed they dont have to
be in order. Group can be programmed to convert continuously,
Index Terms STML053R8T6, STM32CubeMX, and discontinuously trigger by external trigger. In discontinuous
DigilentWaveforms, ADC, polling mode, analog discovery, duty mode parts of group can be triggered to convert. For instance if
cycle we select group to be 16 channels then we can program to
convert first 3 channels on trigger, then wait for another trigger
I. INTRODUCTION
and convert next three channels and so on. Another is the inject
Analog-to-Digital Converter (ADC) is a peripheral that conversion mode. It can perform conversion of selected four
allows measuring the voltage (between 0 and Vref) on a certain channels. They have a priority over normal conversion group
input of the microcontroller and converting it into a number in scan. If normal group conversion is going on and injected
between 0 and 2^N 1 where N is the ADC resolution. The conversion is triggered, then normal conversion is halted, then
easiest way to experiment with an ADC is to connect it to a injected conversion is performed. After that, normal conversion
potentiometer which is a mechanically adjustable resistor. is resumed. Injected conversion channels have their own result
Connecting one side of the terminals of the potentiometer to the registers and offset registers. Offset can store value that will be
ground while the other one on the Vcc pin, the voltage level will automatically deducted from ADC result.
gradually change as the potentiometer knob is rotated.
ADC resolution is one of the key factors to determine how II. GENERATING THE CODE
precise the conversion can be. Faster conversion times can be The configuration tab contains the analog group wherein the
obtained by lowering the resolution. Its reference voltage is ADC is found. This is where the proper modes and other features
equal to supply voltage to Vdd pin. It may use successive will be set. After that, generating the codes would be the next
approximation register principle wherein the conversion is step.
performed in several steps. The number of conversion steps is
equal to the number of bits in the ADC converter. Each step is
driven by the ADC clock. Each ADC clock produces one bit
from result to output. ADC internal design is a switched-
capacitor type.
ADC module has a separate supply which normally can be
connected to general MCU power supply. Also, it can have
external reference source through Vref+ and Vref- that can be
brought through dedicated pins. In no special case analog supply
voltage may be reference internally. It can also be performed in
single or continuous mode for single channel, scan through all
channels, externally triggered conversion. There is also an
analog watchdog which can detect if voltage exceed preset Figure 1. Inserted codes for declaration
threshold values and DMA request based conversions. STM32
microcontrolles support two ADC conversion modes: regular Fig. 1 shows the variables needed to be declared. Declaring
and injected. Regular mode is what we used to see in many types of variables is very important because these actions do not
of microcontroller all channels share same data register. automatically be updated. It shows that the unsigned variable
Various regular modes can be possible, like single, continuos used is adcValue while the float variable is analogValue.
Figure 2. encoded code located in user code begin 2
Figure 3. codes for converting the gathered value into analog value
Figure 6. rectangular wave with 50% duty cycle
Fig. 3 shows the codes which is found under the main()
function. HAL_ADC_PollForConversion(&hadc, 1) is the one Fig. 6 shows the rectangular waveform of the second range.
that checks if the continuous conversion of regular channel is The duty cycle is likely the same with the off state.
finished. The second line of the code means that the adcValue is
what the HAL_ADC_GetValue will receive from hadc. The last
line of codes is the final value of the analogValue wherein it is
multiplied to 3.3 and divided by 4095.
The code was then downloaded. Another way in View is the
Live Watch. The adcValue and analogValue. A potentiometer
and a 1k resistor was connected. The potentiometer is across
the source, PA0 and ground. The connection forms a voltage
divider circuit where PA0 is in between.
III. RECTANGULAR WAVE WITH THREE DIFFERENT
DUTY CYCLES BASED ON ANALOG VALUE Figure 7. analog voltage reading for 50% duty cycle
Table 1. Ranges of analogValue with its duty cycle
Fig. 7 shows the recorded adcValue is 1416 and the
AnalogValue range Duty Cycle analogValue is 1.14109885.
0 < 1.1 25%
1.1 < 2.2 50%
2.2 < 3.3 75%
Three set of analog value range with its duty cycle. With the
help of the Live Watch, the analog value can be identified.