This web site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more.

ADCON register

Last update: 31/07/2015

The programming of a microcontroller requires the reading of its datasheet, it is a real 'must'. In this article we'll pay a look (as easiest as possible) to the registers connected to the ADC converters present in many picmicros and to the registers managing such a devices.

Using one of the most popular 8 bit picmicros like 16f87x or 16f88x, for instance, reading the datasheet, we'll find that the ADC modules (10 bit) are controlled by four different registers. The first two, ADCON0 and ADCON1, are used to set and start the ADC module, while the others are used to store result of the conversions. When an high level language is used, the programmer doesn't need to care a lot of the register connected to the results because they are normally stored in a variable by a routine of the language itself (adc_read, for instance, using mikroc).

The ADCON0 and ADCON1 registers, instead, must be properly set to obtain the necessary conversion.

As we can see this registers are 8 bit registers where:

- bit6 and bit 7 are used to set the frequency of the conversions;

- bits 3, 4 and 5 are used to select the pins of the microcontroller enabled to theadc conversions;

- bit 2 represents the status of the conversion procedure;

- bit 0 starts the conversion.


Luckily, using high level languages all the activities regarding the start and the status of the analog conversion are automatically managed by the routines of the language itself.

The situation should be clear: if for instance, we have to enable the pin AN0 to act as adc input with a conversion clock of F/32 we have simply to set ADCON0 = 0b10000000 (bin) or 0x80 (hex) or 128 (dec).

Regarding the second register, ADCON1, it must be set for two reasons: to select the format of the result value (bit 7), to select (bit0...bit3) the reference voltage and to set the port configuration control bits according to the following table (from the 16F87x datasheet):

registro ADCON

Therefore setting at '1' the bit7 of the register, the result value will be right justified, a '0' value will left justify the result.

The settings regarding the bit0..bit3 can be chosen accordingly to the table on the left: should be clear that if we put such bits at '0000' the Vref will be set to the vdd of the microcontroller and all pins will be set as analog input.

For instance:

ADCON1 = 0x80 (0b10000000) will right justify the result, will set the reference voltage to Vref and will set inputs to 'all analog'

The result value of the conversion will be stored in a double register: ADRESH and ADRESL (or will be returned to a variable if high-level languages are used) with the result right or left justified according to the register adcon1:bit7.

TRISA = 0xFF (or 0b11111111) will complete the set up of the port setting the port as input. 

Diritti riservati 2008-2015. Tutti i marchi riportati sono detenuti dai legittimi proprietari. Tutto il materiale e` liberamente utilizzabile ma non per scopi commerciali. Non si assume alcuna responsabilita` sul materiale pubblicato per eventuali danni diretti o indiretti che possano derivare dall`utilizzo di schemi, progetti o altro materiale presente nel sito. Inviare una mail a: (contenuti) (webserver) per domande e/o suggerimenti.