View previous topic :: View next topic |
Author |
Message |
MotoDan
Joined: 30 Dec 2011 Posts: 55
|
PIC16LF1579 Pull-Up Anomaly |
Posted: Thu Mar 05, 2020 4:31 pm |
|
|
I just discovered a possible issue with the programmable weak pull-ups. I've only tested this on the PIC16LF1579, but I suspect it might also pertain to other similar parts.
The problem was found when I noticed one of my inputs was going high with no external signal was applied. The pin was RB5.
I isolated the code until I determined the cause which turned out to be the application of the internal pull-ups on Port C.
The RB5 pull-up is applied as soon as the port_c_pullups(0xff) statement is executed. Turning off Port C pull-ups does not remove the pull-up on RB5.
The only way I can remove the RB5 pull-up is to execute a port_b_pullups(0x00) statement either before or after the port_c_pullups() statement.
I first noticed this while using PCM 5.080 which has since been updated to the latest 5.093. The same problem exists with either version compiler.
Here's the test program used to demonstrate the issue:
Code: |
#include <16LF1579.h>
#use delay(clock=4000000)
main()
{
while(1)
{
delay_ms(1000);
port_c_pullups(0xFF); //adds a pull-up on RB5
delay_ms(1000);
port_c_pullups(0x00); //does not remove RB5 pull-up
delay_ms(1000);
port_b_pullups(0x00); //removes RB5 pull-up
//RB5 pull-up does not occur once the above is executed
}
}
|
And the associated listing output:
Code: |
CCS PCM C Compiler, Version 5.093, 50212 05-Mar-20 15:50
ROM used: 70 words (1%)
Largest free fragment is 2048
RAM used: 6 (1%) at main() level
18 (2%) worst case
Stack used: 0 locations
Stack size: 16
0000: MOVLP 00
0001: GOTO 019
0002: NOP
.................... #include <16LF1579.h>
.................... //////////// Standard Header file for the PIC16LF1579 device ////////////////
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// (C) Copyright 1996, 2014 Custom Computer Services ////
.................... //// This source code may only be used by licensed users of the CCS C ////
.................... //// compiler. This source code may only be distributed to other ////
.................... //// licensed users of the CCS C compiler. No other use, reproduction ////
.................... //// or distribution is permitted without written permission. ////
.................... //// Derivative programs created using this software in object code ////
.................... //// form are not restricted in any way. ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... #device PIC16LF1579
....................
.................... #list
....................
.................... #use delay(clock=4000000)
0003: MOVLW 20
0004: MOVWF 05
0005: MOVLW 02
0006: MOVWF 04
0007: MOVF 00,W
0008: BTFSC 03.2
0009: GOTO 018
000A: MOVLW 01
000B: MOVWF 78
000C: CLRF 77
000D: DECFSZ 77,F
000E: GOTO 00D
000F: DECFSZ 78,F
0010: GOTO 00C
0011: MOVLW 4A
0012: MOVWF 77
0013: DECFSZ 77,F
0014: GOTO 013
0015: GOTO 016
0016: DECFSZ 00,F
0017: GOTO 00A
0018: RETURN
.................... main()
0019: MOVLB 03
001A: CLRF 0C
001B: CLRF 0D
001C: CLRF 0E
001D: MOVLB 02
001E: CLRF 12
001F: CLRF 11
0020: CLRF 14
0021: CLRF 13
.................... {
.................... while(1)
.................... {
.................... delay_ms(1000);
0022: MOVLW 04
0023: MOVLB 00
0024: MOVWF 21
0025: MOVLW FA
0026: MOVWF 22
0027: CALL 003
0028: DECFSZ 21,F
0029: GOTO 025
.................... port_c_pullups(0xFF); //adds a pull-up on RB5
002A: MOVLW FF
002B: MOVLB 04
002C: MOVWF 0E
002D: MOVLB 01
002E: BCF 15.7
.................... delay_ms(1000);
002F: MOVLW 04
0030: MOVLB 00
0031: MOVWF 21
0032: MOVLW FA
0033: MOVWF 22
0034: CALL 003
0035: DECFSZ 21,F
0036: GOTO 032
.................... port_c_pullups(0x00); //does not remove RB5 pull-up
0037: MOVLB 04
0038: CLRF 0E
.................... delay_ms(1000);
0039: MOVLW 04
003A: MOVLB 00
003B: MOVWF 21
003C: MOVLW FA
003D: MOVWF 22
003E: CALL 003
003F: DECFSZ 21,F
0040: GOTO 03C
.................... port_b_pullups(0x00); //removes RB5 pull-up
0041: MOVLB 04
0042: CLRF 0D
0043: MOVLB 02
0044: GOTO 022
.................... //RB5 pull-up does not occur once the above is executed
.................... }
.................... }
|
The pull-up on RB5 only occurs once - despite the looping.
My current work-around is to simply place a port_b_pullups(0x00) statement in my initialization routine.
I have not tested the other Port B pins yet since my circuit only uses RB5 as an input.
Is this a possible bug or am I missing something? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Fri Mar 06, 2020 1:36 am |
|
|
This is just about making an incorrect assumption.
There is a single master weak pull up 'enable' bit. Once this is turned on
all pullups that are enabled in the individual registers are turned 'on'.
Now the individual enables all wake up set 'on' (read the data sheet).
So as soon as you enable any pull up, all the other pull ups will be turned
on 'by default'. You have to set all three registers (for Port A, B & C), to
values that you actually want. |
|
|
MotoDan
Joined: 30 Dec 2011 Posts: 55
|
|
Posted: Fri Mar 06, 2020 10:48 am |
|
|
Thanks Ttelmah. I see where ALL of the individual port pin pull-up bits are set to '1' by default so ANY change to the pull-ups will result in all others being turned on.
Cheers |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Fri Mar 06, 2020 11:39 am |
|
|
Exactly.
Having just the single 'master enable', leads to the effect you were seeing.
Definitely worth remembering to setup all the ports..... |
|
|
|