16F688 wake with comparators and internal Vref


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2009
    Posts
    22

    Default 16F688 wake with comparators and internal Vref

    I have a piezo disc w 1Meg in parallel to RC0 of 16F866. Working fine to detect vibration when configured as analog, using ADCIN.
    Now I want to wake the PIC from sleep when vibration is detected, when voltage on PORTC.0 exceeds, say, 0.2v (lowest available setting) using internal Vref. I'm using comparator 2, mode 010 with CIS and C2INV bits set. It sleeps, but never wakes.

    What am I missing? Relevant code:

    Code:
    OSCCON=%01100001 '4 mhz clock default 
    DEFINE OSC 4	'for sLCD   can change later
    DEFINE ADC_BITS 8
    DEFINE ADC_SAMPLEUS 50
    DEFINE ADC_CLOCK 3
    VRCON=0    'volt ref off      
    ANSEL=%00010000    'piezo input analog on AN4 RC0
    CMCON0=0          'comparators off, pins analog=0 (off/digital=7)
    INTCON=0         'interrupts disabled
    ' ------------ pins
    piezo    VAR	PORTC.0       
    LED		 VAR	PORTA.2        
    option_reg.7=0      'WPU ports A only  
    'WPUA =%00000000		'PUSHBUTTONS on port A later				
    TRISA=%00000000		'       
    TRISC=%00000001		'analog ch4 RC0 piezo
    PORTA=0 : PORTC=0
    '-------------- variables 
    i               var byte       
    temp            var BYTE
    piezo_analog    var byte
    version   CON 205
    CLEAR
    '-------------- code
    LED=1           'startup, power on
    read 0, temp
    if temp<>version then write 0, version	'save version to EEPROM 0
    pause 1000     'show power on LED
    LED=0
    CMCON0=%00101010    '
    VRCON=%10100001    'approx 0.2 volt Vref
    PAUSEUS 10         'allow Vref to settle
    INTCON.6=1          'PEIE for wake
    PIR1.4=0            'clear flag
    'TRIS               'for lowest sleep power, later
    @ sleep                
    @ nop
    
    
      wake:                        'v205 sleeps but not waking
    CMCON0=0                'comparators off now
    PIR1.4=0                'clear  
    LED=1                  'show awake
    END

  2. #2
    Join Date
    Jan 2009
    Posts
    22


    Did you find this post helpful? Yes | No

    Default Re: 16F688 wake with comparators and internal Vref

    Found it. Neglected to set PIE1.C2IE to enable.

Similar Threads

  1. 16F688 Internal clock and MCLR
    By manxman in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 18th August 2007, 18:38
  2. Need help to shut off comparators for 16f688
    By jessey in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 30th October 2006, 04:54
  3. Need setting to turn off 16F688 comparators
    By Thomas Williams in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 22nd December 2005, 00:39
  4. switching external vref+ and vdd vref
    By alejandro_halon in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 16th February 2005, 20:13
  5. Internal Vref resolution
    By Warrier in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 10th December 2004, 22:05

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts