# Circuit only works when touching pic (ADC)

#### Alromaru

Joined Dec 10, 2017
4
I made a circuit on a pic16f887 where I read an analog input and get a digital output in PORTD with leds. The problem is the circuit doesn't work at all, unless i am touching the top of the pic. can someone tell me what's going on and what can I do to fix this? Thanks in advance.

Concerning the circuit, I'm connecting a voltage divider with a pot to AN0 and connecting both Vdd and Vss in the pic and the PORTD output to leds and resistors.

this is my code:
Code:
LIST P=16F877A
include "p16f887.inc"

; CONFIG1
; __config 0xF0D5
__CONFIG _CONFIG1, _FOSC_INTRC_CLKOUT & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _IESO_OFF & _FCMEN_OFF & _LVP_ON
; CONFIG2
; __config 0xFFFF
__CONFIG _CONFIG2, _BOR4V_BOR40V & _WRT_OFF

ORG 0X00
BANKSEL TRISD
CLRF TRISD        ;SETS PORTD AS OUTPUT
BANKSEL PORTD
CLRF PORTD        ;SETS PORTD TO LOW

;PORT CONFIG
BANKSEL TRISA
BCF TRISA          ;Set RA0 to input
BANKSEL ANSEL
MOVLW B'00000000'     ;LEFT JUST, VREF VDD VSS
;CHANNEL SELECTION/CONVERSION CLOCK
MOVLW B'11000001'    ;Fosc, AN0, ADC ENABLED
BTFSC ADCON0,1        ;SALTA SI BIT 1 ES CERO
MOVWF PORTD;
END

Last edited:

#### LesJones

Joined Jan 8, 2017
2,638
He's using a PIC16F887 not a PIC16F877. I was that the chip was possibly not making a good connection with the socket.

Les.

#### Alromaru

Joined Dec 10, 2017
4
_FOSC_INTRC_CLKOUT Hows that work there has to be a crystal on a 16F877A
What crystal do you have ?
That code will not work at all you got it for the wrong chip
]
My bad, I didn't notice that, thanks!! I changed the that part of the code, but I still have the same problem.

Code:
LIST P=16F887
include "p16f887.inc"

; CONFIG1
; __config 0xF0D5
__CONFIG _CONFIG1, _FOSC_INTRC_CLKOUT & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _IESO_OFF & _FCMEN_OFF & _LVP_ON
; CONFIG2
; __config 0xFFFF
__CONFIG _CONFIG2, _BOR4V_BOR40V & _WRT_OFF

#### spinnaker

Joined Oct 29, 2009
7,835

2. How is your pic connected? PCB? Perfboard? Breadboard? Zif socket ? Regular socket? SMD mouunted?

#### Alromaru

Joined Dec 10, 2017
4
He's using a PIC16F887 not a PIC16F877. I was that the chip was possibly not making a good connection with the socket.

Les.
It's well connected, because it only works when I touch it with my fingers,not with some plastic. I was thinking maybe it has something to do with grounding. I now got it to work by touching some of the PORTA pins. do I have to ground all PORTA pins even though not used in the code??

#### spinnaker

Joined Oct 29, 2009
7,835
What does "not working at all" mean? Is the Pic running?

#### spinnaker

Joined Oct 29, 2009
7,835
I have to ground all PORTA pins even though not used in the code??
What does your datasheet say? This is what mine says for the current pic I am working on.

Unused I/O pins should be configured as outputs and
driven to a logic low state. Alternatively, connect a 1 kΩ
to 10 kΩ resistor to VSS on unused pins and drive the
output to logic low.

#### spinnaker

Joined Oct 29, 2009
7,835
It's well connected, because it only works when I touch it with my fingers,not with some plastic.
If you need to touch it to get it to work, t is a design issue or connection issue. Possible you might be a bad chip but unlikely. I would still like to know what "does not work" means.

#### AlbertHall

Joined Jun 4, 2014
9,826
If it only runs with your finger on the chip my first thought would be that the oscillator is not running. From the config bits you are using the internal oscillator. Please make sure which chip is actually in your circuit.
PIC16F887 has an internal oscillator.
PIC16F877 does not have an internal oscillator.

#### spinnaker

Joined Oct 29, 2009
7,835
If it only runs with your finger on the chip my first thought would be that the oscillator is not running. From the config bits you are using the internal oscillator. Please make sure which chip is actually in your circuit.
PIC16F887 has an internal oscillator.
PIC16F877 does not have an internal oscillator.
We don't know if the chip is running of not. All we know is "circuit doesn't work at all". That can mean anything. I don't see how a chip with no internal OSC could be caused to work if you touch it. Chip has to have an internal OSC.

#### be80be

Joined Jul 5, 2008
2,042
He's using a PIC16F887 not a PIC16F877. I was that the chip was possibly not making a good connection with the socket.

Les.
Read the top of his code it said list 16f877a

I kind of went with the list seeing it was at the top of his code but
yes a 16f887 has one inosc code still wouldn't work as posted for that chip too

#### AlbertHall

Joined Jun 4, 2014
9,826
We don't know if the chip is running of not. All we know is "circuit doesn't work at all". That can mean anything. I don't see how a chip with no internal OSC could be caused to work if you touch it. Chip has to have an internal OSC.
If the chip has no internal oscillator and the oscillator pins are not connected then they may pick up enough AC from the finger to drive the chip with some sort of clock signal.

There is clearly some confusion about the chip number so it makes sense to confirm what the chip number actually is.
Those two numbers are easily confused.

#### Alromaru

Joined Dec 10, 2017
4

2. How is your pic connected? PCB? Perfboard? Breadboard? Zif socket ? Regular socket? SMD mouunted?
What does "not working at all" mean? Is the Pic running?
What I meant is i don't get any output in PORTD to light the LEDs.
If you need to touch it to get it to work, t is a design issue or connection issue. Possible you might be a bad chip but unlikely. I would still like to know what "does not work" means.
I got it to work now by grounding pin 36 (RB3/AN9/PGM/C12IN2-). My question now would be, why this specific pin? How can i know which pins are required to be grounded.
If it only runs with your finger on the chip my first thought would be that the oscillator is not running. From the config bits you are using the internal oscillator. Please make sure which chip is actually in your circuit.
PIC16F887 has an internal oscillator.
PIC16F877 does not have an internal oscillator.
I'm using a PIC16F887 and now get a reading of 1MHz.

#### spinnaker

Joined Oct 29, 2009
7,835
I got it to work now by grounding pin 36 (RB3/AN9/PGM/C12IN2-). My question now would be, why this specific pin? How can i know which pins are required to be grounded.
Read your datasheet. My guess when you grounded the pin you indirectly fixed something else that was actually wrong.

Just to clarify. It was running but the code was just not working the way you expected?? Did you use your debugger to figure out exactly what was wrong?

#### philba

Joined Aug 17, 2017
960
It's been a while since I've done PICs - does_MCLRE_OFF in CONFIG1 default to a 0 or 1? If the pin is config'd as MCLR then it shouldn't be flapping in the breeze. The described behavior seems consistent with a floating MCLR pin. Either pull it high or confiure MCLR as internal. Page 210 of the datasheet.

#### AlbertHall

Joined Jun 4, 2014
9,826
MCLR_OFF means that the MCLR pin does not reset the PIC. It is free for use as a digital input to the PIC.