PDA

View Full Version : Instability with the 12F629



BGreen
- 11th November 2004, 00:08
I am very much a newby to these.

Below is the code that I write originally my input was pin 7, but for some reason I could not get it to triger with a switch. The intent is to give the input pin a high by using a momentary switch, which will cause pin 6 to go hi for 2 seconds, then pin 5 for 2 seconds, the timeout for 3 seconds and then wait for another trigger event. When my hand gets near the switch which triggers pin 3, it triggers. If I get near it it tends to do the same. Any quips of wisdom would be appriciated.

Butch

SEN VAR GPIO.4
POW VAR GPIO.1
SHT VAR GPIO.2
LOW SEN
LOW POW
LOW SHT
INPUT SEN
OUTPUT POW
OUTPUT SHT
LOOP:
IF SEN=1 THEN
HIGH POW
PAUSE 2000
LOW POW
HIGH SHT
PAUSE 2000
LOW SHT
PAUSE 3000
ENDIF
GOTO LOOP

Archilochus
- 11th November 2004, 00:29
That you HH?
Have not used used any of the 12 series yet - but you might want to post some of your code that shows your 'configuration' settings.

BGreen
- 11th November 2004, 00:34
Yep Arch, its me. Hey, I said I'm a newby, that IS all my code.
Good to see ya

thelightbrain
- 11th November 2004, 00:38
The input pin that you are connecting the switch to should also be connected to ground via a 5K or 10K resistor. This will keep it from "floating".

Or, to avoid adding another component, you can enable the internal "weak pullups" and connect the switch to ground. And change the input polling code to:

IF SEN=0 THEN

Also vave to make sure the input your using has the weak pullup.

--Jim

BGreen
- 11th November 2004, 00:44
Thanks Jim, I'll give that a try.

Archilochus
- 11th November 2004, 01:26
Hey Butch - good to see ya starting on the programming - stuffs almost as addictive as the cams !!

Was just looking over the 12F629 data sheet and it looks like it has lots of functions like comparators, A/D inputs, and such.

There will be a bunch of registers like INTCON and OPTION_REG that are pre-set by PBP - you'll sometimes need to set them up manually in order to make sure all your pins are functioning as digital In/Outs, etc (unless you want the analog stuff).
Caused some headaches for me on the 16F628's until I figgured it out (Brian helped out a lot!).
Don't know what the PBP presets are for the 12F629.

You might want to use the GPIO.2 'external interrupt' pin as your sensor input and assign weak pullups and trigger on falling edge (see INTCON and OPTION registers in data sheet).

I think the "ON INTERRUPT" command could then be used while you put the chip to sleep (not sure on the '629).

Arch

BGreen
- 11th November 2004, 03:01
It can Arch. Was on Yahoo with Stevo and figured out there is even more I need to learn. Thanks for the input

mister_e
- 11th November 2004, 05:55
PIC12F629 have internal comparator

to turn them of

CMCON=7

here a link for some specific setting on some PIC

http://www.melabs.com/support/mcu_hints.htm

regards

Dwayne
- 11th November 2004, 15:00
Hello BGreen,

BG>>When my hand gets near the switch which triggers pin 3, it triggers. If I get near it it tends to do the same. Any quips of wisdom would be appriciated.<<

When you program the chip, Make sure your MCLR is set to input pin. If not, your body can difinitely turn this chip on and off. I ran into this just by touching things, and finally realized the Mclr was set to reset. You can pull it high if you don't want to set it as a input, and accomplish the same thing.

Dwayne

BGreen
- 11th November 2004, 20:14
Folks, thanks for the help. I used a 4.7k resister from the switch to ground and its solid as a rock. I had already put a pullup on pin 4. Jig I built is working fine. Now I need to learn the right way to do stuff, and how to use the sleep and interupts.