Aventuras y Desventuras de un hobbyist

Aventuras y Desventuras de un hobbyist....

Reading 12 ADC channels on the Atmega32u4

The Atmega32u4 has 12 Analog inputs, for single ended input mode and according to its datasheet we can call the different channels changing the values on the ADMUX registers(MUX4:0) although it uses 5 bits to select the channels only 3 are really used (MUX2:0) which will allow us to go from 0-7.
According to the DataSheet we end up with 6 channels:
Also note that MUX5 should be cleared in order to use ADC0:7
000 ADC0
001 ADC1
010 N/a
011 N/a
100 ADC4
101 ADC5
110 ADC6
111 ADC7

In order to read the other 6 channels ADC8:13 we must set MUX5 and the assigments for MUX2..0 are:
000 ADC8
001 ADC9
010 ADC10
0011 ADC11
100 ADC12
101 ADC13
110 N/a
111 Temperature sensor N/a

It´s very important to note that MUX5 is not part of ADMUX as in other 8 bit AVRs but is part of  ADCSRB.
Lets start with the code: This function will initialize the ADC
The following function will get the ADC channel we want to read as parameter:
Finally for readability(vinciduino form factor) and portability I added the following defines



Then if we want to read any value we may use:

0 comentarios:

Publicar un comentario