PDA

View Full Version : 16f1824 MCLR pin going low causes PIC to reset - what am I missing?



HankMcSpank
- 6th May 2012, 00:08
So I want to use pin 4 (RA3) as a switch input pin, I've enabled weak pullups...I measure 5V on there - all seems as it should, but whenever I press a switch (which ground the pin), the PIC resets (I have an Hserout command at the top of my code, so I see the word "reset" only if erhm,....the PIC has reset!)

So I have this as the config.....



@ __CONFIG _CONFIG1, _FCMEN_OFF & _FOSC_INTOSC & _WDTE_OFF & _MCLRE_OFF & _CP_ON & _IESO_OFF & _BOREN_OFF & _PWRTE_OFF
@ __CONFIG _CONFIG2, _PLLEN_OFF & _STVREN_OFF


I thought the bolded entry allowed me to use pin 4 (RA3) as a normal digital input.

Is there anything else I have to do to stop the PIC barfing just for grounding the MCLR pin?

ronjodu
- 6th May 2012, 00:40
That pic is new to me but it looks like you may also need to check the configuration word 1 bit 6.

rsocor01
- 6th May 2012, 03:15
Are you using an external pullup resistor for your switch configuration?

HankMcSpank
- 6th May 2012, 13:43
Are you using an external pullup resistor for your switch configuration?


no...if i'm reading the datasheet correctly, it is possible to use a weak pullup for that pin, which is what i've done...



OPTION_REG.7 = 0
WPUA = %00011000
IOCAN = %00011000

rsocor01
- 6th May 2012, 15:40
no...if i'm reading the datasheet correctly, it is possible to use a weak pullup for that pin, which is what i've done...



Hmmm, try using an external resistor (maybe 4.7K Ohms) and see if you have the same problem. You might be drawing too much current when closing the switch and that might be causing the problem.

HankMcSpank
- 6th May 2012, 16:43
just tried an external pullup resistor on RA3 (vs internal weak pullup)- same results.....if I ground RA3 (MCLR pin), the PIC resets

...aaaaaaarrrrgggHHHH

mister_e
- 6th May 2012, 17:07
Before programming your PIC, you've checked the configuration bits in your device programmer software and they match your code right?

Are you sure your programmer do it right?

HankMcSpank
- 6th May 2012, 17:21
If it helps, I'm using a Pickit2 programmer ...whilst I've been away from all of this for a while, I don't recall having to do anything special previously wrt the programmer when using RA3 as a digital input (albeit probably using a different chip).

Just moved the Sitch off RA3...to another input pin, device is not resetting now whe the switch is pressed, so it is definitely related to when RA3 goes low, the 16f1824 is resetting!

mister_e
- 6th May 2012, 17:25
post your .hex files here, just for double-checking purpose.

Are your compiling under MPLAB or MCS?

Still on PBP 2.60?

mackrackit
- 6th May 2012, 17:31
A shot in the dark, but what if you add
_LVP_OFF
to config_2

HankMcSpank
- 6th May 2012, 18:08
A shot in the dark, but what if you add
_LVP_OFF
to config_2

"A long shot....but it might just work" (as they say in the movies), and whaddayaknow.....

BINGO!

with _LVP_OFF ....no resetee, ....*but* without that _CONFIG2 entry, my 16f1824 resets every time RA3 goes low.


So Mr Mackrackit ...choose any cuddly toy from the top shelf!

How bizarre - many thanks, it would have taken me a few weeks to get that one! (& it's just come flooding back why I took a break from these puppies in the first place - ie. somtimes they're *way* obtuse!)


Thanks for *everyone's* input!

mister_e
- 7th May 2012, 13:30
One thing I may suggest... never under do the config fuse lines.... I mean, grab the whole list available in the .INC file and assign each of them, OFF or ON.

Dick Ivers
- 7th May 2012, 18:25
It's explained on the 16f1824 data sheet. See pages 52 and 54. LVP must be 0 for MCLR to turn off. LVP is set to 1 on any reset.