16f684 Porta.2 Instability


Closed Thread
Results 1 to 11 of 11
  1. #1
    JDM160's Avatar
    JDM160 Guest

    Default 16f684 Porta.2 Instability

    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!

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    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.

    --------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Add
    Code:
    CMCON0 = 7
    (see datasheet)
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  4. #4
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    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

  5. #5
    JDM160's Avatar
    JDM160 Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by paul borgmeier
    Add
    Code:
    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.

  6. #6
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    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 ...
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  7. #7
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    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

  8. #8
    JDM160's Avatar
    JDM160 Guest


    Did you find this post helpful? Yes | No

    Unhappy

    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
    Last edited by JDM160; - 4th November 2006 at 03:27.

  9. #9
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default weak pull ups

    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

  10. #10
    JDM160's Avatar
    JDM160 Guest


    Did you find this post helpful? Yes | No

    Default

    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

  11. #11
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    One more reason why you always should post your whole code first
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. 16F684 Basic Functionality
    By munromh in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 30th September 2009, 20:28
  2. 16F684 and RA2
    By GoldStar in forum General
    Replies: 1
    Last Post: - 21st May 2009, 07:29
  3. ICSP and 16F684
    By onaclov2000 in forum Schematics
    Replies: 4
    Last Post: - 5th March 2009, 17:31
  4. help with HPWM on 16f684
    By kimvellore in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 23rd May 2006, 08:05
  5. Help Quick Need to make code smaller
    By Programmednew in forum mel PIC BASIC Pro
    Replies: 41
    Last Post: - 25th January 2005, 03:46

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts