PDA

View Full Version : 12F629 Wakes only once



jderson
- 27th August 2008, 04:14
I thought I understood this interrupt thing, but NO! The following program will wake from SLEEP with GPIO.2 going high the first time, but not with subsequent highs. What am I doing wrong? (The last three lines never get executed.) Thank you for any help.

CMCON = 7
TRISIO = %001100
OPTION_REG = %01000000
GPIO = 0
T1CON = 0
@ DEVICE MCLR_OFF, INTRC_OSC_NOCLKOUT, WDT_OFF, BOD_OFF, PWRT_ON, PROTECT_ON

'GPIO.0 =
'GPIO.1 = LED HIGH OUT
'GPIO.2 = SWITCH HIGH INPUT
'GPIO.3 = MCLR TIED HIGH
'GPIO.4 =
'GPIO.5 =

Main:

HIGH GPIO.1
PAUSE 1000
LOW GPIO.1

INTCON.1 = 0
INTCON.4 = 1
FLAGS = 0
@ SLEEP
@ NOP

INTCON.1 = 0
HIGH GPIO.1
PAUSE 100
LOW GPIO.1

INTCON.1 = 0
INTCON.4 = 1
FLAGS = 0
@ SLEEP
@ NOP
HIGH GPIO.1
PAUSE 1000
END

languer
- 27th August 2008, 07:08
I believe you may have a mismatch condition on the ports.

Try changing the following:

INTCON.1 = 0
HIGH GPIO.1
PAUSE 100
LOW GPIO.1
to:

temp = GPIO.2'read to dummy variable to clear mismatch condition of port (see s3.2.2 of datasheet)
INTCON.1 = 0
HIGH GPIO.1
PAUSE 100
LOW GPIO.1

jderson
- 27th August 2008, 14:05
Hi Languer- Thanks for trying, but no cigar! Adding the line you suggested resulted in a syntax error, so I added INTCON.0 = 0 instead (To clear GPIF). I get the same result. Strange.

Pic2008
- 27th August 2008, 14:22
Please put a pull down resistor 10K to GND from GPIO.2

jderson
- 27th August 2008, 15:02
I currently have a 3k resistor there.

Bruce
- 27th August 2008, 15:34
Place GOTO Main after your last PAUSE 1000. You should see a quick 100mS pulse on the
LED after the 1st wake-up, and a 2 second LED on time after the 2nd wake-up.

Using the internal oscillator you might also want to include DEFINE OSCCAL_1K 1 to make
sure it's calibrated.

jderson
- 27th August 2008, 15:49
Sorry Bruce, I made both changes, and the results are the same. I get one long pulse on the LED, LED goes off until button is pressed, then short pulse and then off again. Next press of button does nothing.

Bruce
- 27th August 2008, 16:02
Strange. This works precisely as expected. No matter how many times I press/release the
switch.


@ DEVICE MCLR_OFF, INTRC_OSC_NOCLKOUT, WDT_OFF, BOD_OFF, PWRT_ON, PROTECT_OFF
DEFINE OSCCAL_1K 1

CMCON = 7
TRISIO = %001100
OPTION_REG = %01000000
GPIO = 0
T1CON = 0

'GPIO.0 =
'GPIO.1 = LED HIGH OUT
'GPIO.2 = SWITCH HIGH INPUT
'GPIO.3 = MCLR TIED HIGH
'GPIO.4 =
'GPIO.5 =

Main:
HIGH GPIO.1
PAUSE 1000
LOW GPIO.1

INTCON.1 = 0
INTCON.4 = 1
FLAGS = 0
@ SLEEP
@ NOP

INTCON.1 = 0
HIGH GPIO.1
PAUSE 100
LOW GPIO.1

INTCON.1 = 0
INTCON.4 = 1
FLAGS = 0
@ SLEEP
@ NOP
HIGH GPIO.1
PAUSE 1000
GOTO Main

END
10K pull-down to ground on GPIO.2 with switch pulling it to Vcc on press.

jderson
- 27th August 2008, 16:11
Strange indeed. I programmed my part with your program using cut & paste, and my results are the same as they were, no second operation! It must be some sort of hardware anomaly. I will chase it with my scope later.

Bruce
- 27th August 2008, 16:39
Try setting bit 7 in OPTION_REG to disable internal pull-ups. WPU powers-up with all internal
pull-ups enabled, and with OPTION_REG = %01000000 you'll have internal pull-ups ON.

I suspect it works on mine due to a slight difference in the internal pull-up. That should cure
it unless you have a problem with your switch circuit.

nomad
- 27th August 2008, 19:43
trying to use "temp = GPIO.2" without declaring the temp variable is probably your syntax error.

"temp var byte" (word whatever) near/at the beginning would solve that.

jderson
- 27th August 2008, 19:59
Thanks for your help, guys! OPTION_REG = %1100000 solves the problem. But why does it work the first time, and not the second time????

Pic2008
- 28th August 2008, 03:23
Sounds weird to me, have you tried using another chip, is it the same result too?

jderson
- 28th August 2008, 04:45
Mystery solved: My homemade development board has 3 other PIC sockets, 2 of which are occupied with 2 different PICs, running different programs. All of these parts share the same switch. This switch has a 5K resistor to ground, and pulls to +5V. The 16F688 has it's external interrupt pin connected to the switch, and also had it's internal pullups enabled. With only the 12F629 attached (internal pullups enabled), the voltage on the INT pins was +1V. With both PICS attached, the voltage rises to +2V. The external interrupt pins are Schmitt trigger inputs. The data sheet says the minimum voltage for "a 1, or a high" is 0.8V.
So the 12F629 was seeing a high when it should have been a low. I have the software set to trigger on the rising edge of the switch, so it went HIGHER, LOWER, and then HIGHER. With both PICS having their internal pullups disabled, the voltage is now +2mv, and all is well. So much for "weak" pullups! As usual, I learned a lesson. Thanks to everyone for your help.

Pic2008
- 28th August 2008, 13:02
You're welcome. Glad that your problem is finally solved.