16F872 funny issue

Status
Not open for further replies.

lexter

New Member
Hi,

I've build a simple testing board (veroboard version), containing PIC16F872 and a couple of leds. The chip is porgrammed using ICD2 kind of programmer, but the issue is that it doesn't run the code, until I touch one of the OSC pins or ground.
I'm using 20Mhz crystal and 33pf caps. MCLR pin is pulled up with 10K resistor.

Has anybody seen anything like this before?
 
Using your ohm meter make sure all the GNDs are connected together. Bad solder joints.

Your crystal may be too far from the PIC.

Check to see if the wiring is right.

Post images of top and bottom of board.
 
Last edited:
You might try checking how my 16F876 tutorial board is conencted, it should be the same as the 872.
 
Hi.
Do you have a bypass cap across Vcc and ground close to the processor?
Is the crystal as close to the PIC as possible?
The 33 puff caps sound a little high. Try 12 to 22 puff.

Hope this helps.
kenjj
 
well, I have a bypass cap, being 100nf (perhaps too small ... )
crystal is really as close to the pins as possible (otherwise would overlap with pic itself ... damn veroboard ... )

I will perhaps try smaller caps for crystal, however I believe that according to the datasheet it shouldn't be a problem ... But I will try tomorrow anyhow.

There was a talk in the datasheet about Rs, being a series resistor between crystal and pic, could that help as well?

If nothing helps, I will post pictures of my "lovely" design ...

Thanks for helping!
 
I had that happen the first time I used and crystal I had the config set wrong I found out
after i changed it 3 times
 
Last edited:
Hi.
Actually, I go with what be80be says. Check your config settings for this. Try this before altering the hardware.

I have seen crystals in parallel with a 1 megOhm resistor, but never series. Could be series resistors are needed with certain crystal types. Can't say for sure. The 100nF cap sounds right.

Good luck!
kenjj
 
I have seen crystals in parallel with a 1 megOhm resistor, but never series. Could be series resistors are needed with certain crystal types. Can't say for sure.

In HS mode some crystals may require a series resistor to lower the power provided to them, a 20MHz crystal is obviously a very thin and fragile device.

Never found the need myself though, but it is covered in the PIC datasheet.
 
Wrong config setting sre the most common reason for a PIC not working. But I have never had a PIC with bad config settings start working when I touched GND or an OSC pin.

It could be possible, but I have not experianced it. Maybe if one had an external mode selected but the wrong external mode.

It would be easy enough post the config part of your code.
 
I had a 16f84a act like what he said if I touched the crystal the leds would flash it wouldn't do any thing if i didn't touch it. I had removed the crystal from a old sound card. I ordered
me some new ones and changed it it did the same thing
Code:
 __CONFIG   _CP_OFF & _WDT_ON & _PWRTE_ON & _RC_OSC
to
Code:
 __CONFIG   _CP_OFF & _WDT_ON & _PWRTE_ON & _HS_OSC
It worked like It should you don't have a config with a stamp. But now I no.
I Like the pic so much better just a lot of new learning
 
Last edited:
So,

Here are my config bits:

PHP:
Osicllator                 HS  (tried with XT as well)
Watchdog Tmr               Off
Power Up Timer             Off
Code Protect               Off
Brown Out Detect           Off
Low Voltage Programming    Off
Data EE Read Protect       Off
Flash PRogram Write        Off

Giving 0x3F3A in total.
Seems to be really strange bug ... I've tried both setting bits in MPLab config and in code ... no result ...
 

I've had this *exact* same problem before.

Add this code in to the top of your project and tell me how it goes:

Code:
banksel ANSEL
clrf ANSEL
banksel ANSELH
clrf ANSELH

So my code looks something like this:

Code:
START
	banksel  TRISA				; RP 1
	clrf TRISA
	clrf TRISB
	clrf TRISC
	banksel  PORTA				; RP 0

	banksel  ANSEL
	clrf     ANSEL
	banksel  ANSELH
	clrf     ANSELH
	
	banksel PORTC                            ; Back to RP0
 
Last edited:
Well, got the following errors:

Symbol not previously defined: ANSEL

and same for ANSELH

are those defined in some particular header? or am I just mistyping? (haven't been sleeping for more than 2 hrs per night for 2 weeks already ... so, might just mistype ...)
 


Ok, please post your code. This is my code: (it will work on a wide array of 16F chips)


Code:
#include <p16F690.inc>
	__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)

	org 0x00

START
	banksel  TRISA				; All ports are output
	movlf    0x00, TRISA
	movlf    0x00, TRISB
	movlf    0x00, TRISC
	banksel  PORTA

	banksel  ANSEL				; Digital inputs
	clrf     ANSEL
	banksel  ANSELH
	clrf     ANSELH

	banksel  CM1CON0			; Disable comparators
	bcf      CM1CON0, C1ON
	banksel  CM2CON0
	bcf      CM2CON0, C2ON
	
	goto $
	end
 
Last edited:
Well, here is mine ... Delay routines are taken from piclist.com delay generator (not plagiarizin') ...

Code:
	list	p=16F872
	include "P16F872.inc"
	__config	0x3F3A

       cblock
	d1
	d2
	d3
	endc

	org 	0x0000

	CLRF 	CCP1CON ; Turn CCP module off
	
	bcf		STATUS, RP0
	bcf		STATUS, RP1
	clrf	PORTA
;	clrf	PORTB
	bsf 	STATUS, RP0		; select bank 1

	clrw
	movwf	ADCON0
	movlw	0x06
	movwf	ADCON1

	movlw	0x00
	movwf	TRISA			; in bank 1
	movwf	TRISB			; in bank 1
	movwf	TRISC
	bcf		STATUS, RP0

	clrf	PORTA
;	clrf	PORTB
	clrf	PORTC

MainLoop
;	incf	count1
	movlw	0xff
	movwf	PORTA
	bsf		PORTB, 5
	bsf		PORTB, 4
	movwf	PORTC
	call	Delay
	bcf		PORTB, 5
	bcf		PORTB, 4
	movlw	0x00
	movwf	PORTC
	call	Delay
	goto	MainLoop

Delay
			;2499992 cycles
	movlw	0x15
	movwf	d1
	movlw	0x74
	movwf	d2
	movlw	0x06
	movwf	d3
Delay_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay_0

			;4 cycles
	goto	$+1
	goto	$+1

			;4 cycles (including call)
	return


	end
 
Last edited:
actually, interesting fact ... I found out today, that I had one of the Vss pins unconnected. I've connected it, but still the same bug. Now, I decided to modify my ICD2 a bit, so that I will have only VDD and GND pins on the connector (separate one). With the above mentioned code, the led pins get high, but never go low. I believe that another issue could be that !MCLR pin never gets its 5V when ICD2 is connected.
 

Your code has so many things wrong with it it's not even funny. I know it's frustrating (especially if you're sleep deprived) so I fixed it for you. Tell me if it works and then we can work on the understanding of the code xD

Code:
	list	p=16F872
	include "p16F872.inc"
	__config	0x3F3A
    
d1 res 1
d2 res 1
d3 res 1


	org 	0x00

	banksel CCP1CON
	clrf 	CCP1CON ; Turn CCP module off
	banksel CCP2CON
	clrf    CCP2CON ; Turn CCP 2 off
	
	banksel TRISA   ; All ports are output
	clrf    TRISA
	clrf    TRISB
	clrf    TRISC
	
	banksel PORTA
	clrf	PORTA   ; Set the value of the pins to 0x00
	clrf	PORTB
	clrf    PORTC

	banksel ADCON0	
	bcf     ADCON0, ADON    ; Disable analog to digital

	banksel ANSEL
	clrf ANSEL
	clrf ANSELH

	banksel PORTA


MainLoop
;	incf	count1
	movlw	0xff
	movwf	PORTA
	bsf		PORTB, 5
	bsf		PORTB, 4
	movwf	PORTC
	call	Delay
	bcf		PORTB, 5
	bcf		PORTB, 4
	movlw	0x00
	movwf	PORTC
	call	Delay
	goto	MainLoop

Delay
			;2499992 cycles
	movlw	0x15
	movwf	d1
	movlw	0x74
	movwf	d2
	movlw	0x06
	movwf	d3
Delay_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay_0

			;4 cycles
	goto	$+1
	goto	$+1

			;4 cycles (including call)
	return


	end

Check the data sheet. Search for "ANSEL", what does it say about the ANSEL register?
 
Last edited:
well, datasheet doesn't contain word ANSEL ...

I do believe that the problem is not in the code ... might be in the config bits, but ... at lest my version was working in SIMulator nicely. When I removed all lines with ANSEL from your version (so that it compiles), it gave the same result ... 2 leds are high all the time ...
 
well, datasheet doesn't contain word ANSEL ...

He seems a little confused about which PIC you're using?.

Check my tutorials, which mostly work with the 16F628 or 16F876 (which is VERY similar to the 872). The 'changes' page shows the minimum chnages required from 628 to 876.
 
try this
Code:
list      p=16f872            ; list directive to define processor
	#include <p16f872.inc>        ; processor specific variable definitions
	
	__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _WRT_ENABLE_ON & _LVP_ON & _CPD_OFF
then the rest off your code
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…