Sei sulla pagina 1di 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 to you how you collect data from register in time through
STML053R8T6 but to be used in Polling Mode. This entails the conversion complete interrupt or using DMA. Conversion group
discussion about the functions of HAL_ADC_START, can be configured to cycle through maximum of 16 channels and
HAL_ADC_PollForConversion, and HAL_ADC_GetValue. order of channels can be also programmed they dont have to
Index Terms STML053R8T6, STM32CubeMX,
be in order. Group can be programmed to convert continuously,
DigilentWaveforms, ADC, polling mode and discontinuously trigger by external trigger. In discontinuous
mode parts of group can be triggered to convert. For instance if
we select group to be 16 channels then we can program to
I. INTRODUCTION convert first 3 channels on trigger, then wait for another trigger
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
threshold values and DMA request based conversions. STM32
microcontrolles support two ADC conversion modes: regular
Figure 1. Inserted codes for declaration
and injected. Regular mode is what we used to see in many types
of microcontroller all channels share same data register.
Various regular modes can be possible, like single, continuos Fig. 1 shows the variables needed to be declared. Declaring
and group. More interesting here is group conversion where of variables is very important because these actions do not
channels are specified to convert where channels are specified
to convert in round robin mode cycle through channels. Its up
automatically be updated. It shows that the unsigned variable
used is adcValue while the float variable is analogValue.

Figure 2. encoded code located in user code begin 2


Figure 5. rectangular wave with 50% duty cycle
Fig. 2 shows the code HAL_ADC_Start(&hadc) that is
written on the second user code begin. This code enables the Fig. 5 shows the rectangular waveform of the second range.
analog-to-digital conversion to start the conversion of regular The recorded adcValue is 1416 and the analogValue is
group. 1.14109885.

Figure 3. codes for converting the gathered value into analog value Figure 6. rectangular wave with 75% duty cycle

Fig. 3 shows the codes which is found under the main() Fig. 6 shows the rectangular waveform of the third range.
function. HAL_ADC_PollForConversion(&hadc, 1) is the one The recorded adcValue is 3236 and the analogValue is
that checks if the continuous conversion of regular channel is 2.6077656744.
finished. The second line of the code means that the adcValue is
what the HAL_ADC_GetValue will receive from hadc. The last Based from Figures 4 until 6, 25% duty cycle is showed
line of codes is the final value of the analogValue wherein it is because the pulse is smaller compared to the pulse on the third
multiplied to 3.3 and divided by 4095. waveform.
The code was then downloaded. Another way in View is the
IV. CONCLUSION
Live Watch. The adcValue and analogValue. A potentiometer
and a 1k resistor was connected. The potentiometer is across Interrupt Mode is very useful in immediate functions.
the source, PA0 and ground. The connection forms a voltage Therefore, the code entered on the interrupt must be as brief as
divider circuit where PA0 is in between. possible so that there will be no delay upon execution. The
interrupt used must be enabled in NVIC configuration because
III. RECTANGULAR WAVE WITH THREE DIFFERENT it enables programmable priority levels and it is easy to use by
DUTY CYCLES BASED ON ANALOG VALUE the programmers. NVIC supports vectored interrupt operations
Table 1. Ranges of analogValue with its duty cycle so that there is no need to use another software to determine
which interrupt to serve.
AnalogValue range Duty Cycle
V. ACKNOWLEDGMENT
0 < 1.1 25%
1.1 < 2.2 50% The student would like to thank the Almighty Father for the
2.2 < 3.3 75% guidance, wisdom, and knowledge He granted all throughout the
Three set of analog value range with its duty cycle. With the duration of the creation of this paper. She also would like to give
help of the Live Watch, the analog value can be identified. acknowledgement to their instructor, Engr. Mark Anthony
Cabilo, for sharing his knowledge on the project and guiding to
have a successful and correct performance.

REFERENCES
[1] SysProgs, "SysProgs," www.visualgdb.com, 22 July
2015. [Online]. Available:
http://visualgdb.com/tutorials/arm/stm32/adc/.
[2] L. T. Phuc, "letanphuc," www.letanphuc.net, 24 July
2016. [Online]. Available:
Figure 4. Rectangular Wave with 25% duty cycle
http://letanphuc.net/2016/07/stm32f0-adc/.
Fig. 4 shows the rectangular waveform of the first range. The [3] ST, "STMicroelectronics," st.com, [Online]. Available:
recorded adcValue is 1266 and the analogValue is http://www.st.com/content/ccc/resource/technical/document/
1.0202198022. application_note/group0/3f/4c/a4/82/bd/63/4e/92/CD002113
14/files/CD00211314.pdf/jcr:content/translations/en.CD002
11314.pdf.

Potrebbero piacerti anche