Continue to Site

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.

PIC16f688 RA4

Status
Not open for further replies.

xNewbie

New Member
Hey guys I'm pretty new with all this programming stuff. Though I am currently working on this project as to where I have my RA4 pin as an input. I use it for momentary switch to change sequence.

Anyways, I have it set to high using WPUA. It would work during startup and would change the sequence whenever I use the switch. But it would often glitch after I try changing to my next sequence and it would instead get stuck on float rather than go back to high.

I pretty much have to shut the power off and back on for pin RA4 to return to being high.

I may have just missed something during my initialization...?

Any suggestion?
 
Any suggestion?
Sounds like your PIC is resetting during program run. Weak pullups are disabled after a reset. Do you have a proper pullup resistor (10K to 33K is fine) on your MCLR pin? Don't let MCLR float or you'll have freaky weird problems. :p

Power is solid? No shortage of it?

Do you have decoupling capacitors between VDD and VSS pins? As close as possible? 0.1uF ceramics are fine for this.

Are you setting RA4 as an output anywhere in the program? That will disable weak pullups too.
 
Last edited:
He might be using the internal MCLR function. I would encourage posters to include their code - or the relevant sections, at least - and a simple circuit diagram in their posts or people can only guess which the problem could be.
For example, I suspect that the CLKOUT funtion on RA4 has not been disabled by the configuration settings.
 
Last edited:
Do you have a proper pullup resistor (10K to 33K is fine) on your MCLR pin? Don't let MCLR float or you'll have freaky weird problems.

Not needed on 16F688; from the datasheet

A weak pull-up is automatically
enabled for RA3 when configured as MCLR and
_disabled when RA3 is an I/O. There is no software
control of the MCLR pull-up.
 
Perhaps you could add a section of code that outputs the current state of WPUA to an unused output pin every so often, that way you'll know if the problem is WPUA being changed somewhere, or if it's something else.

Or you could try adding an external pull-up resistor.
 
Another question.. Lets say it does reset.. Wont it just go back to my initialization code and start over again? and yes I do have an external pull up resistor.

May I be missing something here??

Code:
Parts of codes:

	__CONFIG   _FCMEN_OFF &  _IESO_OFF & _BOD_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT

Inititialization
		Bank1	; set file register bank to 1 
		CLRF		INTCON		
		MOVLW		B'01000010'	
		MOVWF		OPTION_REG	
		CLRF		PIE1
	                              	                          			             MOVLW		B'01100101'	
		MOVWF		OSCCON
		CLRF		OSCTUNE	
		CLRF		VRCON		
		
		MOVLW	B'00110100'	
		MOVWF	WPUA

		MOVLW	B'00110100'	;Enable Int. on Change for all PORTA I/P
		MOVWF	IOCA
			
		Bank0
		MOVLW		b'00100000'	
		MOVWF		T1CON		
		CLRF		PIR1
		CLRF  	  	TXREG
		MOVLW 	  	b'11000000' 	
		MOVWF		RCSTA
		MOVLW		b'01100110'	
		MOVWF		TXSTA
		MOVLW  	 	1     		
		MOVWF  	 	SPBRG
		MOVLW		b'01001000'	
		MOVWF		BAUDCTL
		CLRF		PORTC		
		CLRF		ADCON0
;------ Initializing PORTA ---------------------
		CLRF		PORTA
		MOVLW		b'00000111'	
		MOVWF		CMCON0		
		Bank1
		CLRF		ANSEL				
		MOVLW		b'00110100'
		MOVWF		TRISA		
;------ End of Initializing PORTA -------------	
		MOVLW		b'00100000'
		MOVWF		TRISC		
		Bank0
          BCF			PIR1,RCIF
		MOVF   	 	RCREG,W
		MOVF   	 	RCREG,W
		BSF    		RCSTA,CREN
		Bank1
		BSF		PIE1,RCIE
		Bank0
 
Last edited:
Apparently the GIE is being set during my interrupt service routine which causes this whole thing to go out of wack :)

Well thanks for the help/suggestions.
 
Apparently the GIE is being set during my interrupt service routine which causes this whole thing to go out of wack :)
And had you posted all your code someone would have spotted that and saved you a week of frustration.:D

mike.
 
Status
Not open for further replies.

Latest threads

Back
Top