Microchip Technology PIC32 Family Reference Manual
Microchip Technology PIC32 Family Reference Manual

Microchip Technology PIC32 Family Reference Manual

10-bit analog-to-digital converter (adc)
Hide thumbs Also See for PIC32 Family:

Advertisement

Section 17. 10-bit Analog-to-Digital Converter (ADC)
HIGHLIGHTS
This section of the manual contains the following major topics:
17.1
17.2
17.3
17.4
17.5
17.6
17.7
17.8
17.9
17.10
17.11
© 2007-2011 Microchip Technology Inc.
Introduction.............................................................................................................. 17-2
Control Registers ..................................................................................................... 17-4
ADC Operation, Terminology and Conversion Sequence ..................................... 17-12
ADC Module Configuration .................................................................................... 17-14
Miscellaneous ADC Functions............................................................................... 17-26
Initialization............................................................................................................ 17-51
Interrupts................................................................................................................ 17-53
Operation During Sleep and Idle Modes ............................................................... 17-54
Effects of Various Resets....................................................................................... 17-55
Related Application Notes ..................................................................................... 17-56
Revision History..................................................................................................... 17-57
17
DS61104E-page 17-1

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the PIC32 Family and is the answer not in the manual?

Questions and answers

Summary of Contents for Microchip Technology PIC32 Family

  • Page 1: Table Of Contents

    Miscellaneous ADC Functions................17-26 17.6 Initialization......................17-51 17.7 Interrupts........................ 17-53 17.8 Operation During Sleep and Idle Modes ............... 17-54 17.9 Effects of Various Resets..................17-55 17.10 Related Application Notes ..................17-56 17.11 Revision History..................... 17-57 © 2007-2011 Microchip Technology Inc. DS61104E-page 17-1...
  • Page 2: Introduction

    PIC32 Family Reference Manual Note: This family reference manual section is meant to serve as a complement to device data sheets. Depending on the device variant, this manual section may not apply to all PIC32 devices. Please consult the note at the beginning of the “10-bit Analog-to-Digital Converter (ADC)”...
  • Page 3 ADC1BUF2 REFH REFL Channel Scan CH0SB<3:0> SAR ADC CH0SA<3:0> CSCNA ADC1BUFE REFL ADC1BUFF CH0NA CH0NB Alternate Input Selection Note 1: V + and V - inputs can be multiplexed with other analog inputs. © 2007-2011 Microchip Technology Inc. DS61104E-page 17-3...
  • Page 4: Control Registers

    PIC32 Family Reference Manual 17.2 CONTROL REGISTERS The ADC module has the following Special Function Registers (SFRs): • AD1CON1: ADC Control Register 1 • AD1CON2: ADC Control Register 2 • AD1CON3: ADC Control Register 3 The AD1CON1, AD1CON2 and AD1CON3 registers control the operation of the ADC module.
  • Page 5 (e.g., AD1CON1INV). Writing a ‘1’ to any bit position in the Invert register will invert valid bits in the associated register. Reads from the Invert register should be ignored. © 2007-2011 Microchip Technology Inc. DS61104E-page 17-5...
  • Page 6 PIC32 Family Reference Manual Register 17-1: AD1CON1: ADC Control Register 1 Bit Range 31/23/15/7 30/22/14/6 29/21/13/5 28/20/12/4 27/19/11/3 26/18/10/2 25/17/9/1 24/16/8/0 31:24 — — — — — — — — 23:16 — — — — — — — — R/W-0...
  • Page 7 SFRs in the SYSCLK cycle immediately following the instruction that clears the module’s ON bit. The DONE bit is not persistent in automatic modes. It is cleared by hardware at the beginning of the next sample. © 2007-2011 Microchip Technology Inc. DS61104E-page 17-7...
  • Page 8 PIC32 Family Reference Manual Register 17-2: AD1CON2: ADC Control Register 2 Bit Range 31/23/15/7 30/22/14/6 29/21/13/5 28/20/12/4 27/19/11/3 26/18/10/2 25/17/9/1 24/16/8/0 31:24 — — — — — — — — 23:16 — — — — — — — — R/W-0...
  • Page 9 • 2 • (ADCS<7:0> + 1) = 4 • T 00000000 = T • 2 • (ADCS<7:0> + 1) = 2 • T Note 1: is the PIC32 Peripheral Bus clock time period. Refer to Section 6. “Oscillator” (DS61112) for more information. © 2007-2011 Microchip Technology Inc. DS61104E-page 17-9...
  • Page 10 PIC32 Family Reference Manual Register 17-4: AD1CHS: ADC Input Select Register Bit Range 31/23/15/7 30/22/14/6 29/21/13/5 28/20/12/4 27/19/11/3 26/18/10/2 25/17/9/1 24/16/8/0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 31:24 CH0NB — — — CH0SB<3:0> R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 23:16 CH0NA —...
  • Page 11 Note 1: The AD1CSSL register functionality will vary depending on the number of ADC inputs available on the selected device. Refer to the specific device data sheet for additional details on this register. © 2007-2011 Microchip Technology Inc. DS61104E-page 17-11...
  • Page 12: Adc Operation, Terminology And Conversion Sequence

    PIC32 Family Reference Manual 17.3 ADC OPERATION, TERMINOLOGY AND CONVERSION SEQUENCE This section describes the operation of the ADC, the steps required to configure the converter, special features of the module, and provides examples of ADC configuration with timing diagrams and charts showing the expected output of the converter.
  • Page 13 16. The total number of conversion results between interrupts is the SMPI value. The total number of conversions between interrupts cannot exceed the physical buffer length. © 2007-2011 Microchip Technology Inc. DS61104E-page 17-13...
  • Page 14: Adc Module Configuration

    PIC32 Family Reference Manual 17.4 ADC MODULE CONFIGURATION Operation of the ADC module is directed through bit settings in the appropriate registers. The following instructions summarize the actions and the settings. Options and details for each configuration step are provided in subsequent sections.
  • Page 15 There is no numeric difference between 32-bit and 16-bit modes. In 32-bit mode, the sign extension is applied to all 32-bits. In 16-bit mode, the sign extension is applied only to the lower 16-bits of the result. © 2007-2011 Microchip Technology Inc. DS61104E-page 17-15...
  • Page 16 Figure 17-3: ADC Output Data Formats, 32-bit Mode RAM Contents: d09 d08 d07 d06 d05 d04 d03 d02 d01 d00 Read to Bus: Integer d09 d08 d07 d06 d05 d04 d03 d02 d01 d00 Signed Integer d09 d09 d09 d09 d09 d09 d09 d09 d09 d09 d09 d09 d09 d09 d09 d09 d09 d09 d09 d09 d09 d09 d09 d08 d07 d06 d05 d04 d03 d02 d01 d00 Fractional (1.15) d09 d08 d07 d06 d05 d04 d03 d02 d01 d00 Signed Fractional (1.15)
  • Page 17 Figure 17-4: ADC Output Data Formats, 16-bit Mode RAM Contents: d09 d08 d07 d06 d05 d04 d03 d02 d01 d00 Read to Bus: Integer d09 d08 d07 d06 d05 d04 d03 d02 d01 d00 Signed Integer d09 d09 d09 d09 d09 d09 d09 d08 d07 d06 d05 d04 d03 d02 d01 d00 Fractional (1.15) d09 d08 d07 d06 d05 d04 d03 d02 d01 d00 Signed Fractional (1.15)
  • Page 18 PIC32 Family Reference Manual Table 17-2: Numerical Equivalents of Select Result Codes for FORM<2> (AD1CON1<10>) = 1, 32-bit Result 10-bit 32-bit Signed 32-bit Fractional 32-bit Signed 32-bit Integer Format Output Code Integer Format Format Fractional Format 1023/1024 11 1111 1111 0000 0000 0000 0000...
  • Page 19 17.4.6.2 AUTOMATIC SAMPLING Setting the ASAM bit (AD1CON1<2>) enables Auto-Sample mode. In this mode, the sampling will start automatically after the pervious sample has been converted. Figure 17-9 illustrates an example. © 2007-2011 Microchip Technology Inc. DS61104E-page 17-19...
  • Page 20: Selecting The Voltage Reference Source

    PIC32 Family Reference Manual 17.4.7 Selecting the Voltage Reference Source The user can select the voltage reference for the ADC module. The reference can be internal or external. The VCFG<2:0> bits (AD1CON2<15:13>) select the voltage reference for analog-to-digital conversions. The upper voltage reference (V...
  • Page 21 BUFM bit (AD1CON2<1>) is ‘0’. Attempting to create a conversion list with the number of samples greater than 16 will result in the sampling sequence being truncated to 16 samples. © 2007-2011 Microchip Technology Inc. DS61104E-page 17-21...
  • Page 22 PIC32 Family Reference Manual 17.4.10 Buffer Fill Mode The Buffer Fill mode allows the output buffer to be used as a single 16-word buffer or two 8-word buffers. When the Dual Buffer Mode bit, BUFM (AD1CON2<1>), is ‘0’, the complete 16-word buffer is used for all conversion sequences.
  • Page 23 T time of 83.33 ns (see 17.10 “Related Application Notes”). Equation 17-2: Available Sampling Time, Sequential Sampling ) ConversionTime T TriggerPulseInterval T – CONV – CONV Note: is the trigger pulse interval time. © 2007-2011 Microchip Technology Inc. DS61104E-page 17-23...
  • Page 24 PIC32 Family Reference Manual 17.4.12.1 CONFIGURING THE ADC FOR 1000 KSPS OPERATION Calculate the parameters for 1 Msps for a system clock of 60 MHz and Peripheral Clock Divider = 2. The calculation is performed as follows: Calculate the Peripheral Bus clock time period (T ) and the sample plus convert period.
  • Page 25 This trigger option provides the fastest conversion rates on multiple channels. After the start of acquisition, the module will count a number of T clocks specified by the SAMC bits. © 2007-2011 Microchip Technology Inc. DS61104E-page 17-25...
  • Page 26: Miscellaneous Adc Functions

    PIC32 Family Reference Manual 17.4.14 Turning ON the ADC When the ON bit (AD1CON1<15>) is ‘1’, the ADC module is in Active mode and is fully powered and functional. When ON is ‘0’, the ADC module is disabled. The digital and analog portions of the circuit are turned off for maximum current savings.
  • Page 27 ADC configuring for Alternate Sampling mode. Figure 17-6 shows the ADC configuration for Scan mode. Figure 17-7 shows the ADC configuration for a combination of Alternate Sampling mode and Scan mode. © 2007-2011 Microchip Technology Inc. DS61104E-page 17-27...
  • Page 28 PIC32 Family Reference Manual Figure 17-5: Simplified 10-bit High-Speed ADC Block Diagram for Alternate Sample Mode Internal Data Bus Comparator CH0SA<3:0> 10-bit SAR Conversion Logic ADC1BUF0: Data CHONA ADC1BUFF Formatting CH0SB<3:0> AD1CON1 AD1CON2 AD1CON3 AN10 AD1CHS AD1PCFG AN11 AD1CSSL AN12...
  • Page 29 10-bit SAR Conversion Logic Data ADC1BUF0: CH0NA ADC1BUFF Formatting AD1CON1 AD1CON2 AD1CON3 AN10 AD1CHS AD1PCFG AN11 AD1CSSL AN12 AN13 AN14 Sample Control Control Logic Conversion Control AN15 Pin Config Control Input MUX Control © 2007-2011 Microchip Technology Inc. DS61104E-page 17-29...
  • Page 30 PIC32 Family Reference Manual Figure 17-7: Simplified 10-bit High-Speed ADC Block Diagram for Alternate Sample and Scan Mode Internal Data Bus Comparator AD1CSSL 10-bit SAR Conversion Logic Data ADC1BUF0: CH0NA ADC1BUFF Formatting CH0SB<3:0> AD1CON1 AD1CON2 AD1CON3 AN10 AD1CHS AD1PCFG AN11...
  • Page 31: Conversion Sequence Examples

    AD1CON1SET = 0x0002; // start sampling ... DelayNmSec(100); // for 100 ms AD1CON1CLR = 0x0002; // start Converting while (!(AD1CON1 & 0x0001));// conversion done? ADCValue = ADC1BUF0; // yes then get ADC value // repeat © 2007-2011 Microchip Technology Inc. DS61104E-page 17-31...
  • Page 32 PIC32 Family Reference Manual 17.5.9 Automatic Acquisition Figure 17-9 is an example in which setting the ASAM bit (AD1CON1<2>) initiates automatic acquisition, and clearing the SAMP bit (AD1CON1<1>) terminates sampling and starts conversion. After the conversion completes, the module will automatically return to a acquisition state.
  • Page 33 // repeat continuously AD1CON1CLR = 0x0002; // start sampling then... // after 31Tad go to conversion while (!(AD1CON1 & 0x0001)); // conversion done? ADCValue = ADC1BUF0; // yes then get ADC value // repeat © 2007-2011 Microchip Technology Inc. DS61104E-page 17-33...
  • Page 34 PIC32 Family Reference Manual 17.5.11 Free Running Sample Conversion Sequence shown Figure 17-11, using Auto-Convert Conversion Trigger mode (SSRC<2:0> = 111) in combination with the Automatic Sampling Start mode (ASAM = 1), allows the ADC module to schedule acquisition/conversion sequences with no intervention by the user or other device resources.
  • Page 35 SAMP = 1 Figure 17-13: Converting 1 Channel, Auto-Sample Start, Conversion Trigger Based Conversion Start Conversion Trigger ADCLK CONV SAMP CONV SAMP SAMP DONE ADC1BUF0 ADC1BUF1 Instruction Execution set ASAM = 1 © 2007-2011 Microchip Technology Inc. DS61104E-page 17-35...
  • Page 36 PIC32 Family Reference Manual Example 17-5: Converting 1 Channel, Auto-Sample Start, Conversion Trigger Based Conversion Start Code AD1PCFG = 0xFFFB; // all PORTB = Digital; RB2 analog AD1CON1 = 0x0040; // SSRC bit = 010 implies GP TMR3 // compare ends sampling and starts // converting.
  • Page 37 Figure 17-14: Converting One Channel 15 Times 15 Samples Per Interrupt Conversion Trigger SAMP SAMP SAMP SAMP ADCLK CONV CONV CONV CONV Input to MUX A ASAM SAMP DONE ADC1BUF0 ADC1BUF1 ADC1BUFE ADC1BUFF ADIF Instruction Execution set ASAM = 1 © 2007-2011 Microchip Technology Inc. DS61104E-page 17-37...
  • Page 38 PIC32 Family Reference Manual Table 17-4: Converting One Channel 15 Times/Interrupt CONTROL BITS OPERATION SEQUENCE Sequence Select Sample MUX A Inputs: AN0 SMPI<2:0> = 1111 Convert, Write Buffer 0x0 Interrupt on 15th sample Sample MUX A Inputs: AN0 — Convert, Write Buffer 0x1 —...
  • Page 39 Figure 17-15: Scanning Through 16 Inputs 16 Samples Per Interrupt Conversion Trigger SAMP SAMP SAMP SAMP ADCLK CONV CONV CONV CONV Input MUX A AN14 AN15 ASAM SAMP DONE ADC1BUF0 ADC1BUF1 ADC1BUFE ADC1BUFF ADIF Instruction Execution set ASAM = 1 © 2007-2011 Microchip Technology Inc. DS61104E-page 17-39...
  • Page 40 PIC32 Family Reference Manual Table 17-5: Scanning Through 16 Inputs/Interrupt CONTROL BITS OPERATION SEQUENCE Sequence Select Sample MUX A Inputs: AN0 SMPI<2:0> = 1111 Convert, Write Buffer 0x0 Interrupt on 16th sample Sample MUX A Inputs: AN1 — Convert, Write Buffer 0x1 —...
  • Page 41 Figure 17-16: Converting Three Inputs, Three Samples Per Interrupt Using Dual 8-Word Buffers Conversion Trigger SAMP SAMP SAMP ADCLK CONV CONV CONV Input to MUX A SAMP BUFS ADC1BUF0 ADC1BUF1 ADC1BUF2 ADC1BUF8 ADC1BUF9 ADC1BUFA ADIF Instruction Execution set ASAM = 1 clear IFS0,#ADIF clear IFS0,#ADIF © 2007-2011 Microchip Technology Inc. DS61104E-page 17-41...
  • Page 42 PIC32 Family Reference Manual Table 17-6: Converting Three Inputs, Three Samples/Interrupt Using Dual 8-Word Buffers OPERATION SEQUENCE CONTROL BITS Sequence Select Sample MUX A Inputs: AN0 SMPI<2:0> = 0010 Convert AN0, Write Buffer 0x0 Interrupt after every third sample Sample MUX A Inputs: AN1 —...
  • Page 43 Conversion Trigger SAMP SAMP SAMP SAMP ADCLK CONV CONV CONV CONV Input to MUX A Input to MUX B ASAM SAMP DONE ADC1BUF0 ADC1BUF1 ADC1BUFE ADC1BUFF ADIF Instruction Execution set ASAM = 1 © 2007-2011 Microchip Technology Inc. DS61104E-page 17-43...
  • Page 44 PIC32 Family Reference Manual Table 17-7: Converting Two Sets of Inputs Using Alternating Input Selections CONTROL BITS OPERATION SEQUENCE Sequence Select Sample MUX A Inputs: AN0 SMPI<2:0> = 0011 Convert, Write Buffer 0x0 Interrupt on 4th sample Sample MUX B Inputs: AN1 —...
  • Page 45 Conversion Trigger SAMP SAMP SAMP SAMP ADCLK CONV CONV CONV CONV Input to MUX A Input to Max B ASAM SAMP DONE ADC1BUF0 ADC1BUF1 ADC1BUFE ADC1BUFF ADIF Instruction Execution set ASAM = 1 © 2007-2011 Microchip Technology Inc. DS61104E-page 17-45...
  • Page 46 PIC32 Family Reference Manual Figure 17-19: 10-bit High-Speed ADC Block Diagram for Alternating Sample and Scan Internal Data Bus Comparator AD1CSSL 10-bit SAR Conversion Logic ADC1BUF0: Data CHONA ADC1BUFF Formatting CHOSB<3:0> AD1CON1 AD1CON2 AD1CON3 AN10 AD1CHS AD1PCFG AN11 AD1CSSL AN12...
  • Page 47 AN2 sample 2 AN2 sample 6 ADC1BUF2 AN1 sample 3 AN1 sample 7 ADC1BUF3 AN2 sample 4 AN2 sample 8 ADC1BUF4 ADC1BUF5 ADC1BUF6 ADC1BUF7 • • • ADC1BUF8 ADC1BUF9 ADC1BUFA ADC1BUFB ADC1BUFC ADC1BUFD ADC1BUFE ADC1BUFF © 2007-2011 Microchip Technology Inc. DS61104E-page 17-47...
  • Page 48 PIC32 Family Reference Manual 17.5.18 Transfer Function The ideal transfer function of the ADC is shown in Figure 17-20. The difference of the input voltages, (V – V ), is compared to the reference, (V + – V • The first code transition occurs when the input voltage is (V + –...
  • Page 49 A 100-pin PIC32 device package is shown as an example in Figure 17-21. Figure 17-21: ADC Voltage Reference Schematic 10 μF 0.1 μF 0.01 μF 1 μF 0.1 μF 0.01 μF 1 μF 0.1 μF 0.01 μF © 2007-2011 Microchip Technology Inc. DS61104E-page 17-49...
  • Page 50: Connection Considerations

    PIC32 Family Reference Manual 17.5.20 ADC Sampling Requirements The analog input model of the 10-bit ADC module is shown in Figure 17-22. The total acquisition time for the analog-to-digital conversion is a function of the internal amplifier settling time and the holding capacitor charge time.
  • Page 51: Initialization

    AD1CON1CLR = 0x0002; /* End Sampling and start Conversion*/ /* The DONE bit is set by hardware when the convert sequence is finished. */ /* The ADIF bit will be set. */ © 2007-2011 Microchip Technology Inc. DS61104E-page 17-51...
  • Page 52 PIC32 Family Reference Manual Example 17-7: Converting 1 Channel at 400 ksps, Auto-Sample Start, 2 T Sampling Time Code Example AD1PCFG = 0xFFFB; all PORTB = Digital; RB2 = analog AD1CON1 = 0x00E0; SSRC bit = 111 implies internal counter ends sampling and starts converting.
  • Page 53: Interrupts

    Some PIC32 devices feature persistent interrupts. On such devices, clearing the AD1IF flag bit will not have any effect unless ADC1BUFx register is read. Refer to the specific device data sheet and Section 8. “Interrupts” (DS61108) for more information. © 2007-2011 Microchip Technology Inc. DS61104E-page 17-53...
  • Page 54: Operation During Sleep And Idle Modes

    PIC32 Family Reference Manual 17.8 OPERATION DURING SLEEP AND IDLE MODES Sleep and Idle modes are useful for minimizing conversion noise because the digital activity of the CPU, buses and other peripherals is minimized. 17.8.1 CPU Sleep Mode Without RC ADC Clock When the device enters Sleep mode, all clock sources to the module are shut down and stay at logic ‘0’.
  • Page 55: Effects Of Various Resets

    Any conversion that was in progress will terminate and the result will not be written to the result buffer. The values in the ADC1BUFx registers are initialized after a WDT reset. ADC1BUF0 through ADC1BUFF will contain 0x00000000. © 2007-2011 Microchip Technology Inc. DS61104E-page 17-55...
  • Page 56: Related Application Notes

    Four Channel Digital Voltmeter with Display and Keyboard AN557 Understanding ADC Performance Specifications AN693 Note: Please visit the Microchip web site (www.microchip.com) for additional Application Notes and code examples for the PIC32 family of devices. DS61104E-page 17-56 © 2007-2011 Microchip Technology Inc.
  • Page 57: Revision History

    - Removed Table 17-9: ADC Interrupt Vectors for Various Offsets with EBASE = 0x8000:0000 • Changed all occurrences of PIC32MX to PIC32 • Updates to register formatting and minor text updates have been incorporated throughout the document © 2007-2011 Microchip Technology Inc. DS61104E-page 17-57...
  • Page 58 PIC32 Family Reference Manual NOTES: DS61104E-page 17-58 © 2007-2011 Microchip Technology Inc.
  • Page 59 Select Mode, Total Endurance, TSHARC, UniWinDriver, WiperLock and ZENA are trademarks of Microchip Technology Incorporated in the U.S.A. and other countries. SQTP is a service mark of Microchip Technology Incorporated in the U.S.A. All other trademarks mentioned herein are property of their respective companies.
  • Page 60 Fax: 408-961-6445 China - Xian Tel: 86-29-8833-7252 Toronto Fax: 86-29-8833-7256 Mississauga, Ontario, Canada China - Xiamen Tel: 905-673-0699 Tel: 86-592-2388138 Fax: 905-673-6509 Fax: 86-592-2388130 China - Zhuhai Tel: 86-756-3210040 08/02/11 Fax: 86-756-3210049 DS61104E-page 17- 60 © 2007-2011 Microchip Technology Inc.

Table of Contents