CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

16F1827 Weak Pullups work on Port B but not on port A

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
johnl



Joined: 30 Sep 2003
Posts: 120

View user's profile Send private message

16F1827 Weak Pullups work on Port B but not on port A
PostPosted: Fri Feb 26, 2016 2:02 pm     Reply with quote

The assembly listing shows 0b11111 getting written to the WPUA register, but the datasheet says all but one bit of the WPUA register are unimplemented. So how do the individual port A pullups get configured? This code fails to enable the resistors on port A.
Code:

#include<16F1827.h>
#include<string.h>
#USE fast_io(B)
#USE  DELAY (CLOCK = 32M)
#use rs232(baud=9600,xmit=PIN_b2,PARITY=N,BITS=8,STOP=1, errors)
#FUSES   HS, PLL          // High speed osc with HW enabled 4X PLL
#FUSES   PUT         // Power Up Timer
#FUSES   NOBROWNOUT  // No brownout reset
#FUSES   NOWDT       // No Watch Dog Timer
#FUSES   MCLR      // Master Clear pin used for I/O
#FUSES   NOLVP       // No low voltage prgming
#FUSES   NOPROTECT   // Code not protected from reading
#FUSES   NOCPD       // No EE protection


#byte PORTA = 0x0E
#byte PORTB = 0x0D
#define IN PIN_B4
#define ZEROtimer       set_timer1(0)
#define LED PIN_B3
#define PULSE_OFF        output_low( PIN_B3)
#define PULSE_ON        output_high( PIN_B3)
      
long time;
int get_dmx(long );
long read_address(void);
int i;
int databit[8] = {0,0,0,0,0,0,0,0};
//=======================================
void main()
{
set_tris_b(0b11010011);
set_tris_a(0b00011111);
setup_adc_ports(NO_ANALOGS);
setup_timer_1 ( T1_INTERNAL );
port_a_pullups(0b00011111);
port_b_pullups(0b11010011);


while(1);;;;

}

Assembly listing for the pullup functions:
Code:

6:                port_a_pullups(0b00011111);
   028    301F     MOVLW 0x1f
   029    0024     MOVLB 0x4
   02A    008C     MOVWF 0xc
   02B    0021     MOVLB 0x1
   02C    1395     BCF 0x15, 0x7
37:                port_b_pullups(0b11010011);
   02D    30D3     MOVLW 0xd3
   02E    0024     MOVLB 0x4
   02F    008D     MOVWF 0xd
38:               
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 26, 2016 2:23 pm     Reply with quote

The listing looks better in Symbolic mode:
Code:
.................... port_a_pullups(0b00011111); 
0026:  MOVLW  1F
0027:  MOVLB  04
0028:  MOVWF  WPUA
0029:  MOVLB  01
002A:  BCF    OPTION_REG.WPUEN


The 16F1827 data sheet says this:
Quote:
12.2.1 WEAK PULL-UPS
Each of the PORTA pins has an individually configurable
internal weak pull-up. Control bit WPUA<5> enables or
disables the pull-up (see Register 12-6).

The 2nd sentence contradicts the first. Also, the WPUA register diagram
contradicts the first sentence. It says:
Quote:
bit 5 WPUA5: Weak Pull-up RA5 Control bit

It appears that only pin RA5 has a weak pullup available on it.
johnl



Joined: 30 Sep 2003
Posts: 120

View user's profile Send private message

PostPosted: Fri Feb 26, 2016 2:37 pm     Reply with quote

That's what I was afraid of. I am surprised there is no mention in the datasheet errata. Glad I didn't lay out the PCB yet.

Thanks for confirming.
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Fri Feb 26, 2016 4:02 pm     Reply with quote

It's only confusing, since they bothered to have the 'general' weak pull-up register for PortA, which is normally reserved for chips that have individual weak pull-ups, but then only implemented it on the MCLR pin, and because of the extra paragraph that PCM_Programmer is pointing to.
Obviously CCS based their code on other chips that normally have the individual bits if there is a WPUA register. :(

However it is interesting how this has changed in the data sheet.
The original sheet doesn't have the section referring to individual pull-ups. It just has the diagram and all references are to RA5 only. The paragraph PCM_Programmer points to, was added in the 2011 data sheet (potentially contradicting itself), and is directly copied from a couple of other chips that do have weak pull up's on the other pins (1829 for example).

So the only erratum, is in the sheet. Should be pointed out to MicroChip, and CCS, should have it pointed out that only RA5 has this.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Feb 26, 2016 4:37 pm     Reply with quote

The weak pull ups you want for the PIC in question come in convenient 1206/805/603 and even leaded packages and don't require programming to be on-duty even with power off... Laughing Laughing
hmmpic



Joined: 09 Mar 2010
Posts: 314
Location: Denmark

View user's profile Send private message

PostPosted: Sun Feb 28, 2016 1:56 am     Reply with quote

If you can use a 14 pin chip then, 16F1825 have the WPU.
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Feb 28, 2016 6:30 am     Reply with quote

I'll 'second' asmboy and point out that using REAL resistors remind you those I/O pins ARE inputs and better be high without an input to them !

Jay
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Sun Feb 28, 2016 10:12 am     Reply with quote

BTW: smart designers use pull-ups & downs on OUTPUTS too- especially where a design critical initial state MUST be HI or LOW for safety/performance reasons.

During power down and reset - those output lines can float long enough to make real trouble in your design - while your pic code is getting its I/O together. Its the prime reason i faithfully #use fastio() and ALWAYS init my I/O TRIS in a speedy structured way.
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Sun Feb 28, 2016 10:31 am     Reply with quote

Yes.
The internal pull-ups are 'OK' for non critical things like a keyboard, or inputs, where you do not read them till after you have setup the pull-ups, but 'beware' of using them for anything that requires a signal floats or is driven 'to' a level. They are very low current (which may not be enough to operate some circuitry), and the time before they are enabled, can be very dangerous.

It has always surprised me, that given the fuses like the one controlling the default ADC port selection on some chips, that MicroChip has never implemented a chip with a fuse controlled pull up/down.
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Sun May 29, 2016 11:54 pm     Reply with quote

Same with the PIC16F1847
After spending a day searching the problem Embarassed
I read the data sheet:

Quote:
12.2.1 WEAK PULL-UPS
Each of the PORTA pins has an individually configurable
internal weak pull-up. Control bit WPUA<5> enables or
disables the pull-up (see Register 12-6). The weak
pull-up is automatically turned off when the port pin is
configured as an output. The pull-up is disabled on a
Power-on Reset by the WPUEN bit of the
OPTION_REG register.

REGISTER 12-6: WPUA: WEAK PULL-UP PORTA REGISTER

only WPUA5 imlemented!!!
By the way the CCS Wizard letting me to chose Port A pull-ups!!!

The LST shows
Code:
....................     port_a_pullups(0xC0);
007B:  MOVLW  C0
007C:  MOVLB  04
007D:  MOVWF  WPUA
007E:  MOVLB  01
007F:  BCF    OPTION_REG.WPUEN
....................

So I was thinking the pull-ups are enabled, but they are not there at all.

Ttelmah, regarding your sentence
Quote:
The internal pull-ups are 'OK' for non critical things like a keyboard, or inputs, where you do not read them till after you have setup the pull-ups

I am reading some of port B pins with switches that are giving ground for '0' logic if ON. Do you think the internal pull-up's are OK for that?
I am reading them just in the main in the "while", the settings are the first line in the main:
Code:
port_b_pullups (0xFF);

In the past I used always pull-ups, but I want to reduce components on the board

Best wishes
Joe
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Mon May 30, 2016 1:17 am     Reply with quote

Yes. Your 'switches' are effectively a 'keyboard'. Just happens to be using slightly more solid switches than most. Smile

However 'beware' that like any keyboard, 'bounce' is always potentially there. My keyboards always use a timer interrupt to scan, and don't accept they are 'on', till the same state is seen on two successive passes through the interrupt.
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Mon May 30, 2016 2:33 am     Reply with quote

Thank you Ttelmah Smile

In the specific program I am polling the switches, testing consecutive 8 times '1' or '0' logic.

Best wishes
Joe
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group