Skip to main content

Section 6.2 Day 7 In-Class: Reading a Potentiometer

Today we’ll read a potentiometer with the ADC. We’ll start by working out what an ADC’s count means, then use the STM32C031C6 datasheet to find which pins can be analog inputs and which channel each one reaches. We’ll then wire a potentiometer to one of those pins and configure the ADC register by register, so that the count printed on your terminal changes as you turn the knob. Along the way we’ll look closely at ADC_ISR, the ADC’s status register, and at how a flag in it is cleared, which does not work the way clearing a bit has worked so far. At the end we’ll run a successive approximation by hand.