|
|
View previous topic :: View next topic |
Author |
Message |
spero Guest
|
10F206 comparator with int voltage reference not working?? |
Posted: Thu Sep 22, 2005 12:23 pm |
|
|
Has anyone successfully used the 10F206 comparator using the internal voltage reference (0.6V) as the negative reference for the comparator? I cannot get the comparator to change the CMPOUT bit to 0.
I'm trying to implement a cheap and nasty battery low detect as follows;
When the battery falls to its cutoff level, a resistive potential divider will present 0.6V at the CIN+ pin (GP0). The negative reference of the comparator is setup to use the internal voltage reference.
My code to setup and read the comparator output bit is as follows;
-----------------------------------------
#bit CMPOUT = 0x07.7
#bit CMPON = 0x07.3
#asm // Setup and enable comparator - load CMCON0 reg
movlw 0xFB
movwf 0x07
#endasm
delay_us(1); // Let comparator stabilise before reading
if(CMPOUT == 0)
bat_low = TRUE; // If Vin+ < Vin- then set flag
output_high(PIN_B2);
CMPON = 0; // Disable comparator before going to sleep
set_tris_b(0x09); // Set TRIS again after comparator has fiddled with them...
sleep();
--------------------------------------------------
Cheers,
Spero. |
|
|
mcafzap
Joined: 07 Sep 2003 Posts: 46 Location: Manchester, UK
|
|
Posted: Fri Sep 23, 2005 6:23 am |
|
|
Quote: | Has anyone successfully used the 10F206 comparator using the internal voltage reference (0.6V) as the negative reference for the comparator? |
Without referring to the datasheet, here is a section of my code, where I set the comparator voltage to about half rail. I also put the thing to sleep to save power - hence no 'While (1)'.
Code: |
#byte CMCON0 = 0x07
#bit GP0= GPIO.0 //comparator input
#bit CMPOUT = CMCON0.7
#bit CMPON = CMCON0.3
void main() {
#asm
movlw 0x09 //Bits 0 & 3 inputs
TRIS GPIO
// Disable wake-up on pin change, enable weak pull-ups,
// Timer0 source internal, L to H
// Prescaler to WDT, max division 2304mS
movlw 0x8F
OPTION
#endasm
// no comparator output,
CMCON0 = 0x73;
nofield = 0;
alert_on = 0;
sleepcount=0;
}
// while (1) {
CMPON = 1; // Turn on Comparator
if (CMPOUT){ // Triggered
CMPON = 0;
etc. |
|
|
|
Guest
|
|
Posted: Fri Sep 23, 2005 8:37 am |
|
|
Thanks...I found my problem; I had a == instead of a = and my flag was never being set, so the comaparator was working all the time! |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|