PDA

View Full Version : 16F688 wake with comparators and internal Vref



gmglickman
- 15th October 2013, 17:00
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:


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

gmglickman
- 15th October 2013, 18:00
Found it. Neglected to set PIE1.C2IE to enable.