Searching \ for '[PIC] PIC16F18854 PORTB Read problem' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/ios.htm?key=port
Search entire site for: 'PIC16F18854 PORTB Read problem'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] PIC16F18854 PORTB Read problem'
2017\08\22@225632 by James Wages

flavicon
face
I've discovered something unusual while programming a PIC16F18854 in Assembly.  
I have PORTB set to be all DIGITAL INPUTS.  (In the case of the 16F18854, PORTB is RB0 through RB7.)  Normally on other PICs, the following code works just fine to read such inputs:

    banksel PORTB       ; [Bank 0]
    movf    PORTB, W    ; Move state of PORTB input pins to W register.
    movwf   RAMa        ; Save W in RAM (0x077, RAM common to all banks)

The problem is that when I use to above code, RB5 (pin 26) is misread.  It is misread even when I use this code (repetition, just for a test):

    banksel PORTB       ; [Bank 0]
    movf    PORTB, W    ; Move state of PORTB input pins to W register.
    movwf   RAMa        ; Save W in RAM
    nop
    nop
    nop
    nop
    movf    PORTB, W    ; Move state of PORTB input pins to W register.
    movwf   RAMa        ; Save W in RAM
    nop
    nop
    nop
    nop
    movf    PORTB, W    ; Move state of PORTB input pins to W register.
    movwf   RAMa        ; Save W in RAM


But when I manually check the state of every pin in PORTB, nothing is misread and the problem is solved:

   banksel PORTB        ; [Bank 0]
   clrf    RAMa
   btfsc   PORTB, RB0
   bsf     RAMa, 7
   btfsc   PORTB, RB1
   bsf     RAMa, 6
   btfsc   PORTB, RB2
   bsf     RAMa, 5
   btfsc   PORTB, RB3
   bsf     RAMa, 4
   btfsc   PORTB, RB4
   bsf     RAMa, 3
   btfsc   PORTB, RB5
   bsf     RAMa, 2
   btfsc   PORTB, RB6
   bsf     RAMa, 1
   btfsc   PORTB, RB7
   bsf     RAMa, 0


I'm pleased I have a solution, but I don't understand why moving the entire PORT to W and then to RAM causes a misread pin.  Do any of you know? (And again, PORTB is setup via TRISB to be all INPUTS, ANSELB is cleared, making the pins DIGITAL.)

Thanks.

-- http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
mailman.mit.edu/mailman/listinfo/piclist
.

2017\08\22@233331 by James Cameron

flavicon
face
Is there anything attached to pin 26?

Port B is complicated on the PIC16F18854.

What is INLVLB5 set to?

What is WPUB5 set to?

What is ODCB5 set to?

What is CCDPB5 set to?

What is CCDNB5 set to?

Does changing SLRB5 fix it?

-- James Cameron
http://quozl.netrek.org/
-- http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
mailman.mit.edu/mailman/listinfo/piclist
.

2017\08\24@011411 by James Wages

flavicon
face
TRISB is b'11111111' at Reset, but I also manually write that value into TRISB in my init routine, ensuring without a doubt that all of PORTB is set to INPUTS.  Each of those 8 inputs (including pin 26) each have an external 100k-ohm pull-up to 5V.  Furthermore, there is an 8-switch DIP connected to each of those 8 INPUTS that when switched ON will short the individual INPUTS to Ground.  So the problem is that when I have my DIP SW tied to pin-26 to be ON/Ground, the PIC still thinks pin-26 is OFF/5V.  And yes, I verified with a DMM that there are no problems at all with my DIP SW and voltage levels.

INLVLB is b'11111111' at Reset, but I also tested with it manually set to 0, to no avail.

WPUB is set to 0 at Reset, and I also use clrf on that register in my code to ensure internal pullups are Disabled.

ODCONB is set to 0 at Reset, and it shouldn't matter since it pertains to sourcing or sinking current on OUTPUT pins -- all my PORTB pins are defined as INPUTS.  In any case, I leave that register at its default of 0.

I searched the entire 16F18554 datasheet in vain for CCDPB5 & CCDNB5, but they do not exist.  The only explanation I can imagine as to why you mentioned them is because you were looking at the wrong datasheet.  When I Google those two registers I find the "PIC16(L)F18855/75" datasheet, which is WRONG.  The PIC I am referring to is the 16F18854.  I provide the correct datasheet link for you below.

SLRCONB is set to b'11111111' ("limited") at Reset.  I normally leave it that way.  But per your request, I used clrf on it in my init routine, but the problem remains -- changing slew rate has no positive impact.

ANSELB is b'11111111' at Reset, but I use clrf on it in my init routine to ensure all pins are DIGITAL I/O.  I do NOT have any analog pins.
I don't use LATB because that pertains to Outputs.


With the exception of your mention of "CCDPB5 & CCDNB5", the above are all the registers associated with PORTB, as per TABLE 12-3 given on page 196 of the Revision B datasheet:

http://ww1.microchip.com/downloads/en/DeviceDoc/40001826B.pdf



And although I do have an ISR, it does not make calls to any routine that writes to my RAM (at 0x077).  Furthermore, when I do write to that RAM, interrupts are disabled.


Further thoughts would be appreciated.  But honestly, I wouldn't be surprised if it was flawed silicon because to date I've found and reported (to Microchip) no less than 15 distinct errors in that silly datasheet.  In all my years of using PICs I've not encountered that many errors in a datasheet.  I think it reflects badly on Microchip.  I am using this particular chip because I need more pins than a PIC16F1508 affords me, and I also need an NCO module, a CWG module, two CLC modules, and a PWM module in a low-priced PIC.

The reason I submitted my query to this list is because even though I've found a work-around (i.e., use "btfsc" on each and every silly PORTB input) I do not understand why "movf  PORTB, W" is misreading RB5 (pin 26).  That concerns me.

Thank you,

James Wages




Wed, 23 Aug 2017 13:33:21 +1000, James Cameron <spam_OUTquozlTakeThisOuTspamlaptop.org>:

   Is there anything attached to pin 26?
       Port B is complicated on the PIC16F18854.
       What is INLVLB5 set to?
       What is WPUB5 set to?
       What is ODCB5 set to?
       What is CCDPB5 set to?
       What is CCDNB5 set to?
       Does changing SLRB5 fix it?


-- http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
mailman.mit.edu/mailman/listinfo/piclist
.

2017\08\24@041726 by alan.b.pearce

face picon face
There have been chips in the past where there was some strange interaction with between port A and Port B that meant some bits of the a port (I can't remember which one) were not usable in some situations.

I think you are at the 'contact the FAE, here are the symptoms, what is the problem' point.



-- http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
mailman.mit.edu/mailman/listinfo/piclist
.

2017\08\29@200333 by stephen.forrestn/a

flavicon
face
Hi James -

When you say it is misread, do you mean that it is always HI or always LO?
Also, are you sure about your individual tests? It seems you are reversing the bit order- RB0 => RAMa,7 etc... Hence RB5 will be in RAMa,2, not RAMa,5 as might be expected.

Stephen

{Original Message removed}


'[PIC] PIC16F18854 PORTB Read problem'
2017\09\01@042030 by James Wages
flavicon
face
Stephen,

I resolved it in the Microchip forum here:

http://www.microchip.com/forums/m/tm.aspx?m=1011143

James Wages

> On Aug 31, 2017, at 1:00 AM, .....piclist-requestKILLspamspam@spam@mit.edu wrote:
>
> Hi James -
>
> When you say it is misread, do you mean that it is always HI or always LO?
> Also, are you sure about your individual tests? It seems you are reversing the bit order- RB0 => RAMa,7 etc... Hence RB5 will be in RAMa,2, not RAMa,5 as might be expected.
>
> Stephen
>
> ----- -- http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
mailman.mit.edu/mailman/listinfo/piclist
.

2017\09\03@185500 by stephen.forrestn/a

flavicon
face
Hi James - I am pleased you have a working solution . It would be good to really understand what happened in the first versions though.

Stephen


{Original Message removed}

More... (looser matching)
- Last day of these posts
- In 2017 , 2018 only
- Today
- New search...