Inputs are "sinking" voltages?


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2007
    Posts
    67

    Default Inputs are "sinking" voltages?

    Hey all - I'm moving right along figuring this stuff out thanks to all your help but I hit another unknown today.

    I set a pin as an input, but when I feed it an input (say a +5v square wave pulse) it is "sinking" it. I view it with the scope and it just reads ground, but if I break the connection to the pin on the PIC, the line is showing the square wave. Touch the PIC pin again and it goes flat again on the scope.

    The pin I'm using is RA1 on a 16F688. I was originally trying to use RA2, saw this problem, then saw in the data sheet in the pinout description that RA2 is listed as a schmitt trigger, and not TTL. So I tried to use RA1 instead as it is specifically listed as a TTL input.

    I've also tried running a simple code to toggle a probe pin up and down and that's not working either - as if for some reason that pin just won't see my input at all.

    Here is my code:

    Code:
    define OSC 20             'Set PBP Osc clock to 20Mhz
    TRISA = 1                   'All A port I/O's as inputs
    ANSEL = %00000000     'Turn off analog input for ports, set digital I/O
    CMCON0 = %00000111   'Turn off comparators (CMCON0.0:2 = 111)
    TRISC = 0           'All C port I/O's as outputs
    
    mysignal VAR PORTA.1     'signal on RA1
    
    probe VAR PORTC.3         'o-scope probe RC3 
    LOW probe
    
    mainloop:
      if mysignal = 1 THEN
        HIGH probe
        ENDIF
      IF mysignal = 0 THEN
        LOW probe
        ENDIF
      GOTO mainloop
    END

    This same sort of example has seemed to work on other PIC's but it just won't work here. I'm confused and assuming there is some additional register I need to configure that I'm missing.

    Thanks!
    Last edited by kevj; - 6th September 2007 at 10:02.

  2. #2
    sinoteq's Avatar
    sinoteq Guest


    Did you find this post helpful? Yes | No

    Default Binary math

    Your A.1 in-port is not set as input. You use PortA.1 right?? Look at this:

    TRISA=%00000 'This is all A-pins to output == Decimal 0
    TRISA=%00001 This makes A.0 an INPUT == Decimal 1
    TRISA=%00010' This will make A.1 an INPUT == Decimal 2
    TRISA=%11111 'All input== Decimal 31


    Get the point?

    Sometimes it is better to use Binary when setting the registers because then you "see" the number better when you compare with the datasheet.

    M
    Last edited by sinoteq; - 6th September 2007 at 10:27.

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    No ANSEL on this chip. The ADC is controlled with ADCON0.

    ADCON0=7 ' NO ANALOG
    Dave
    Always wear safety glasses while programming.

  4. #4
    sinoteq's Avatar
    sinoteq Guest


    Did you find this post helpful? Yes | No

    Default 16f688??

    The code is for 16F688 right? Then ANSEL is the way to go and no other way.
    Datasheet page 36
    M

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    My mistake Been a long night.
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Aug 2007
    Posts
    67


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sinoteq View Post
    Your A.1 in-port is not set as input. You use PortA.1 right?? Look at this:

    TRISA=%00000 'This is all A-pins to output == Decimal 0
    TRISA=%00001 This makes A.0 an INPUT == Decimal 1
    TRISA=%00010' This will make A.1 an INPUT == Decimal 2
    TRISA=%11111 'All input== Decimal 31
    Doh! Yes, I think I see it now. In my mind I was thinking just assigning dec 1 would make all the registers 1 - a short way of saying %11111111 which is of course not correct.

    I get it now. Knew it had to be some silly oversight like that.


    Quote Originally Posted by sinoteq View Post
    The code is for 16F688 right? Then ANSEL is the way to go and no other way.
    Datasheet page 36
    M
    So then my code on the ANSEL is correct?

    Code:
    ANSEL = %00000000     'Turn off analog input for ports, set digital I/O
    I thought that was pretty self explanatory in the data sheet but I could still have it wrong.

    Thank you!

Similar Threads

  1. decoding quadrature encoders
    By ice in forum mel PIC BASIC Pro
    Replies: 93
    Last Post: - 28th February 2017, 09:02
  2. Erratic analog inputs .
    By timseven in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 10th October 2009, 22:34
  3. Unable to get 2 inputs to work
    By rangerdoc in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 1st June 2008, 03:16
  4. inputs on 12F675 (or for that matter any PIC)
    By muddy0409 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th April 2007, 19:43
  5. Using portb as inputs PIC goes crazy
    By peterdeco1 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 14th November 2005, 14:15

Members who have read this thread : 0

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