You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>STM32W108C8</strong><br />
Analog-to-digital converter<br />
11.1.4 Offset/gain correction<br />
11.1.5 DMA<br />
When a conversion is complete, the 16-bit converted data is processed by offset/gain<br />
correction logic:<br />
● The basic ADC conversion result is added to the 16-bit signed (two’s complement)<br />
value of the ADC offset register (ADC_OFFSET).<br />
● The offset-corrected data is multiplied by the 16-bit ADC gain register, ADC_GAIN, to<br />
produce a 16-bit signed result. If the product is greater than 0x7FFF (32767), or less<br />
than 0x8000 (-32768), it is limited to that value and the INT_ADCSAT bit is set in the<br />
INT_ADCFLAG register.<br />
ADC_GAIN is an unsigned scaled 16-bit value: ADC_GAIN[15] is the integer part of the gain<br />
factor and ADC_GAIN[14:0] is the fractional part. As a result, ADC_GAIN values can<br />
represent gain factors from 0 through (2 – 2 -15 ).<br />
Reset initializes the offset to zero (ADC_OFFSET = 0) and gain factor to one (ADC_GAIN =<br />
0x8000).<br />
The ADC DMA channel writes converted data, which incorporates the offset/gain correction,<br />
into a DMA buffer in RAM.<br />
The ADC DMA buffer is defined by two registers:<br />
● ADC_DMABEG is the start address of the buffer and must be even.<br />
● ADC_DMASIZE specifies the size of the buffer in 16-bit samples, or half its length in<br />
bytes.<br />
To prepare the DMA channel for operation, reset it by writing the ADC_DMARST bit in the<br />
ADC_DMACFG register, then start the DMA in either linear or auto wrap mode by setting<br />
the ADC_DMALOAD bit in the ADC_DMACFG register. The ADC_DMAAUTOWRAP bit in<br />
the ADC_DMACFG register selects the DMA mode: 0 for linear mode, 1 for auto wrap mode.<br />
● In linear mode the DMA writes to the buffer until the number of samples given by<br />
ADC_DMASIZE has been output. Then the DMA stops and sets the<br />
INT_ADCULDFULL bit in the INT_ADCFLAG register. If another ADC conversion<br />
completes before the DMA is reset or the ADC is disabled, the INT_ADCOVF bit in the<br />
INT_ADCFLAG register is set.<br />
● In auto wrap mode the DMA writes to the buffer until it reaches the end, then resets its<br />
pointer to the start of the buffer and continues writing samples. The DMA transfers<br />
continue until the ADC is disabled or the DMA is reset.<br />
When the DMA fills the lower and upper halves of the buffer, it sets the INT_ADCULDHALF<br />
and INT_ADCULDFULL bits, respectively, in the INT_ADCFLAG register. The current<br />
location to which the DMA is writing can also be determined by reading the ADC_DMACUR<br />
register.<br />
Doc ID 018587 Rev 2 162/215