Page 1 of 2
Problem With Input Port-F Pin4 on PIC18F6520

Posted:
Mon Jun 30, 2014 2:22 pm
by disremy
I have a weird problem with the Pin Port-F pin4 (0x10) on PIC18F6520
Whatever the level (0 or 5v voltage) at the input
pin Port-F pin4, the state doesn't change in PortF register.
the bit b4 is always read as 0 .
I used several methods to read it, with Btfsc intruction
or with MOVF Portf,W and test bit b4 in wreg.
In TrisF the Pin is well declared as a input
The analog to digital converter is disabled, Full inputs in logic mode.
the comparator is also disabled.
I verified that all registers implicated are in the good state
with a ICD3 in Step by Step mode.
ADCON0,ADCON1,TRISF,PORTF,CMCON,CVRCON.
I also verified that tere is no short circuit on hardware.
If someone have an idea ?
Re: Problem With Input Port-F Pin4 on PIC18F6520

Posted:
Mon Jun 30, 2014 6:58 pm
by jtemples
What value have you set for ADCON1?
Re: Problem With Input Port-F Pin4 on PIC18F6520

Posted:
Mon Jun 30, 2014 8:15 pm
by SLTom992
jt must be correct. You have ADCON1 lower nibble set to less than 0x06. Since this is the DEFAULT on this register you have to set ADCON1 to 0x06 or higher.
Re: Problem With Input Port-F Pin4 on PIC18F6520

Posted:
Mon Jun 30, 2014 11:41 pm
by ric
disremy wrote:The analog to digital converter is disabled.
Full inputs in logic mode.
the comparator in also idsabled.
I verified that all registers implicated are in the good state
with a ICD3 in mode Step by Step.
ADCON0,ADCON1,TRISF,PORTF,CMCON,CVRCON.
...
All this states that you THINK you have put the correct value into all of these registers.
As you still have a problem, it is a much better idea to show the actual values in the registers, and/or the code writing to them, so others can independently verify you have done it correctly.
Re: Problem With Input Port-F Pin4 on PIC18F6520

Posted:
Tue Jul 01, 2014 9:33 am
by disremy
The code is a input driver witch collect the state of several pins on several ports
An extract of the code :
- Code: Select all
PIN_FD_BK EQU 2 ;
PIN_VARDEF EQU 4 ;
Variables :
INPUTS2 EQU 0x017D ; Recopie avec mise en forme des entrees
INP_AUX4 EQU 0 ; Set Si Entree Auxiliaire 4 Active Defaut VAR
INP_AUX5 EQU 1 ; Set Si Entree Auxiliaire 5 Active FeedBack
Code:
MOVLW 00010100B ;
MOVWF TRISF ;
CLRF CMCON ; Utile Sur les Pic18 A Partir de 40 Broches
CLRF CVRCON ;
;
MOVLW 0x0F ; Added code to desactivate the AD
MOVWF ADCON1 ; usually not required
CLRF ADCON0 ;
LFSR 1,INPUTS2 ;
CLRF INDR1 ;
LFSR 0,INPUTS ;
CLRF INDR0 ;
;
BTFSS PORTE,IN_TOR2 ; Recopie Entree TOR Aux 1
BSF INDR0 ,INP_AUX1 ; Le Contact doit etre ferme
;
BTFSS PORTE,IN_TOR1 ; Recopie Entree TOR Aux 3
BSF INDR0 ,INP_AUX2 ; Le Contact doit etre ferme
MOVF PORTF,W ; Doesn't work
BTFSC WREG ,PIN_VARDEF ; Recopie Entree PIN_VARDEF - -
; BTFSC PORTF,PIN_VARDEF ; Recopie Entree PIN_VARDEF Doesn't work
; BTFSC PORTE,IN_TOR1 ; Recopie Entree TOR Aux 1 Work Well on PORTE
BSF INDR1 ,INP_AUX4 ; Le Contact doit etre Ouvert
;
;
BTFSC PORTF,PIN_FD_BK ; Recopie Entree TOR Aux 4 Work Well !!
BSF INDR1 ,INP_AUX5 ; Le Contact doit etre ferme
;
;
MOVLW 00001011B ; Added code to restore good state for AD
MOVWF ADCON1 ;
MOVLW 00000001B ;
MOVWF ADCON0 ;
Re: Problem With Input Port-F Pin4 on PIC18F6520

Posted:
Tue Jul 01, 2014 10:57 am
by Ian.M
Use the LATx registers for individual output pin manipulation!
Re: Problem With Input Port-F Pin4 on PIC18F6520

Posted:
Tue Jul 01, 2014 2:00 pm
by disremy
I know that but it is a input problem, not ouput
I always use LATx to ouptut and Portx to input !!!
Re: Problem With Input Port-F Pin4 on PIC18F6520

Posted:
Tue Jul 01, 2014 7:20 pm
by Ian.M
Sorry for the brain-fart.
Are you able to try a different chip to eliminate the possibility of a bad pin maybe due to ESD damage? When you pull the pin high is it hi-z or does it take significant current. Does the pin work as an output?
Re: Problem With Input Port-F Pin4 on PIC18F6520

Posted:
Wed Jul 02, 2014 8:51 am
by disremy
Thanks,
I made the test and I have the same behavior on another pic18F6520.
For Esd is a good idea but, the PortF-pin4 is driven by the photo transistor of an optocoupler ...
Several input and output of portF are protected by optocouplers
All other pin of portF work well wathever input or ouput mode.
Re: Problem With Input Port-F Pin4 on PIC18F6520

Posted:
Wed Jul 02, 2014 9:41 am
by disremy
The Phototransistor collector pin of the optocoupler is pull-up by a 22K resistor to ensure good voltage level on portf-pin4 (4,8V).