Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Comparator with internal reference voltage?

Status
Not open for further replies.

poojarai

Newbie level 6
Joined
Dec 26, 2010
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,342
Hi,
Can any one please help me to setup comparator in 16F886.I dont know why code is not working for internal reference.I alway get C1OUTas low. I used A0=negative anaolg ip and A2=internal voltage for comparator1.i think problem is in CR1(CM1CON0) ,when i make it 0 and connect A3= as +ve analog ip ,it works properly .Is there any problem in my code or something else.here is my code.


/*
IC -16F886
Complier version-9.71a
*/

#include "htc.h"
#define _XTAL_FREQ 4000000
__CONFIG(XT & WDTDIS & LVPDIS & DEBUGEN & IESODIS & BORDIS & MCLREN& PWRTDIS &UNPROTECT& LVPDIS & FCMDIS );
volatile unsigned int a=0;

void main(void)
{
PORTA=0x00; //clear all
ANSEL=0xFF;
TRISA=0b00001111; //set pin0 to pin3 as input
PORTB=0x00; //clear all
ANSELH=0x00;
//******************************************************************
/*1(VREN)=CVREF circuit powered on
1(VROE)=CVREF voltage level is also output on the RA2/AN2/VREF-/CVREF/C2IN+ pin
0(VRR)= High range
0(VRSS)=Comparator Reference Source =VDD - VSS
0001(VR<3:0>)=CVREF Value Selection 0 ≤ VR<3:0> ≤ 15
When VRR = 1: CVREF = (VR<3:0>/24) * VDD
When VRR = 0: CVREF = VDD/4 + (VR<3:0>/32) * VDD */

VRCON = 0b11100001; // Set voltage reference register
//*************************************************************
/*1(C1ON)=Comparator C1 is enabled
0(C1OUT)=noninverted out
1(C1OE)=C1OUT is present on the C1OUT pin
0(C1POL)=C1OUT logic is not inverted
0=Unimplemented
1(C1R)=C1VIN+ connects to C1VREF output
00(C1CH<1:0>)=C12IN0- pin of C1 connects to C1VIN- */
CM1CON0 = 0b10100100;
//**************************************************************
__delay_ms(2); // delay for 2 milliseconds
while(1)
{
if(C1OUT==1)
{
a++;
}
else
{
a=0;
}
}
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top