Activity 6.2.8. “Homework”, to help you get a head start on the lab.
(a)
Move the pot to A3. Rewire the wiper to the header pin labeled
A3 and make the program work again. You will need to find out which port pin A3 is, which the Nucleo pinout gives, and then which ADC channel that port pin reaches, which is datasheet Table 12 again. Do not assume any of the three numbers match. Work each translation out from the pinout and the datasheet, and keep a record of the chain you followed.
Everything that mentions the old pin has to change with it. Check each line of
pa0_adc_init() in turn and ask whether it still names the right thing.
(b)
Change the resolution. Set your pot so the DMM reads as close to 1.000 V as you can manage, and record the count the ADC returns. Then find the
RES field in ADC_CFGR1 in the reference manual and switch the converter to 10-bit. Read the field’s access rules while you are there: RM0490 §14.12.4 allows software to program ADC_CFGR1 only while ADEN is cleared, so where you put this line matters as much as what it says. Predict the new count before you run it, then check. Explain the factor you see.
(c)
Check the arithmetic both ways. Pick any three knob positions. For each, measure the wiper with the DMM, record the count your program reports, and compute the voltage from the count. How closely do the measured and computed voltages agree, and is the difference within the one-LSB rounding you would expect?
