PDA

View Full Version : 16f684 Porta.2 Instability



JDM160
- 22nd October 2006, 06:15
I'm having a problem with PORTA.2 on a 16F684. Even though I have disabled all external interrupts and set everything to digital I/O, I can not run portA.2 as an I/O port. As a matter of fact, any change in voltage on that pin causes erratic behavior and an apparent "reset" of the chip. By change in voltage, I mean as little as touching the pin. I can only get the chip to run stable if I tie that pin to Vdd with a resistor.

Here are my program configs:

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
include "modedefs.bas"

DEFINE OSC 4

OSCCON = %01010000 '2 Mhz

ANSEL = %00000000 ' all digital I/O

TRISA = %11111111 ' input pins
TRISC = %11011111 ' input pins except pwm port

T2CON = %00000110 ' enable timer 2 for PWM and set prescaler to 16

CCPR1L = %00000000 'zero duty cycle
CCP1CON = %00001100 'enable PWM, active high

PR2 = 24 '0-100 duty cycle
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Have i missed a necessary configuration that will disable any peripheral components that can cause this instability? Thanks in advance!

sayzer
- 22nd October 2006, 09:25
Hi JDM160,

Couple of things.

1. Your DEFINE is 4 MHz but you set your PIC to 2 MHz. You are telling Complier that you are going to use 4Mhz operation, but the PIC will be running at 2 Mhz.

2. Separately from Item 1 above, check your OSCCON.0 (bit0).
OSCCON.0=1, Internal oscillator is used for system clock.
OSCCON.0=0, Clock source defined by FOSC<2:0> of the CONFIG register.

--------------------------

paul borgmeier
- 22nd October 2006, 09:38
Add

CMCON0 = 7
(see datasheet)

BobK
- 22nd October 2006, 15:16
Hi JDM,

Your last sentence of the first paragraph-"I can only get the chip to run stable if I tie that pin to Vdd with a resistor."

If the pins are inputs you must pull them either hi or lo. You just can't leave them hanging there!

BobK

JDM160
- 23rd October 2006, 03:26
Add

CMCON0 = 7
(see datasheet)

Isn't that the same as CMCON0 = %00000000, and isn't that the power up default values anyway? If you haven't noticed, I'm new at this :-) Thanks for any help.

About the clock issues, PBPs smallest value is 4mhz for the compiler. I have no choice on that one. The only impact for my program is my pause statements.

Also, I am setting the intoscio in the fuse configuration.

As far as having to tie inputs to ground or vdd, why is it only pin PORTA.2 that is giving me trouble?

I have a feeling it has to do with the external interrupt function on that pin, but it should be disabled by default no?

Thanks again all, your help is much appreciated.

paul borgmeier
- 23rd October 2006, 06:33
CMCON0 = 0 ' Default (with most of PORTA = Analog)
CMCON0=7 ' all digital (or CMCON0 = %00000111)
Again, see datasheet (PORTA section, first highlighted box)
Let us know ...

BobK
- 23rd October 2006, 12:48
Hi JDM,

It's your comments like "I can only get the chip to run stable if I tie that pin to Vdd with a resistor" that caused me to send you this comment. You give us clues to the mystery and it's up to us to guess what is going on. If you read enough posts on this forum you will see that many times the people on this forum ask for complete code listings and schematics to help us out.

Now you write "As far as having to tie inputs to ground or vdd, why is it only pin PORTA.2 that is giving me trouble?" I don't know what you have actually connected to your PIC. You are only talking about PortA.2. So when you comment about putting your finger on a pin or put a resistor to Vdd then the problem goes away, what do you think the response from us should be? You have gotten some good feedback from Paul, Sayzer, and myself as to the more common problems people have encountered with the types of comments you have made. Now it's your turn to help us out some more with a drawing of what you have going so we can help you more!

BobK

JDM160
- 3rd November 2006, 22:19
I am still having problems with my program. If I don't tie my inputs to ground, my program wont run properly! The problem is that I'm trying to sense a ground or "low" condition at that pin and using internal pullups.

My basic circuit is as follows: I am running 4 LEDs off of PORTC through NPN transistors. I am also running a PWM output.

I have 3 digital inputs that read a switch state as on or off. Pins are tied to ground through a 10k resistor. Press switch 1 on input 1 and LED1 on output 1 goes on (input pin drivin to +5V when switch closed). Nothing fancy, very simple logic.

My problem lies when I enable an input that is normally "high" through the weak pullups. The program does not run at all. If I configure that pin as an output, program runs fine.... There is no routines in the code that reference that pin either! So I'm pretty sure it's not my code...

What am I missing!!!

Here is my configuration:

OSCCON = %01100001 '4 Mhz
INTCON = %00000000 'disable interrupts
PIE1 = %00000000
CMCON0 = %00000111
ANSEL = %00000000 ' all digital I/O
TRISA = %11111111 ' input pins
TRISC = %11011111 ' input pins except pwm port
IOCA = %00000000

T2CON = %00000100 ' enable timer 2 for PWM and set prescaler to 0

CCPR1L = %00000000 'zero duty cycle
CCP1CON = %00001100 'enable PWM, active high

PR2 = 24 '0-100 duty cycle

Archangel
- 4th November 2006, 06:05
Hi JDM160,
I have never used weak pull ups before, however; I do not see in you code where you enabled them. If I understand the data sheet correctly, and it is very possible I do not . . . WPUA=%00110111 should enable them on portA 0,1,2,4,5. with A3 configured automaticly if used as mclr and not available if configured as an I/O. The data sheet says weak pullups are disabled after power on reset.page 32.

Joe

JDM160
- 5th November 2006, 02:02
Thank you everyone for trying to help me with my "problems." It turns out all my problems were due to a simple "while" statement. I'll be the first to admit it... I'm a moron.

Thank you so much for your help! Till next time LOL

mister_e
- 5th November 2006, 02:38
One more reason why you always should post your whole code first ;)