Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC randomly latches up

Status
Not open for further replies.

tempus

Member
Hey all;

I'm using a PIC16F737 to switch a bunch of JFETs and LEDs on and off. I've got everything working fine, except that the PIC locks up on random button presses. So far I haven't really seen any pattern, i.e., it doesn't seem to matter which button is pushed. Also, there may be 20 button pushes before it locks up in one case, and 3 in another. Interestingly, the problem resolves itself over time - again not consistently; sometimes it may be 30s, other times it may only take a few.

Any ideas on how to resolve this?

I'm running the PIC at 4 MHz, using the internal oscillator.

Thanks
 
Last edited:

picbits

Well-Known Member
Do you have decent decoupling caps on the power pins as close to the PIC as possible (1nf + 10nf + 100nf) ?

Do the JFETS have a resistor between the gate and pin driving it from the PIC ?

Do you have the watchdog timer enabled and adequately cleared in the software ?

Do you have a call without a return somewhere (stack overflow)

Could be a million different reasons but without your schematics and code etc its a bit hard to work out.
 

tempus

Member
Do you have decent decoupling caps on the power pins as close to the PIC as possible (1nf + 10nf + 100nf) ?

I have a 0.1uF cap right at the power/ground pins. You have 3 listed here - do you mean to use 3 separate caps?

Do the JFETS have a resistor between the gate and pin driving it from the PIC ?

Yes. Every output pin is connected to a JFET via a 1M resistor and to an LED via a 2K or 750 ohm resistor.

Do you have the watchdog timer enabled and adequately cleared in the software ?

Watchdog timer is off. I didn't think I should use it because I was concerned with it resetting something that should be latched on.

Do you have a call without a return somewhere (stack overflow)

Yes. Here is my code:

Code:
;=============Pedalboard PIC code JFETs 10ms mute===============2009 10 21===

		list	p=pic16f737
		#include	<P16F737.inc>		; processor specific variable definitions
		radix	hex
;
	__CONFIG    _CONFIG1,  _CP_OFF & _CCP2_RB3 & _DEBUG_OFF & _VBOR_2_0 & _BOREN_0 & _MCLR_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_IO
	__CONFIG    _CONFIG2,  _BORSEN_0 & _IESO_OFF & _FCMEN_OFF
;------------------------------------------------------------
;				Counter locations
dbcount		equ		0x21
dc1			equ		0x22
dbcount_2  	equ		0x23
;------------------------------------------------------------
			org		0x000
;
;Initialization

start		bsf		STATUS,RP0		
			bcf		STATUS,RP1		;bank 1
			bsf 	OSCCON,IRCF2 	;set int osc 110=4Mhz	
			bsf 	OSCCON,IRCF1			
			bcf 	OSCCON,IRCF0
			movlw	0x0F			;conifgure all pins as
			movwf	ADCON1			;   digital inputs
			bcf		OPTION_REG,7	;enable PORTB pullups
			movlw	0x1F			;load w with 00011111
			movwf	TRISA			;make RA0-RA4 inputs,RA5-RA7 outputs
			movlw	0xFF			;load w with 1's
			movwf	TRISB			;make PORTB inputs	
			movlw	0x00			;load w with 0's
			movwf	TRISC			;make PORTC outputs
			bcf		STATUS,  RP0	;bank 0
			bsf		PORTA,6			;output hi RA6 - mute on
			nop		
			bsf		PORTA,5			;output hi RA5 - vb off
			nop
			bsf		PORTA,7			;output hi RA7 - lead channel on
			movlw	0x55			;load w with 01010101
			movwf	PORTC			;all effects bypassed
			bcf		PORTA,6			;output lo RA6 - mute off

;Main Program			

switch		btfss	PORTE,3			;bypass switch hi?
			goto	bypass			;no - swtich pressed
			btfss	PORTA,0			;comp vb switch hi?
			goto	compvb			;no - switch pressed
			btfss	PORTA,1			;comp switch hi?
			goto	comp			;no - switch pressed
			btfss	PORTA,2			;flanger switch hi?
			goto	flanger			;no - switch pressed
			btfss	PORTA,3			;chorus switch hi?
			goto	chorus			;no - switch pressed
			btfss	PORTA,4			;delay switch hi?
			goto	delay			;no - switch pressed
			btfss	PORTB,0			;comp delay switch hi?
			goto	compdelay		;no - switch pressed
			btfss	PORTB,1			;comp flanger switch hi?
			goto	compflanger		;no - switch pressed
			btfss	PORTB,2			;ch delay switch hi?
			goto	chdelay	 		;no - switch pressed
			btfss	PORTB,3			;clch delay switch hi?
			goto	clchdelay		;no - switch pressed
			btfss	PORTB,4			;cl flanger switch hi?
			goto	clflanger		;no - switch pressed
			btfss	PORTB,5			;cl chorus switch hi?
			goto	clchorus		;no - switch pressed
			btfss	PORTB,6			;clean switch hi?
			goto	clean			;no - switch pressed
			btfss	PORTB,7			;comp delay vb switch hi?
			goto	compdlyvb		;no - switch pressed
			goto	switch			;check all switches again

;					Switch Actions
;
bypass		bsf		PORTA,6			;turn mute on
			;	debounce switch down
db_down		movlw	0x1A			;max count = 20ms/768us = 26 = 0x1A
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly		incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly
			btfsc	PORTE,3			;if button up (RE3 hi),
			goto	db_down			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly
			;	actual switching
			call	mutedelay		;mute for 1s	
			bsf		PORTA,5			;output hi RA5 - vb off
			nop
			bsf		PORTA,7			;output hi RA7 - lead channel on
			movlw	0x55			;load w with 01010101
			movwf	PORTC			;all effects bypassed
			bcf		PORTA,6			;turn mute off
			;	debounce switch up 
db_up		movlw	0x0D			;max count = 10ms/768us = 13 = 0x0D
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly		incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly
			btfss	PORTE,3			;if button down (RE3 lo),
			goto	db_up			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly
			goto	switch

compvb		bsf		PORTA,6			;turn mute on
			;	debounce switch down
db_down1	movlw	0x1A			;max count = 20ms/768us = 26 = 0x1A
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly1		incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly1
			btfsc	PORTA,0			;if button up (RA0 hi),
			goto	db_down1		;restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly1	
			;	actual switching
			call	mutedelay		;mute for 1s
			movlw	b'01010110'		
			movwf	PORTC			;turn comp on
			bcf		PORTA,5			;output lo RA5 - vb on
			nop
			bsf		PORTA,7			;output hi RA7 - lead channel on
			bcf		PORTA,6			;turn mute off
			;	debounce switch up 
db_up1		movlw	0x0D			;max count = 10ms/768us = 13 = 0x0D
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly1		incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly1
			btfss	PORTA,0			;if button down (RA0 = lo),
			goto	db_up1			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly1
			goto	switch			;check switches again

comp		bsf		PORTA,6			;turn mute on
			;	debounce switch down
db_down2	movlw	0x1A			;max count = 20ms/768us = 26 = 0x1A
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly2		incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly2
			btfsc	PORTA,1			;if button up (RA1 hi),
			goto	db_down2		;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly2	
			;	actual switching
			movlw	b'01010110'		
			movwf	PORTC			;turn comp on
			bsf		PORTA,5			;output hi RA5 - vb off
			nop
			bsf		PORTA,7			;output hi RA7 - lead channel on
			call	mutedelay		;mute for 1s
			;	debounce switch up 
db_up2		movlw	0x0D			;max count = 10ms/768us = 13 = 0x0D
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly2		incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly2
			btfss	PORTA,1			;if button down (RA1 lo),
			goto	db_up2			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly2		
			bcf		PORTA,6			;turn mute off
			goto	switch			;check switches again

flanger		bsf		PORTA,6			;turn mute on
			;	debounce switch down
db_down3	movlw	0x0D			;max count = 10ms/768us = 13 = 0x0D
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly3		incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly3
			btfsc	PORTA,2			;if button up (RA2 hi),
			goto	db_down3		;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly3	
			;	actual switching
			call	mutedelay		;mute for 1s
			movlw	b'01011001'		
			movwf	PORTC			;turn flanger on
			bsf		PORTA,5			;output hi RA5 - vb off
			nop
			bsf		PORTA,7			;output hi RA7 - lead channel on
			;	debounce switch up 
db_up3		movlw	0x0D			;max count = 10ms/768us = 13 = 0x0D
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly3		incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly3
			btfss	PORTA,2			;if button down (RA2 = lo),
			goto	db_up3			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly3
			bcf		PORTA,6			;turn mute off
			goto	switch			;check switches again

chorus		bsf		PORTA,6			;turn mute on
			;	debounce switch down
db_down4	movlw	0x0D			;max count = 10ms/768us = 13 = 0x0D
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly4		incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly4
			btfsc	PORTA,3			;if button up (RA3 hi),
			goto	db_down4		;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly4	
			;	actual switching
			call	mutedelay		;mute for 1s
			movlw	b'01100101'		
			movwf	PORTC			;turn chorus on
			bsf		PORTA,5			;output hi RA5 - vb off
			nop
			bsf		PORTA,7			;output hi RA7 - lead channel on
			;	debounce switch up 
db_up4		movlw	0x0D			;max count = 10ms/768us = 13 = 0x0D
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly4		incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly4
			btfss	PORTA,3			;if button down (RA3 lo),
			goto	db_up4			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly4
			bcf		PORTA,6			;turn mute off
			goto	switch			;check switches again

delay		bsf		PORTA,6			;turn mute on
			;	debounce switch down
db_down5	movlw	0x0D			;max count = 10ms/768us = 13 = 0x0D
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly5		incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly5
			btfsc	PORTA,4			;if button up (RA4 hi),
			goto	db_down5		;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly5	
			;	actual switching
			call	mutedelay		;mute for 1s
			movlw	b'10010101'		
			movwf	PORTC			;turn delay on
			bsf		PORTA,5			;output hi RA5 - vb off
			nop
			bsf		PORTA,7			;output hi RA7 - lead channel on
			;	debounce switch up 
db_up5		movlw	0x0D			;max count = 10ms/768us = 13 = 0x0D
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly5		incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly5
			btfss	PORTA,4			;if button down (RA4 lo),
			goto	db_up5			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly5
			bcf		PORTA,6			;turn mute off
			goto	switch			;check switches again

compdelay	bsf		PORTA,6			;turn mute on
			;	debounce switch down
db_down6	movlw	0x0D			;max count = 10ms/768us = 13 = 0x0D
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly6		incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly6
			btfsc	PORTB,0			;if button up (RB0 hi),
			goto	db_down6		;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly6	
			;	actual switching
			call	mutedelay		;mute for 1s
			movlw	b'10010110'		
			movwf	PORTC			;turn comp and delay on
			bsf		PORTA,5			;output hi RA5 - vb off
			nop
			bsf		PORTA,7			;output hi RA7 - lead channel on
			;	debounce switch up 
db_up6		movlw	0x0D			;max count = 10ms/768us = 13 = 0x0D
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly6		incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly6
			btfss	PORTB,0			;if button down (RB0 lo),
			goto	db_up6			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly6
			bcf		PORTA,6			;turn mute off
			goto	switch			;check switches again

compflanger	bsf		PORTA,6			;turn mute on
			;	debounce switch down
db_down7	movlw	0x0D			;max count = 10ms/768us = 13 = 0x0D
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly7		incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly7
			btfsc	PORTB,1			;if button up (RB1 hi),
			goto	db_down7		;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly7	
			;	actual switching
			call	mutedelay		;mute for 1s
			movlw	b'01011010'		
			movwf	PORTC			;turn comp and flanger on
			bsf		PORTA,5			;output hi RA5 - vb off
			nop
			bsf		PORTA,7			;output hi RA7 - lead channel on
			;	debounce switch up 
db_up7		movlw	0x0D			;max count = 10ms/768us = 13 = 0x0D
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly7		incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly7
			btfss	PORTB,1			;if button down (RB1 lo),
			goto	db_up7			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly7
			bcf		PORTA,6			;turn mute off
			goto	switch			;check switches again

chdelay		bsf		PORTA,6			;turn mute on
			;	debounce switch down
db_down8	movlw	0x0D			;max count = 10ms/768us = 13 = 0x0D
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly8		incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly8
			btfsc	PORTB,2			;if button up (RB2 hi),
			goto	db_down8		;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly8	
			;	actual switching
			call	mutedelay		;mute for 1s
			movlw	b'10100101'		
			movwf	PORTC			;turn chorus and delay on
			bsf		PORTA,5			;output hi RA5 - vb off
			nop
			bsf		PORTA,7			;output hi RA7 - lead channel on
			;	debounce switch up 
db_up8		movlw	0x0D			;max count = 10ms/768us = 13 = 0x0D
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly8		incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly8
			btfss	PORTB,2			;if button down (RB2 lo),
			goto	db_up8			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly8
			bcf		PORTA,6			;turn mute off
			goto	switch			;check switches again

clchdelay	bsf		PORTA,6			;turn mute on
			;	debounce switch down
db_down9	movlw	0x0D			;max count = 10ms/768us = 13 = 0x0D
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly9		incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly9
			btfsc	PORTB,3			;if button up (RB3 hi),
			goto	db_down9		;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly9	
			;	actual switching
			call	mutedelay		;mute for 1s
			movlw	b'10100101'		
			movwf	PORTC			;turn chorus and delay on
			bsf		PORTA,5			;output hi RA5 - vb off
			nop
			bcf		PORTA,7			;output lo RA7 - clean channel on
			;	debounce switch up 
db_up9		movlw	0x0D			;max count = 10ms/768us = 13 = 0x0D
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly9		incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly9
			btfss	PORTB,3			;if button down (RB3 lo),
			goto	db_up9			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly9
			bcf		PORTA,6			;turn mute off
			goto	switch			;check switches again

clflanger	bsf		PORTA,6			;turn mute on
			;	debounce switch down
db_down10	movlw	0x0D			;max count = 10ms/768us = 13 = 0x0D
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly10	incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly10
			btfsc	PORTB,4			;if button up (RB4 hi),
			goto	db_down10		;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly10	
			;	actual switching
			call	mutedelay		;mute for 1s
			movlw	b'01011001'		
			movwf	PORTC			;turn flanger on
			bsf		PORTA,5			;output hi RA5 - vb off
			nop
			bcf		PORTA,7			;output lo RA7 - clean channel on
			;	debounce switch up 
db_up10		movlw	0x0D			;max count = 10ms/768us = 13 = 0x0D
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly10	incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly10
			btfss	PORTB,4			;if button down (RB4 lo),
			goto	db_up10			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly10
			bcf		PORTA,6			;turn mute off
			goto	switch			;check switches again

clchorus	bsf		PORTA,6			;turn mute on
			;	debounce switch down
db_down11	movlw	0x0D			;max count = 10ms/768us = 13 = 0x0D
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly11	incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly11
			btfsc	PORTB,5			;if button up (RB5 hi),
			goto	db_down11		;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly11	
			;	actual switching
			call	mutedelay		;mute for 1s
			movlw	b'01100101'		
			movwf	PORTC			;turn chorus on
			bsf		PORTA,5			;output hi RA5 - vb off
			nop
			bcf		PORTA,7			;output lo RA7 - clean channel on
			;	debounce switch up 
db_up11		movlw	0x0D			;max count = 10ms/768us = 13 = 0x0D
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly11	incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly11
			btfss	PORTB,5			;if button down (RB5 lo),
			goto	db_up11			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly11
			bcf		PORTA,6			;turn mute off
			goto	switch			;check switches again

clean		bsf		PORTA,6			;turn mute on
 			;	debounce switch down
db_down12	movlw	0x0D			;max count = 10ms/768us = 13 = 0x0D
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly12	incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly12
			btfsc	PORTB,6			;if button up (RB6 hi),
			goto	db_down12	;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly12	
			;	actual switching
			call	mutedelay		;mute for 1s
			movlw	b'01010101'		
			movwf	PORTC			;turn chorus and delay on
			bsf		PORTA,5			;output hi RA5 - vb off
			nop
			bcf		PORTA,7			;output lo RA7 - clean channel on
			;	debounce switch up 
db_up12		movlw	0x0D			;max count = 10ms/768us = 13 = 0x0D
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly12	incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly12
			btfss	PORTB,6			;if button down (RB6 lo),
			goto	db_up12			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly12
			bcf		PORTA,6			;turn mute off
			goto	switch			;check switches again

compdlyvb	bsf		PORTA,6			;turn mute on
			;	debounce switch down
db_down13	movlw	0x0D			;max count = 10ms/768us = 13 = 0x0D
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly13	incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly13
			btfsc	PORTB,7			;if button up (RB7 hi),
			goto	db_down13		;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly13	
			;	actual switching
			call	mutedelay		;mute for 1s
			movlw	b'10010110'		
			movwf	PORTC			;turn comp and delay on
			bcf		PORTA,5			;output lo RA5 - vb on
			nop
			bsf		PORTA,7			;output hi RA7 - lead channel on
			;	debounce switch up 
db_up13		movlw	0x0D			;max count = 10ms/768us = 13 = 0x0D
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly13	incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly13
			btfss	PORTB,7			;if button down (RB7 lo),
			goto	db_up13			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly13
			bcf		PORTA,6			;turn mute off
			goto	switch			;check switches again
;-----------------------------------------------------------------------------
;					mutedelay - 10ms delay 
;
mutedelay
			;9998 cycles
	movlw	0xCF
	movwf	dbcount
	movlw	0x08
	movwf	dc1
Delay_0
	decfsz	dbcount, f
	goto	$+2
	decfsz	dc1, f
	goto	Delay_0

			;2 cycles
	goto	$+1
			return

			end

The actual delay is set at 4 ms instead of 10 in the current design I'm using, but otherwise everything is the same (I would post the original code, but it somehow got erased and I can't pull it up :mad:) I can also post a schematic if you like.

Thanks
 

picbits

Well-Known Member
If you have a 100nf (0.1uf) capacitor across the power pins it should be sufficient for a 4Mhz operation (although it doesn't hurt to add the others to see if it makes it any more stable - it will help rule out power supply problems).


I've had a quick look at your code (and it was just a quick look) and the only thing that really jumps out at me is that you don't have any interrupts used or enabled.

Dont always rely on registers being at the right value on power on. If you are not using Interrupts, its worth clearing the Intcon register (and GIE bit etc).

You've also got some of your code in the place where the interrupt vector would be - this might or might not complicate things if you had an errant intterupt.

Maybe start the code like this from the ORG statement

Code:
ORG 0x00 ; this is where the software starts running
GOTO start
ORG 0x08 ; Interrupt vector
GOTO int_v
ORG 0x18 ; Only really used for devices with multi level interrupt
GOTO int_v

int_v
btfsc intcon,gie
goto int_v
retfie

start ;this is where your program starts

Like I said - a bit of a stab in the dark but for the sake of a couple more lines well worth it.

Also check all your paging is correct and you switch back to page0 when finished with page1 etc (I don't miss working on 16F devices lmao)
 

picbits

Well-Known Member
Oh - also forgot to say, if you are using MPLAB as your compiler/debugger, make sure the "use config bits in code" is ticked or it will ignore what you have in the code and use its default values (another gotcha lol)
 

tempus

Member
I've had a quick look at your code (and it was just a quick look) and the only thing that really jumps out at me is that you don't have any interrupts used or enabled.

My application didn't require any. I should mention that this is my 1st PIC project as well, so I may not be that well versed in some of the little tricks and caveats. Should I be using interrupts?

Dont always rely on registers being at the right value on power on. If you are not using Interrupts, its worth clearing the Intcon register (and GIE bit etc).

I'll check into that - I need to go back to the data sheet and look into that and the code for it.

10K pullup on MCLR pin whether you use MCLR in config or not

It's being used as an input so I have that already.

OK thanks again. I'll try to digest some of this stuff, as I'm not really clear on the interrupt thing.
 

tempus

Member
I've made a little progress on this problem. I discovered that when a certain switch made the PIC lock up, I could 'unlock' it up by pressing that same switch again. I think the problem must be in the debounce routine. I've got a 10ms debounce loop set on the debounce up section of each button push; perhaps it should be longer. I'm going to try upping it to 20ms and see if that fixes things.
 

qratman

New Member
It's being used as an input so I have that already.

In my recently made project with PIC12F683 I initially used MCLR/GPIO4 as input too. Pulled up with 10k, the other end went over 4-5m cable to hercon and back to ground.

I noticed that when switching fluorescent lamps OFF in other rooms, PIC suffered occational resets.

Leaving MCLR/GPIO4 alone and putting hercon to another IO pin cured the problem.
 

Mike - K8LH

Well-Known Member
That 4-5 meter cable may be acting as an excellent antenna for picking up electrical noise.
 
Last edited:
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top