Electrical – right or left alignment of data in ADC


I am using a STM32F407 discovery board for ADC and I found that the DR or the data register of the ADC can be configured in left or right alignment. What does this mean? Also, what are the advantage/disadvantages of each alignment?

Best Answer

Alignment determines how the binary will end up in the hardware register. Suppose you have a 16 bit resolution register (or 2x8 bits) but only 12 bit ADC resolution. Your option is then either to get:




Where "D" is your data bits and "X" is "don't care" bits (usually filled with zeroes). The form requiring the least amount of bitwise arithmetic to get to your desired format is usual the preferred one. One will contain the need to shift, the other won't.

This in turn depends on endianess - the byte order. If the ADC is using the same endianess as your CPU then you'd pick the one matching best. In case of STM32 little endian that probably means the 2nd of the two forms. Built-in ADCs in microcontrollers typically have the same endianess as the CPU. In case of external ones, it could have either big or little endian.

Related Topic