Well, that was interesting. I've never used ULPWU or PLVD yet, but I have used the 12F635
in a ton of applications.
Out of curiosity, I put this together to tinker with today, and it works just like the book says.
You'll probably want to experiment with the series resistor & cap value. As voltage drops, the
wake up frequency increases, so you'll need to find some happy medium there to work in your
own application. I used a 200ohm series resistor with 1kpF cap.
At 5 volts it wakes up around every 30mS, and trips PLVD at <= 4.0 V.Code:@ DEVICE PIC12F635,MCLR_OFF,INTRC_OSC_NOCLKOUT,WDT_OFF,BOD_OFF @ DEVICE PWRT_ON,FCMEN_OFF,IESO_OFF,WUREN_OFF,PROTECT_OFF SYMBOL PROBE = GPIO.1 ' scope probe indicates wakeup from sleep SYMBOL PLVD_LED = GPIO.2 OSCCON = %01100000 ' Internal 4MHz select OPTION_REG = 128 ' internal pull-ups off CMCON0 = 7 ' disable comparator VRCON = 0 ' disable internal Vref GPIO = %00000000 ' LED off on boot TRISIO = %00000001 ' GPIO.0 = input, rest outputs PIR1 = 0 ' clear peripheral int flags PCON.5 = 1 ' ultra low power wakeup enabled Main: GPIO.0 = 1 ' set data latch on GPIO.0 TRISIO.0 = 0 ' GPIO.0 = output (charging cap) PAUSEUS 24 ' charge cap for 24uS TRISIO.0 = 1 ' GPIO.0 = input to discharge cap IOCA.0 = 1 ' int on change enabled for GPIO.0 INTCON = %00001000 ' global ints disabled, int on change enabled @ SLEEP ' put PIC to sleep TOGGLE PROBE ' indicate ULPWU wake up from sleep & clear mismatch INTCON.0 = 0 ' clear wake up on change int flag GOSUB TestVolts ' go test for under voltage condition GOTO Main ' not sure what this does...;o} TestVolts: INTCON.6 = 1 ' peripheral ints enabled LVDCON = %00010101 ' enable PLVD. set trip point to 4.0V ' enable PLVD interrupt only when PLVD internal Vref is stable IF LVDCON.5 = 1 THEN PIE1.6 = 1 ' if stable, enable IF PIR1.6 = 1 THEN ' voltage <= 4.0V? HIGH PLVD_LED ' yes. indicate voltage is <= 4.0V PIR1.6 = 0 ' clear int flag ELSE LOW PLVD_LED ' else, indicate voltage is > 4.0V ENDIF LVDCON = 0 ' PLVD disabled before returning to sleep INTCON.6 = 0 ' peripheral ints disabled PIE1 = %00000000 ' low voltage detect int disabled RETURN END




Bookmarks