PDA

View Full Version : PIC12F675 not waking up



peterk
- 4th July 2004, 14:42
Hi,

New to the forum,

Melanie you may have already rxed a message.

I am trying to save power and 12f675 draws almost nothing when asleep.

Here the program

' GPIO.0 = Led Out
' GPIO.1 =
' GPIO.2 = Trigger In
' GPIO.3 =
' GPIO.4 = Osc
' GPIO.5 = Osc

DEFINE ONINT_USED 1
INTCON.3 = 1 ' Enable the port change interrupt
CMCON = 7 ' Disables Analog Inputs
ANSEL = 0 ' Sets Analog Inputs as Digital I/O

TRISIO = $FF ' All As Inputs

High GPIO.0
Pause 10
Low GPIO.0

On_Test: ' Wait for the interupt on GPIO.2, ie Rear Panel Switch

Pause 1
IF GPIO.2 = 0 Then
GoTo Awake
EndIf
INTCON.0 = 0 ' Clear the RB port change flag bit
Nap 7 ' Go to sleep. When the watchdog is
' disabled, NAP won't wake up until
' an interrupt occurs.

GoTo On_Test ' Do it again upon waking

Awake:

Low GPIO.0
Pause 10
High GPIO.0
Pause 10

GoTo Awake


All the progam does is wakes up, doesn't perform awake, then goes back to sleep. (I monitor the current consuption)

When I program the PIC I leave the watchdog off.

Thanks for any help

Peter

Melanie
- 4th July 2004, 17:15
Of course it's not waking up. By disabling the WatchDog Timer you've disabled NAP (read about how NAP works in the PBP manual).

peterk
- 5th July 2004, 00:07
OK, So why does this work for 16F628?

Melanie
- 5th July 2004, 01:46
Post the complete code for the 16F628 and when I've a free moment I'll look into it.

peterk
- 5th July 2004, 08:10
As follows;
' PicBasic Pro program to demonstrate wake on interrupt.

' You should DISABLE THE WATCHDOG TIMER when programming the
' PICmicro device.

' The program outputs the condition of the switches on the
' LEDs, then immediately goes into power-down mode. When
' the condition on any switch changes, the RB port change
' interrupt occurs, waking the part.
' Since the global interrupt enable bit is not set, no
' jump to the interrupt vector occurs. Program execution
' is resumed, the LEDs are updated, and the part goes back
' to sleep.
' To further reduce the power consumption, all unused
' hardware peripherals should be disabled. The PORTB
' pullups should be replaced with external resistors, and
' the internal pullups disabled.


' Define ONINT_USED to allow use of the boot loader.
' This will not affect normal program operation.
DEFINE ONINT_USED 1

' Define the pins that are connected to pushbuttons.
' The switches must be connected to PORTB, pins 4,5,6,
' or 7 in order to use the RB port change interrupt.
sw1 VAR PORTB.4

' Define the pins that are connected to LEDs
led1 VAR PORTB.0

INTCON.3 = 1 ' Enable the RB port change interrupt
OPTION_REG = $7f ' Enable PORTB pull-ups
TRISB = %11111000 ' Set PORTB.0-2 (LEDs) to output, 3-7 to input

main: ' main program begins here

PORTB = 0 ' Turn off all LEDs

' Check any button pressed to toggle on LED
IF sw1 = 0 Then
GoTo Start
EndIf
INTCON.0 = 0 ' Clear the RB port change flag bit

NAP 7 ' Go to sleep. When the watchdog is
' disabled, NAP won't wake up until
' an interrupt occurs.

GoTo main ' Do it again upon waking

Start:
' Rest of program

Thanks Mel

End

peterk
- 5th July 2004, 12:25
Got It Melanie !

I looked at some of your example programs and utilised the following;
' Test Program for 32 Khz
' Interupt to wake
' Works 5 Jun 04
' Pause 1 = 122.07 ms
' Pauseu 1 = 122.07 us
' GPIO.0 = Led Out
' GPIO.1 =
' GPIO.2 = Trigger In
' GPIO.3 =
' GPIO.4 = Osc
' GPIO.5 = Osc

DEFINE ONINT_USED 1
INTCON=%00010000 ' enable Interrupt
OPTION_REG.6=0 ' Trigger on Falling edge
CMCON = 7 ' Disables Analog Inputs
ANSEL = 0 ' Sets Analog Inputs as Digital I/O
TRISIO = $FF ' All As Inputs

High GPIO.0 ' Test Pulse
Pause 10
Low GPIO.0

On_Test: ' Wait for the interupt on GPIO.2, Low from Switch

IF GPIO.2 = 0 Then
GoTo Awake ' Wake Up And Exit
EndIf
INTCON.1=0 ' Reset Interrupt Flag

@ Sleep ' Go to @ sleep.

GoTo On_Test ' Do it again upon waking

Awake:

Low GPIO.0 ' FlashLED
Pause 1
High GPIO.0
Pause 1

IF GPIO.1 = 0 Then
Low GPIO.0 ' Turn LED Off
GoTo On_Test ' Wait for next interupt of Switch Low
EndIf

GoTo Awake ' Flash LED Continuosly

Thanks

Peter

Melanie
- 6th July 2004, 08:58
Just very quickly Peter, as I'm under serious pressure today... interrupts don't work the same way on the 12 series PICs as they do on the 16 series... read "Special Features of the CPU" interrupt section in the 12F's Datasheet. Your program may not be executing the way you think it is...

PS. Also the TRISIO for the output pin should be a '0' not a '1'.

peterk
- 6th July 2004, 11:21
hi Melanie,
Thanks for the info
will check out and let you know
peter