C.6
LESSON 4 – ANALOG-TO-DIGITAL CONVERTERS AND COMPARATORS
This lesson is broken up into two programs which demonstrate how to use the
analog-to-digital converter, the comparator and the internal voltage reference. The first
program set is comp.asm (written in assembly) and comp.c (written in C). This program
shows the very basic implementation of using the comparator with the internal voltage
reference. The second program set is atod.asm (written in assembly) and atod.c
(written in C). This program uses the LED display library to show the value of the
analog-to-digital (A-D) converter.
C.6.1
Comparator Lesson
For this lesson, the comparator is configured as a dedicated comparator driving the
GP2 pin directly. With <CM2:CM0> = 101, the comparator has multiplexed inputs.
GP0/CIN+ is selected as the input to the V IN - by setting CIS = 1, thus making the analog
potentiometer the one input. The internal voltage reference is used as the other input
to the comparator on V IN +. The module compares the potentiometer voltage with the
reference, and the logic is setup (CINV = 1) such that the output is high when the input
voltage is higher than the reference. LED3 is driven directly by the comparator and is
lit when the output of the module is high. To light D3, you must configure RA4 (GPIO4)
and RA2 (GPIO2) as digital outputs via the TRIS register, RA4 is set low and RA2 is
driven directly by the comparator without additional software overhead. The remaining
I/O's are configured as high impedance inputs.
Note:
The schematics, as shown in Appendix A, display the 14-pin device pinout.
This is compatible with 8-pin devices.
The internal voltage reference is essentially a variable resistor based voltage divider
between V DD and V SS . Use the low range mode (VRR = 1) and set the internal
reference to be 0.5 V DD by selecting <VR3:VR0> = 1100, thus C VREF = V DD *(12/24).
By stepping through the different voltage reference settings, a basic-low resolution
analog-to-digital converter can be implemented.
The comparator module has seven different modes. Three of the modes can drive an
output pin directly. The software can monitor the output directly or create an interrupt
on change. Bits CMIE and PEIE must be set to enable the comparator interrupt which
can be used to wake the device from SLEEP.
Figure C-11 shows the project setup for the assembly and C projects.
FIGURE C-11:
? 2004 Microchip Technology Inc.
ASSEMBLY AND C PROJECT SETUP
DS40051D-page 57
相关PDF资料
DV164120 KIT STARTER PICKIT 2
DV164121 KIT PICKIT 2 DEBUG EXPRESS
DV164122 ANALYZER SRL PICKIT W/DEMO BOARD
DV164131 KIT STARTER PICKIT 3
DV164132 KIT EVAL F1 FOR PIC12F1/PIC16F1
DV243003 KIT STARTER FOR SRL MEM PRODUCTS
DVA1001 ADAPTER FOR PIC16F716 18DIP
DVA1004 DEVICE ADAPTER 8/14/20DIP
相关代理商/技术参数
DV164101 制造商:Microchip Technology Inc 功能描述:TOOLS: FLASH MICROCONTROLLER (
DV164102 功能描述:开发板和工具包 - 无线 rfPICkit RoHS:否 制造商:Arduino 产品:Evaluation Boards 工具用于评估:AT32UC3L 核心:AVR32 频率: 接口类型:USB 工作电源电压:5 V
DV164120 功能描述:电路内置调试器 PICkit 2 8/14/20P Flash RoHS:否 制造商:Microchip Technology 产品:In-Circuit Debugger Kits 工具用于评估:PIC MCUs, dsPIC DSCs 用于:07-00024, AC164113 核心:dsPIC, PIC 接口类型:USB 工作电源电压:3 V to 5 V
DV164121 功能描述:电路内置调试器 PICkit 2 Debug Express RoHS:否 制造商:Microchip Technology 产品:In-Circuit Debugger Kits 工具用于评估:PIC MCUs, dsPIC DSCs 用于:07-00024, AC164113 核心:dsPIC, PIC 接口类型:USB 工作电源电压:3 V to 5 V
DV164121 制造商:Microchip Technology Inc 功能描述:ICPICKIT2 PROGRAMMER/DEBUGGER ((NW))
DV164121+TEFLCST3 制造商:Microchip Technology Inc 功能描述:KIT PICKIT2+FLOWCODE-HOME BUNDLE 制造商:Microchip Technology Inc 功能描述:ICD, PICKIT 2, FLOW CODE, PIC, DSPIC 制造商:Microchip Technology Inc 功能描述:ICD, PICKIT 2, DEBUG EXP, FLOW CODE, PIC, DSPIC; Silicon Family Name:PIC12F6xx, PIC16F5xx; Core Architecture:PIC; Core Sub-Architecture:PIC12, PIC18, PIC24; IC Product Type:Debugger / Programmer; Series:PICkit 2 ;RoHS Compliant: Yes
DV164122 功能描述:界面开发工具 PICkit Ser Analyzer RoHS:否 制造商:Bourns 产品:Evaluation Boards 类型:RS-485 工具用于评估:ADM3485E 接口类型:RS-485 工作电源电压:3.3 V
DV164126 功能描述:开发板和工具包 - PIC / DSPIC USB Kit w/ PICkit LowPinCount RoHS:否 制造商:Microchip Technology 产品:Starter Kits 工具用于评估:chipKIT 核心:Uno32 接口类型: 工作电源电压: