Section 46. Scalable Comparator Module

Similar documents
Section 24. Comparator

Section 20. Comparator Voltage Reference Module

Section 19. Dual Comparator Module

Section 28. WDT and SLEEP Mode

Section 8. Reset HIGHLIGHTS. Reset. This section of the manual contains the following major topics:

Section 9. Watchdog Timer (WDT)

Section 9. Watchdog Timer and Power-up Timer

Section 16. Analog-to-Digital Converter (ADC)

Section 10. Power-Saving Features

Section 14. Timer1 HIGHLIGHTS. Timer1. This section of the manual contains the following major topics:

n/a PIC12F629-I/P (RC) n/a PIC12F629-I/SN (RC) n/a PIC12F675-I/P (RC) n/a PIC12F675-I/SN MICROCONTROLLER (RC)

Section 8. Reset. Reset HIGHLIGHTS. This section of the manual contains the following topics:

Section 11. Timer0. Timer0 HIGHLIGHTS. This section of the manual contains the following major topics:

PIC Microcontroller Introduction

William Sandqvist

Section 13. Timer0 HIGHLIGHTS. Timer0. This section of the manual contains the following major topics:

Section 16. Basic Sychronous Serial Port (BSSP)

User-configurable Resolution. 9 to 12 bits (0.5 C to C)

User-configurable Resolution. 9 to 12 bits (0.5 C to C)

DS1306. Serial Alarm Real Time Clock (RTC)

Section 9. Watchdog Timer (WDT) and Power-Saving Modes

Section 30. In-Circuit Serial Programming (ICSP )

Section 37. Real-Time Clock and Calendar (RTCC)

Section 21. Addressable USART

IP-THERMISTOR. 6 CHANNELS TEMPERATURE 8-CHANNEL VOLTAGE Industry Pack module HARDWARE REFERENCE MANUAL. Revision 1.0 JANUARY, 2008

Section 32. High-Level Device Integration

DS1676 Total Elapsed Time Recorder, Erasable

Section 33. Device Configuration (Part II)

commodore semiconductor group NMOS 950 Rittenhouse Rd., Norristown, PA Tel.: 215/ TWX: 510/ (MEMORY, I/O, TIMER ARRAY)

Section 33. Programming and Diagnostics

Understanding the basic building blocks of a microcontroller device in general. Knows the terminologies like embedded and external memory devices,

DS1305EN. Serial Alarm Real-Time Clock

IMPROVING PROCESS CONTROL APPLICATIONS BY USING IP COMMUNICATIONS

Section 21. UART UART HIGHLIGHTS. This section of the manual contains the following major topics:

DS1305. Serial Alarm Real Time Clock (RTC) FEATURES PIN ASSIGNMENT ORDERING INFORMATION

CW2013. Low-Cost 1s Fuel Gauge IC with Low-SOC Alert. General Description. Features. Applications. Order Information

Microcontrollers and Interfacing week 10 exercises

NM-251D-INC. Dual Axis Inclinometer Output Format converter User Guide V1.00. Introduction

Programmable Threshold Comparator Data Sheet

Section 10. Watchdog Timer and Power Saving Modes

VREG_3V3 Block User Guide V02.03

PIC16F87X. 28/40-pin 8-Bit CMOS FLASH Microcontrollers. Devices Included in this Data Sheet: Pin Diagram PDIP. Microcontroller Core Features:

1. Features and Benefits

Low Voltage, 10-Bit Digital Temperature Sensor in 8-Lead MSOP AD7314

PIC Serial Peripheral Interface (SPI) to Digital Pot

PMS165C. 8bit IO-Type Controller

DS1305EN. Serial Alarm Real-Time Clock

Chapter 26 Topic Page 26.1 ADC12 Introduction

12-BIT, 200-KSPS, 11 CHANNEL, LOW POWER, SERIAL ADC WITH INTERNAL REFERENCE

SLG4AX OSFP Low-Speed Module Controller. General Description. Pin Configuration

DS1305 Serial Alarm Real Time Clock (RTC)

24-Bit Analog-to-Digital Converter (ADC) for Weigh Scales FEATURES APPLICATIONS S8550 VFB. Analog Supply Regulator. Input MUX.

Modtronix Engineering Modular Electronic Solutions SBC28DC. Single board computer for 28 pin DIP PICs

Section 18. Serial Peripheral Interface (SPI)

Designing with Siliconix PC Card (PCMCIA) Power Interface Switches

SILICON MICROSTRUCTURES

DS1302. Trickle Charge Timekeeping Chip FEATURES PIN ASSIGNMENT PIN DESCRIPTION

RTC Interface 89C51 DS M. Krishna Kumar MAM/M7/LU17/V1/ Vcc VCC 5 SDA P1.0 6 SCL P KHz 3 BAT 3.

DS 1682 Total Elapsed Time Recorder with Alarm

More PIC Programming. Serial and parallel data transfer External busses Analog to digital conversion

CMOS SyncFIFO 64 X 9, 256 x 9, 512 x 9, 1,024 X 9, 2,048 X 9, 4,096 x 9 and 8,192 x 9

Section 4. Program Memory

Introduction to PIC Programming

Section 7. Oscillator

EFM8LB1 Analog to Digital Converter (ADC) 2 2 S E P T E M B E R

Section 30. I/O Ports with Peripheral Pin Select

DS1306 Serial Alarm Real-Time Clock

Section 13. Parallel Master Port (PMP)

Features. Ordering Information. Selector Guide. Applications. Pin Configurations. I 2 C Port Expander with 8 Open-Drain I/Os

I/O Ports with Interrupt-on-Change (IOC)

ED1021 I/O Expander with UART interface & analog inputs

VREG_3V3 Block User Guide V03.03

Hello, and welcome to this presentation of the STM32 Universal Synchronous/Asynchronous Receiver/Transmitter Interface. It covers the main features

Course Introduction. Content: 21 pages 4 questions. Learning Time: 35 minutes

PIC10F200/202/204/206 Data Sheet

PTB O165CXXS 8bit IO-Type Controller Data Sheet

For reference only Refer to the latest documents for details

Pic24f Family Reference Manual Section 14. Timers

Keywords Digital IC tester, Microcontroller AT89S52

CY7C603xx CYWUSB

Web Site: Forums: forums.parallax.com Sales: Technical:

VREG_3V3 Block User Guide V05.03

CSE 466 Exam 1 Winter, 2010

Section 20. Serial Peripheral Interface (SPI)

and 8 Open-Drain I/Os

MM912_634, Silicon Analog Mask (M91W) / Digital Mask (N53A) Errata

LC717A10AR. Overview. Features. CMOS LSI Capacitance-Digital-Converter LSI for Electrostatic Capacitive Touch Sensors

I 2 C Port Expander with Eight Inputs. Features

PC104P-16AO20 20-Channel 16-Bit High-Speed Analog Output PC104-Plus Board With 440,000 Samples per Second per Channel, and Simultaneous Clocking

±0.5 C Accurate, 16-Bit Digital SPI Temperature Sensor ADT7310

Section 8. Interrupts

CMOS Z8 OTP Microcontrollers

Section 7. Oscillator

Description and Application Manual for 2SB315A SCALE Dual-Channel Plug-and-play IGBT Drivers

10-Bit Digital Temperature Sensor (AD7416) and 4-/1-Channel ADCs AD7416/AD7417/AD7418

Digital Thermometer and Thermostat

XEN1210 Magnetic Sensor

I 2 C Serial EEPROM Family Data Sheet

Capacitive Touch Remote Control Reference Design User s Guide

ILI2303. ILI2303 Capacitive Touch Sensor Controller. Specification

Transcription:

46 Section 46. Scalable Module Scalable Module HIGHLIGHTS This section of the manual contains the following major topics: 46.1 Introduction... 46-2 46.2 Control Register... 46-4 46.3 Operation... 46-7 46.4 Response Time... 46-7 46.5 Outputs... 46-8 46.6 Analog Input Connection Considerations... 46-9 46.7 Interrupts... 46-9 46.8 Code Examples... 46-10 46.9 Operation During Sleep and Idle Modes... 46-12 46.10 Effects of a Reset... 46-12 46.11 Related Application Notes... 46-13 46.12 Revision History... 46-14 2010 Microchip Technology Inc. Advance Information DS39734A-page 46-1

PIC24F Family Reference Manual 46.1 INTRODUCTION The scalable comparator module is comprised of several identical analog comparator blocks, each complete with its own supporting input selectors and output logic. Each comparator can be configured in a variety of ways, independent of the other comparators. Inputs can be selected from four analog inputs multiplexed with I/O pins, external voltage references, and the on-chip voltage reference (see Section 20. Voltage Reference Module ) or the on-chip band gap reference. A status register provides a single location to monitor all comparators simultaneously. The block diagram for a single comparator is shown in Figure 46-1. Depending on the device family, the scalable comparator module may contain anywhere from two to six analog comparators; the most commonly used configuration contains three. Refer to the device data sheet for specific information. Note: A comparator module with two analog comparators may also be the integrated dual comparator module, described in the Family Reference Manual chapter Dual Module (DS39710). Check the device data sheet to verify which comparator module is included in a particular device. Figure 46-1: Single Block Diagram CCH<1:0> EVPOL<1:0> CXINB CXINC CXIND Trigger/Interrupt Logic EVT VBG/2 OR CVREF- (1) CREF CPOL CXINA CVREF OR CVREF+ (1) Note 1: For some devices, CVREF+ and CVREF- are the options for and, respectively. This is device-specific and not selectable by the user. Refer to the device data sheet for specific information. DS39734A-page 46-2 Advance Information 2010 Microchip Technology Inc.

Section 46. Scalable Module 46.1.1 Configuration Each of the several comparators has complete control over its input selections, output inversion, output on I/O pin and event generation. The input of each comparator can select from one of three I/O pins (INB, CXINC or IND), while the input of the comparator comes from the comparator voltage reference, or the positive I/O pin (INA or CVREF). The comparators provide a common-mode voltage range which is nominally rail-to-rail, VSS to VDD. Refer to the particular data sheet for actual electrical specifications. The configuration options are shown in Figure 46-2. The comparator also has four options to configure a separate event/trigger output based on changes of the comparator s output. Users can select from rising-edge, falling-edge, and all transitions. If the mode is changed, the comparator output level may not be valid for the specified mode change delay. Note: interrupts should be disabled during a mode change; otherwise, a false interrupt may occur. 46 Scalable Module Figure 46-2: Individual Configurations Off CON = 0, CREF = x, CCH<1:0> = xx Off (Read as 0 ) INB > INA Compare CON = 1, CREF = 0, CCH<1:0> = 00 COMPARATOR CXINB > CVREF COMPARE CON = 1, CREF = 1, CCH<1:0> = 00 CXINB CXINA CXINB CVREF (1) INC > INA Compare CON = 1, CREF = 0, CCH<1:0> = 01 INC > CVREF Compare CON = 1, CREF = 1, CCH<1:0> = 01 CXINC CXINA CXINC CVREF (1) IND > INA Compare CON = 1, CREF = 0, CCH<1:0> = 10 IND > CVREF Compare CON = 1, CREF = 1, CCH<1:0> = 10 CXIND CXINA CXIND CVREF (1) VBG > INA Compare CON = 1, CREF = 0, CCH<1:0> = 11 VBG > CVREF Compare CON = 1, CREF = 1, CCH<1:0> = 11 VBG/2 (1) CXINA VBG/2 (1) CVREF (1) Note 1: For some devices, CVREF+ and CVREF- are the options for and, respectively. Refer to the device data sheet for specific information. 2010 Microchip Technology Inc. Advance Information DS39734A-page 46-3

PIC24F Family Reference Manual 46.2 CONTROL REGISTER The scalable comparator module uses several registers for configuration and control. Depending on the number of comparators, up to seven registers are implemented. The CMxCON registers (Register 46-1) are used to configure the individual comparators. Each comparator uses its own individually-numbered CMCON register. The CON bit (CMxCON<15>) enables or disables the individual comparator. The bit (CMxCON<14>) enables the output of the comparator to appear on the corresponding pin. The COUT bit (CMxCON<8>) reports the output state of the comparator, as determined by the relative values of Vin+ and Vinand the CPOL bit (CMxCON<13>). The CREF and CCH<1:0> bits (CMxCON<4> and <1:0>, respectively) configure the and inputs to the comparator. The pin can select from a dedicated analog input (INA) or the comparator voltage reference (CVREF or CVREF+). The pin can select from four sources: three other dedicated analog inputs (INB, INC or IND) or voltage reference (CVREF- or VBG/2). Taken together, this provides a total of eight input configurations for each comparator. (The CVREF and internal band gap options available to the user are solely determined by the comparator voltage reference module available on the microcontroller. Voltage reference options are controlled by the CVRCON register, discussed in Section 20. Voltage Reference Module.) The EVPOL bits (CMxCON<7:6>) configure the event-detection logic to report changes to the output state of the comparator, which can in turn be used for event or interrupt generation. The options include event generation on rising state changes (low-to-high), falling state changes (high-to-low), and all state changes. When a configured event occurs, it is flagged by the CEVT bit (CMxCON<9>). The CMSTAT register (Figure 46-2) serves as a convenient monitor for the status of all comparators; one CMSTAT register is implemented for the entire module. The and EVT bits mirror the states of the corresponding bits in the CMxCON registers on a synchronous basis. In the CMSTAT register, all and EVT bits are read-only, and cannot be changed. In addition, the CMIDL bit (CMSTAT<15>) determines how the comparator module as a whole operates when the microcontroller is in Idle mode. DS39734A-page 46-4 Advance Information 2010 Microchip Technology Inc.

Section 46. Scalable Module 46 Register 46-1: CMxCON: x Control Registers (s 1 Through n) R/W-0 R/W-0 R/W-0 U-0 U-0 U-0 R/W-0 R-0 CON CPOL CEVT COUT bit 15 bit 8 R/W-0 R/W-0 U-0 R/W-0 U-0 U-0 R/W-0 R/W-0 EVPOL1 EVPOL0 CREF CCH1 CCH0 bit 7 bit 0 Scalable Module Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as 0 -n = Value at POR 1 = Bit is set 0 = Bit is cleared x = Bit is unknown bit 15 bit 14 CON: Enable bit 1 = is enabled 0 = is disabled : Output Enable bit 1 = output is present on the pin 0 = output is internal only bit 13 CPOL: Output Polarity Select bit 1 = output is inverted 0 = output is not inverted bit 12-10 Unimplemented: Read as 0 bit 9 bit 8 CEVT: Event bit 1 = event defined by EVPOL<1:0> has occurred; subsequent triggers and interrupts are disabled until the bit is cleared 0 = event has not occurred COUT: Output bit When CPOL = 0: 1 = > 0 = < When CPOL = 1: 1 = < 0 = > VINbit 7-6 EVPOL<1:0>: Trigger/Event/Interrupt Polarity Select bits 11 = Trigger/event/interrupt generated on any change of the comparator output (while CEVT = 0) 10 = Trigger/event/interrupt generated on transition of the comparator output: If CPOL = 0 (non-inverted polarity): High-to-low transition only. If CPOL = 1 (inverted polarity): Low-to-high transition only. 01 = Trigger/Event/Interrupt generated on transition of comparator output: If CPOL = 0 (non-inverted polarity): Low-to-high transition only. If CPOL = 1 (inverted polarity): High-to-low transition only. 00 = Trigger/event/interrupt generation is disabled bit 5 Unimplemented: Read as 0 Note 1: The use of either CVREF or CVREF+ for CREF options, and VBG/2 or CVREF- for CCH<1:0> options, are device-specific and not selectable by the user. Refer to the device data sheet for specific information. 2010 Microchip Technology Inc. Advance Information DS39734A-page 46-5

PIC24F Family Reference Manual Register 46-1: CMxCON: x Control Registers (s 1 Through n) (Continued) bit 4 CREF: Reference Select bits (non-inverting input) 1 = Non-inverting input connects to internal CVREF or CVREF+ source (1) 0 = Non-inverting input connects to CXINA pin bit 3-2 Unimplemented: Read as 0 bit 1-0 CCH<1:0>: Channel Select bits 11 = Inverting input of comparator connects to internal VBG/2 or CVREF- source (1) 10 = Inverting input of comparator connects to CXIND pin 01 = Inverting input of comparator connects to CXINC pin 00 = Inverting input of comparator connects to CXINB pin Note 1: The use of either CVREF or CVREF+ for CREF options, and VBG/2 or CVREF- for CCH<1:0> options, are device-specific and not selectable by the user. Refer to the device data sheet for specific information. Register 46-2: CMSTAT: Module Status Register R/W-0 U-0 R-0 R-0 R-0 R-0 R-0 R-0 CMIDL C6EVT (1) C5EVT (1) C4EVT (1) C3EVT (1) C2EVT C1EVT bit 15 bit 8 U-0 U-0 R-0 R-0 R-0 R-0 R-0 R-0 C6OUT (1) C5OUT (1) C4OUT (1) C3OUT (1) C2OUT C1OUT bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as 0 -n = Value at POR 1 = Bit is set 0 = Bit is cleared x = Bit is unknown bit 15 CMIDL: Stop in Idle Mode bit 1 = Module does not generate interrupts in Idle mode, but is otherwise operational 0 = Module continues normal operation in Idle mode bit 14 Unimplemented: Read as 0 bit 13-8 EVT: x Event Status bit (s 1 through 6) (read-only) (1) Shows the current event status of x (CMxCON<9>). bit 7-6 Unimplemented: Read as 0 bit 5-0 : x Output Status bit (s 1 through 6) (read-only) (1) Shows the current output of x (CMxCON<8>). Note 1: Bits are only implemented when the corresponding number of comparators are present in the module. Refer to the specific device data sheet for more information. When the comparators are not present, these bits are unimplemented and read as 0. DS39734A-page 46-6 Advance Information 2010 Microchip Technology Inc.

46.3 COMPARATOR OPERATION Section 46. Scalable Module A single comparator is shown in Figure 46-3, along with the relationship between the analog input levels and the digital output. When the analog input at is less than the analog input, the output of the comparator is a digital low level. When the analog input at is greater than the analog input, the output of the comparator is a digital high level. The shaded areas of the output of the comparator in Figure 46-3 represent the uncertainty due to input offsets and response time. 46.3.1 Internal Reference Signals Some applications require multiple comparators to operate from a common reference. The comparators allow the selection of an internally generated voltage reference, CVREF, from the comparator voltage reference module. The internal reference is available to a comparator at its non-inverting input when the CREF bit (CMxCON<4>) is set. On some PIC24F devices, an optional CVREF- signal can be selected at the inverting input with the CCH bits (CMxCON<1:0>). The voltage reference and its options are described in more detail in Section 20. Voltage Reference Module. For device-specific options, refer to the device data sheet. 46 Scalable Module Figure 46-3: Single + Output Output 46.4 COMPARATOR RESPONSE TIME Response time is the maximum time, after selecting a new reference voltage or input source, before the comparator output has a valid level. If the internal reference is changed, the maximum delay of the internal voltage reference must be considered when using the comparator outputs (Refer to Tset, VR310, on the data sheet.) Otherwise, the maximum delay of the comparators should be used. Refer to Tresp on the data sheet for the particular part. 2010 Microchip Technology Inc. Advance Information DS39734A-page 46-7

PIC24F Family Reference Manual 46.5 COMPARATOR OUTPUTS The comparator outputs can be read from the CMxCON and CMSTAT registers. The COUT/ bits are read-only, as are the EVT bits in CMSTAT; the CEVT bit in each CMxCON register is both readable and writable. The comparator outputs may also be directly output to the I/O pins by setting the bit. When enabled, multiplexers in the output path of the I/O pins switch, and the unsynchronized output of the comparator appears on the pin. Figure 46-4 shows the comparator output logic. The polarity of the comparator output can be changed using the CPOL bit (CMxCON<13>); setting the bit inverts the digital output as defined in Section 46.3 Operation. This change carries through uniformly to the internal status indicator bit and the output pin, as well as to event detection logic. The uncertainty of each of the comparators is related to the input offset voltage and the response time given in the electrical specifications. Note 1: When reading the PORT register, all pins configured as analog inputs will read as a 0. s configured as digital inputs will convert an analog input according to the Schmitt Trigger input specification. 2: Analog levels on any pin defined as a digital input may cause the input buffer to consume more current than is specified. Figure 46-4: Output Block Diagram PORT pins Multiplex + pin CPOL D Q Bus Data Read CMxCON EN D Q Set CMIF bit Reset EN CL From Other s DS39734A-page 46-8 Advance Information 2010 Microchip Technology Inc.

PIC24F Family Reference Manual 46.6 ANALOG INPUT CONNECTION CONSIDERATIONS A simplified circuit for an analog input is shown in Figure 46-5. A maximum source impedance of 10 k is recommended for the analog sources. Any external component connected to an analog input pin, such as a capacitor or a Zener diode, should have very little leakage current. Refer to the device data sheet for input voltage limits. Figure 46-5: Analog Input Model VDD VA RS < 10k AIN CPIN 5 pf ILEAKAGE 500 na RIC Input VSS Legend: CPIN = Input Capacitance ILEAKAGE = Leakage Current at the pin due to various junctions RIC = Interconnect Resistance RS = Source Impedance VA = Analog Voltage 46.7 COMPARATOR INTERRUPTS The Interrupt Flag CMIF (IFS1<2>) is set whenever the Event flag of any comparator is set. The application can read CEVT (CMxCON<9>) or the corresponding EVT bit (CMSTAT<8+x>) to determine the actual source. Note that the CEVT bit is writable via the CMxCON register. After event detection, hardware sets CEVT; it must be cleared in software to enable another operation. Both the CMIF and CEVT bits must be reset by clearing them in software. If the CMIE bit (IEC1<2>) is cleared, an interrupt will not be generated; however, the CMIF bit will still be set if an interrupt condition occurs. The user can clear the interrupt in the Interrupt Service Routine by clearing CMIF. See Section 8. Interrupts in this manual for more information. DS39734A-page 46-9 Advance Information 2010 Microchip Technology Inc.

46.8 CODE EXAMPLES Section 46. Scalable Module The following code examples show a typical sequence for initializing and configuring a detection event for an analog comparator. While these examples only discuss a single comparator, operations for several comparators are very similar. 46.8.1 Initialization The initialization sequence in Example 46-1 configures one unit (C2) in the comparator module with its output enabled and inverted. The C2IN- terminal is connected to VBG/2 (nominally, 600 mv) and the C2IN+ terminal is fed from the C2INA pin. The delay used in the example is based on an 8 MHz oscillator. 46 Scalable Module Example 46-1: Configuration // PIC24F256GB110 C2 Initialization Example // 22: C2INA. #define C1OUT_IO 1 // C1 OUT # for MUX Table #define C2OUT_IO 2 // C2 OUT # for MUX Table #define C3OUT_IO 36 // C3 OUT # for MUX Table TRISBbits.TRISB3 = 1; AD1PCFGbits.PCFG3 = 0; IEC1bits.CMIE = 0; CM2CONbits. = 1; CM2CONbits.CPOL = 1; CM2CONbits.EVPOL = 0; CM2CONbits.CREF = 0; CM2CONbits.CH = 3; CM2CONbits.CON = 1; IFS1bits.CMIF = 0; // Disable Digital Output on port pin // Set input to Analog // IE Off so no interrupt occurs from set-up // Enable output pin // Invert sense. +In High ==> Out Low // No event detection // +IN is C2INA // -IN is Vbg/2 ~= 0.60 V // Turn ON // Clear IF after set-up asm volatile("repeat #40"); //Delay 10us Nop(); // Assign C2OUT to desired RP pin. // (See Sec 12 I/O Ports with PPS.) 46.8.2 Event Capture The example in Example 46-2 shows the use of the comparator s event detection logic. Note that the EVPOL bits select the direction of the edge to be detected, and provides an option for choosing both edges, thus detecting any change. Furthermore, the CPOL bit switches polarity before the edge detector. Although status is checked in a simple while loop here, it would most often be found in an Interrupt Service Routine (ISR). In the ISR, the CMSTAT register gives visibility of all comparators simultaneously. However, CMSTAT flags are read-only, and the detect bits must be cleared in the individual CMxCON registers. 2010 Microchip Technology Inc. Advance Information DS39734A-page 46-10

PIC24F Family Reference Manual Example 46-2: Event Detection // PIC24F256GB110 C1 Event Example // 21: C1INB. #define C1EVT 0X0100 // Event flag in CMSTAT Module Status Reg #define C2EVT 0X0200 // Event flag in CMSTAT Module Status Reg #define C3EVT 0X0400 // Event flag in CMSTAT Module Status Reg #define C1OUT 0X0001 // Output flag in CMSTAT Module Status Reg #define C2OUT 0X0002 // Output flag in CMSTAT Module Status Reg #define C3OUT 0X0004 // Output flag in CMSTAT Module Status Reg unsigned int eventcount = 0; TRISBbits.TRISB4 = 1; AD1PCFGbits.PCFG4 = 0; IEC1bits.CMIE = 0; CM1CONbits. = 0; CM1CONbits.CPOL = 0; CM1CONbits.EVPOL = 2; CM1CONbits.CREF = 1; CM1CONbits.CCH = 0; CM1CONbits.CON = 1; CVRCON = 0x88; CM1CONbits.CEVT = 0; IFS1bits.CMIF = 0; while (1) { if (CMSTAT & C1EVT) { eventcount++; } } CM1CONbits.CEVT = 0; // Disable Digital Output on port pin // Set input to Analog // IE Off so no interrupt occurs from setup // Disable output pin // Standard sense. +In High ==> Out High // Event detected on output edge falling // +IN is internal CVRef // -IN is C1INB // Turn ON // CVRef = (1/2) * (AVdd - AVss) // Clear IF after set-up // When C1INB RISES above AVdd/2, // C1OUT falls & edge is counted. // Loop forever // Check C1EVT bit // Count edges for whoever uses them // Must use Control Register to clear flag. // Status is read-only. DS39734A-page 46-11 Advance Information 2010 Microchip Technology Inc.

Section 46. Scalable Module 46.9 OPERATION DURING SLEEP AND IDLE MODES 46.9.1 Operation During Sleep When a comparator is active and the device is placed in Sleep mode, the comparator remains active and the interrupt is functional, if enabled. This interrupt will wake-up the device from Sleep mode, when enabled. Each operational comparator will consume additional current, as shown in the comparator specifications. To minimize power consumption while in Sleep mode, turn off all comparators by clearing the CON bits (CMxCON<15> = 0), before entering Sleep. If the device wakes up from Sleep, the contents of the CMxCON registers are not affected. See Section 10. Power-Saving Features in this manual for additional information on Sleep. 46 Scalable Module 46.9.2 Operation During Idle When a comparator is active and the device is placed in Idle mode, the comparator remains active and interrupts are generated, if enabled, and CMIDL = 0 (CMCON<15>). If it is desired for the comparators to operate in Idle mode without generating interrupts, set the CMIDL bit (CMSTAT<15>). See Section 10. Power-Saving Features in this manual for more information on Idle. 46.10 EFFECTS OF A RESET A device Reset forces the CMxCON registers to their Reset state, causing the comparators to be turned off (CON = 0). However, the input pins multiplexed with analog input sources are configured as analog inputs by default on device Reset. The I/O configuration for these pins is determined by the ADxPCFG or ANSx registers, depending on the device. Therefore, device current is minimized when analog inputs are present at Reset time. 2010 Microchip Technology Inc. Advance Information DS39734A-page 46-12

PIC24F Family Reference Manual 46.11 RELATED APPLICATION NOTES This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the PIC24F device family, but the concepts are pertinent and could be used with modification and possible limitations. The current application notes related to the module are: Title Application Note # Resistance and Capacitance Meter Using a PIC16C622 AN611 Make a Delta-Sigma Converter Using a Microcontroller s Analog Module AN700 A Based Slope ADC AN863 Oscillator Circuits for RTD Temperature Sensors AN895 Temperature Measurement Circuits for Embedded Applications AN929 Analog Sensor Conditioning Circuits An Overview AN990 Note: Please visit the Microchip web site (www.microchip.com) for additional application notes and code examples for the PIC24F family of devices. DS39734A-page 46-13 Advance Information 2010 Microchip Technology Inc.

46.12 REVISION HISTORY Revision A (January 2010) Section 46. Scalable Module This is the initial released revision of this document. 46 Scalable Module 2010 Microchip Technology Inc. Advance Information DS39734A-page 46-14