Sunteți pe pagina 1din 6

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 exceed preset threshold values and DMA request based
STML053R8T6 but to be used in Polling Mode. This entails the conversions. STM32 microcontrolles support two ADC
discussion about the functions of HAL_ADC_START,
HAL_ADC_PollForConversion, and HAL_ADC_GetValue. The conversion modes: regular and injected. Regular mode is what
last part of this paper involves the usage of potentiometer, and a we used to see in many types of microcontroller all channels
resistor to vary the analog voltage externally. The duty cycle can share same data register. Various regular modes can be
be compared through the simulations and through the help of
Analog Discovery. possible, like single, continuos and group. More interesting
here is group conversion where channels are specified to
Index Terms STML053R8T6, STM32CubeMX, convert where channels are specified to convert in round robin
DigilentWaveforms, ADC, polling mode, analog discovery, duty
cycle mode cycle through channels. Its up to you how you collect
data from register in time through conversion complete
I. INTRODUCTION
interrupt or using DMA. Conversion group can be configured
Analog-to-Digital Converter (ADC) is a peripheral that to cycle through maximum of 16 channels and order of
allows measuring the voltage (between 0 and Vref) on a certain channels can be also programmed they dont have to be in
input of the microcontroller and converting it into a number in order. Group can be programmed to convert continuously, and
between 0 and 2^N 1 where N is the ADC resolution. The discontinuously trigger by external trigger. In discontinuous
easiest way to experiment with an ADC is to connect it to a mode parts of group can be triggered to convert. For instance if
potentiometer which is a mechanically adjustable resistor. we select group to be 16 channels then we can program to
Connecting one side of the terminals of the potentiometer to convert first 3 channels on trigger, then wait for another trigger
the ground while the other one on the V cc pin, the voltage level and convert next three channels and so on. Another is the inject
will gradually change as the potentiometer knob is rotated. conversion mode. It can perform conversion of selected four
ADC resolution is one of the key factors to determine how channels. They have a priority over normal conversion group
precise the conversion can be. Faster conversion times can be scan. If normal group conversion is going on and injected
obtained by lowering the resolution. Its reference voltage is conversion is triggered, then normal conversion is halted, then
equal to supply voltage to Vdd pin. It may use successive injected conversion is performed. After that, normal conversion
approximation register principle wherein the conversion is is resumed. Injected conversion channels have their own result
performed in several steps. The number of conversion steps is registers and offset registers. Offset can store value that will be
equal to the number of bits in the ADC converter. Each step is automatically deducted from ADC result.
driven by the ADC clock. Each ADC clock produces one bit
from result to output. ADC internal design is a switched- II. GENERATING THE CODE

capacitor type. The configuration tab contains the analog group wherein the
ADC module has a separate supply which normally can be ADC is found. This is where the proper modes and other
connected to general MCU power supply. Also, it can have features will be set. After that, generating the codes would be
external reference source through Vref+ and Vref- that can be the next step.
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
III. RECTANGULAR WAVE WITH THREE DIFFERENT
DUTY CYCLES BASED ON ANALOG VALUE
Table 1. Ranges of analogValue with its duty cycle

AnalogValue range Duty Cycle


25%
0 analogValue<1.1
50%
1.1 analogValue< 2.2

Figure 1. Inserted codes for declaration 75%


2.2 analogValue< 3.3
Fig. 1 shows the variables needed to be declared. Declaring
of variables is very important because these actions do not Three set of analog value range with its duty cycle. With
automatically be updated. It shows that the unsigned variable the help of the Live Watch, the analog value can be identified.
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 4. Rectangular Wave with 25% duty cycle
analog-to-digital conversion to start the conversion of regular
group. 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.

Figure 3. codes for converting the gathered value into analog value

Fig. 3 shows the codes which is found under the main() Figure 5. analog voltage reading for 25% duty cycle
function. HAL_ADC_PollForConversion(&hadc, 1) is the one
that checks if the continuous conversion of regular channel is The recorded adcValue is 1266 and the analogValue is
finished. The second line of the code means that the adcValue 1.0202198022.
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.
Figure 6. rectangular wave with 50% duty cycle
Fig. 6 shows the rectangular waveform of the second range. it enables programmable priority levels and it is easy to use by
The duty cycle is likely the same with the off state. the programmers. NVIC supports vectored interrupt operations
so that there is no need to use another software to determine
which interrupt to serve.

Figure 7. analog voltage reading for 50% duty cycle

Fig. 7 shows the recorded adcValue is 1416 and the


analogValue is 1.14109885.

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 9. analog voltage reading for 75% duty cycle

Fig. 9 shows the recorded adcValue is 3236 and the


analogValue is 2.6077656744.

Based from Figures 4,6 and 8, 25% duty cycle is showed


because the pulse is smaller compared to the pulse on the third
waveform.
IV. CONCLUSION
Interrupt Mode is very useful in immediate functions.
Therefore, the code entered on the interrupt must be as brief as
possible so that there will be no delay upon execution. The
interrupt used must be enabled in NVIC configuration because
V.ACKNOWLEDGMENT or
The student would like to thank the Almighty Father for the ial
s/
guidance, wisdom, and knowledge He granted all throughout
ar
the duration of the creation of this paper. Also to her family and m/
friends for they helped in such a way that the student was st
motivated in giving 100% for this paper. m
32
/a
REFERENCES dc
/.
[1
[2
]
]
Sy
L.
sP
T.
ro
Ph
gs
uc
,
,
"S
"l
ys
et
Pr
an
og
ph
s,"
uc
w
,"
w
w
w.
w
vi
w.
su
let
al
an
gd
ph
b.
uc
co
.n
m,
et,
22
24
Ju
Ju
ly
ly
20
20
15
16
.
.
[O
[O
nli
nli
ne
ne
].
].
A
A
va
va
ila
ila
bl
bl
e:
e:
htt
htt
p:/
p:/
/vi
/le
su
ta
al
np
gd
hu
b.
c.
co
ne
m/
t/2
tut
01 l/d
6/ oc
07 u
/st m
m en
32 t/a
f0 pp
- lic
ad ati
c/. on
[3 _n
] ot
S e/
T, gr
"S ou
T p0
M /3
icr f/
oe 4c
le /a
ctr 4/
on 82
ic /b
s," d/
st. 63
co /4
m, e/
[O 92
nli /C
ne D
]. 00
A 21
va 13
ila 14
bl /fi
e: le
htt s/
p:/ C
/w D
w 00
w. 21
st. 13
co 14
m/ .p
co df
nt /jc
en r:c
t/c on
cc te
/re nt/
so tra
ur ns
ce lat
/te io
ch ns
ni /e
ca n.
C 14
D .p
00 df.
21
13

S-ar putea să vă placă și