Вы находитесь на странице: 1из 3

ADC (Polling Mode)

Lea Dominique Fariola


Department of Electrical and Electronics Engineering
University of San Carlos
Talamban, Cebu City Philippines
leadominiquefariola@gmail.com

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

Fig. 2 shows the code HAL_ADC_Start(&hadc) that is


written on the second user code begin. This code enables the Figure 5. analog voltage reading for 25% duty cycle
analog-to-digital conversion to start the conversion of regular
group. The recorded adcValue is 1266 and the analogValue is
1.0202198022.

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.

Figure 8. rectangular wave with 75% duty cycle

Fig. 8 shows the rectangular waveform of the third range.


The duty cycle is greater than its off state.

Figure 4. Rectangular Wave with 25% duty cycle

Fig. 4 shows the rectangular waveform of the first range. The


pulse width of the waveform is small and the off state is longer
than the on state.
V. ACKNOWLEDGMENT
The student would like to thank the Almighty Father for the
guidance, wisdom, and knowledge He granted all throughout the
duration of the creation of this paper. Also to her family and
friends for they helped in such a way that the student was
motivated in giving 100% for this paper.

Figure 9. analog voltage reading for 75% duty cycle REFERENCES


[1] SysProgs, "SysProgs," www.visualgdb.com, 22 July
Fig. 9 shows the recorded adcValue is 3236 and the
2015. [Online]. Available:
analogValue is 2.6077656744.
http://visualgdb.com/tutorials/arm/stm32/adc/.
Based from Figures 4,6 and 8, 25% duty cycle is showed [2] L. T. Phuc, "letanphuc," www.letanphuc.net, 24 July
because the pulse is smaller compared to the pulse on the third 2016. [Online]. Available:
waveform. http://letanphuc.net/2016/07/stm32f0-adc/.
[3] ST, "STMicroelectronics," st.com, [Online]. Available:
IV. CONCLUSION http://www.st.com/content/ccc/resource/technical/document/
Interrupt Mode is very useful in immediate functions. application_note/group0/3f/4c/a4/82/bd/63/4e/92/CD002113
Therefore, the code entered on the interrupt must be as brief as 14/files/CD00211314.pdf/jcr:content/translations/en.CD002
possible so that there will be no delay upon execution. The 11314.pdf.
interrupt used must be enabled in NVIC configuration because
it enables programmable priority levels and it is easy to use by
the programmers. NVIC supports vectored interrupt operations
so that there is no need to use another software to determine
which interrupt to serve.

Вам также может понравиться