Docsity

Microcontroller Technology: Analog-to-Digital Converter (ADC) Module in PIC16F877A, Lecture notes of Microcontrollers

Partial preview of the text

Download Microcontroller Technology: Analog-to-Digital Converter (ADC) Module in PIC16F877A and more Lecture notes Microcontrollers in PDF only on Docsity!

BEEZ 2404

Microcontroller Technology

Chapter 5: Analog Digital Converter

At the end of the class, you will be able:

To understand the concept Anolog and Digital

to setup the ADC module.

to understand the application of ADC.

ADC Module of PIC16F877A

ADC block diagram as shown below. AN0 – AN analog input pin Reference Voltage Scheme

ADC Module (How to use?)

In order to enable the A/D converter to run without problems as well as to avoid

unexpected results, it is necessary to consider the following:

◦ A/D converter does not differ between digital and analog signals. Pins should

be configured as analog inputs before the process of conversion starts.

◦ Bits used for this purpose are stored in the TRIS and ANSEL (ANSELH)

registers;

◦ When reading the port with analog inputs, the state of the corresponding bits

will be read as a logic zero (0)

Analog Digital Converter

The A/D module has four registers. These registers are: ◦ A/D Result High Register (ADRESH) ◦ A/D Result Low Register (ADRESL) ◦ A/D Control Register 0 (ADCON0) ◦ A/D Control Register 1 (ADCON1)

ADRESH/ADRESL Register

The result obtained after converting an analog value into digital is a10-bit number that is to be stored in the ADRESH and ADRESL registers. There are two ways of handling it: ◦ left and right justification which simplifies its use to a great extent. The format of conversion result depends on the ADFM bit of the ADCON1 register. ◦ In the event that the A/D converter is not used, these registers may be used as general-purpose registers.

ADCON0 Register

Analog Channel Select bits select a pin or an analog channel for A/D conversion, i.e. voltage measurement:

ADCON0 Register

ADON - A/D On bit enables A/D converter.

ADCON1 Register

 Bit 0 – Bit 3 (A/D Port Configuration Control bits) How to determine bit 0 to bit 3 logic?

ADCON1 Register

 Bit 6(A/D Conversion Clock Select bit (ADCON1 bits in shaded area and in bold ) ADCS2 bit work closely with ADCS1:ADCS0 bits (ADCON0) in order to select clock frequency used for internal synchronization of A/D converter

A/D Conversion Clock

The A/D conversion time per bit is defined as TAD. The A/D conversion requires a minimum 12TAD per 10-bit conversion. The source of the A/D conversion clock is software selected. The seven possible options for TAD are: ◦ 2 TOSC ◦ 4 TOSC ◦ 8 TOSC ◦ 16 TOSC ◦ 32 TOSC ◦ 64 TOSC ◦ Internal A/D module RC oscillator (2-6 us) For correct A/D conversions, the A/D conversion clock (TAD) must be selected to ensure a minimum TAD time of 1.6 us.

Analog Comparator

In addition to A/D converter, there is another module, which so called analog electronics. Two high quality comparators, along with additional electronics, are integrated into the microcontroller and connected to its pins. The comparator module contains two analog comparators. The inputs to the comparators are multiplexed with I/O port pins RA 0 through RA 3 , while the outputs are multiplexed to pins RA 4 and RA 5

Analog Comparator Register

The CMCON register controls the comparator input and output multiplexers. A

block diagram of the various comparator configurations is shown in datasheet

Comparator output bit Comparator output inversion bit Comparator input switch bit Comparator mode bits

Analog Comparator Configuration

Refer to PIC16F87XA datasheet, there are 8 possible ways to configure analog comparator module which is <CM2:CM0>: ◦ Comparators Reset <000> ◦ One Independent Comparator with Output<001> ◦ Two Independent Comparators<010> ◦ Two Independent Comparators with Outputs<011> ◦ Two Common Reference Comparators<100> ◦ Two Common Reference Comparators with Outputs<101> ◦ Four Inputs Multiplexed to Two Comparators<110> ◦ Comparators Off (POR Default Value)<111>