PDA

View Full Version : PORTC Weak Pull-ups on PIC16F1503



Aussie Barry
- 24th October 2013, 11:15
Hi All,

I am making good inroads programming the PIC16F1503.
I am able to set Timer1 and IOC interrupts with Darrel's DT_INT routine and can flash LED's at appropriate rates but I have hit a snag setting up weak pull-ups on PORTC.
I can set up weak pull-ups on PORTA but I get a syntax error message when compiling with a weak pull-up on PORTC setting.
My code is as follows:



#CONFIG
__config _CONFIG1, _FOSC_INTOSC & _MCLRE_OFF & _CP_OFF & _CLKOUTEN_OFF
__config _CONFIG2, _LVP_OFF & _LPBOR_OFF
#ENDCONFIG

OSCCON = %01101000 ; Fosc = 4MHz
; Clock determined by Fosc<1:0> Config Word
DEFINE OSC 4 ; Define socillator as 4MHz

' Included the interrupt system
INCLUDE "DT_INTS-14.bas"
INCLUDE "ReEnterPBP.bas"

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _ISR, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM


@ INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts


ANSELA = 0 ; Disable PORTA ADC
ANSELC = 0 ; Disable PORTC ADC
DACCON0.7 = 0 ; Disable DAC
CM1CON0.7 = 0 ; Disable comparator 1
CM2CON0.7 = 0 ; Disable comparator 2
T1CON = %00110000 ; Fosc/4
; 1:8 Prescaler
; Timer1 OFF
T1GCON.7 = 0 ; Timer1 counts regardless of gate function
TRISA = %00011000 ; PORTA.3 and PORTA.4 as inputs
TRISC = %00001101 ; PORTC.0, PORTC.2 and PORTC.3 as inputs
OPTION_REG.7 = 0 ; Enable Weak Pull-ups
WPUA = %00011000 ; Pull-ups on PORTA.3 and PORTA.4WPUC = 1
WPUC = %00001101 ; Pull-ups on PORTC.0, PORTC.2 and PORTC.3
IOCAP = %00011000 ; IOC positive edge register PORTA.3 + PORTA.4
IOCAN = %00011000 ; IOC negative edge register PORTA.3 + PORTA.4


The compiler reports a syntax error at the WPUC = %00001101 statement.
No problems with the WPUA = %00011000 statement so I am bewildered.
The datasheet clearly states how to use the WPUC register and I believe I have followed the instructions correctly.
Am I missing something?

I am using Microcode Studio Version 5.0.0.0, PBP3.0.5.4 and MeLabs U2 programmer.

Any assistance would be greatly appreciated.

Cheers
Barry
VK2XBP

Acetronics2
- 24th October 2013, 12:49
Hi, Barry

you're right

WPUC definition is missing in the .PBPINC file ...

you can add it yourself if you want ( C:\PBP3\DEVICES\PIC16F1503.PBPINC file)

PBP Team : To be corrected fo Next release
Alain

Darrel Taylor
- 24th October 2013, 18:17
Ok Alain,

If you can tell me what address that register is in, it will be added.

I'm betting you won't find that little bit of information.

Darrel Taylor
- 24th October 2013, 23:00
I guess Alain doesn't want to play. :(
Instead, he posted a bug report in the melabs forum without doing any research.

So Barry,
The 16F1503 doesn't have a WPUC register.

Yes, I know you'll find references to WPUC in the datasheet ... but it doesn't exist.
There is a WPUA, but no WPUC.

If you need pull-ups on PORTC, they'll have to be external.

Aussie Barry
- 24th October 2013, 23:51
Hi Darrel,

I did a bit of searching on this subject and found some conflicting information.
Microchip has released an errata document stating WPUC is not available for the PIC16F1503 but I also found another forum where a member had successfully implemented WPUC at H.'020E'
http://www.microchip.com.edgekey.net/forums/m631051-print.aspx

I am not sure who to believe.
I really don't have room on my board for external pull-up resistors. I chose the PIC16F1503 because it was reported to have weak pull-ups on both PORTA and PORTC.
Is a workaround possible using H.'020E' address?

Cheers
Barry
VK2XBP

Darrel Taylor
- 25th October 2013, 00:13
The person that said he got PORTC pull-ups to work on a 16F1503, has a total of 1 post on that forum.
Completely unreliable source.

The register, and the pull-ups do not exist in hardware.
No amount of messing with the code will change that fact.

Attempting to write to that address will result in errors from the assembler.
You can use the FSR's to indirectly write to address 020E ... but no pull-ups will activate on PORTC, because they're not there.
And when you read it back it returns all 0's.
I have actually done that with a 16F1503.



I am not sure who to believe.
I'm Crushed! :eek:

Aussie Barry
- 25th October 2013, 00:22
Hi Darrel,

Thanks for the prompt reply and detailed explanation.
Please do not feel crushed. My comments were from complete despair and were not directed at you. I should have known better than to question your reply but I read that someone had managed to achieve what I wanted to do and I saw a glimmer of hope on the horizon.

Time for a re-think on how to achieve my desired result. Thankfully, I do like a good challenge ;)

Cheers
Barry
VK2XBP

Aussie Barry
- 25th October 2013, 02:24
Perhaps I should look at using PIC16F1823 instead of the PIC16F1503?

Darrel, are you aware of any issues with WPUC on the PIC16F1823?

Cheers
Barry
VK2XBP

Darrel Taylor
- 25th October 2013, 20:31
On the 16F1823 ... the weak pull-ups on PORTC work fine.

Acetronics2
- 25th October 2013, 21:04
I guess Alain doesn't want to play. :(
Instead, he posted a bug report in the melabs forum without doing any research.



Apologies, Darrel ...

I 've forgotten to download their ....GRRRRR ... F... errata sheet !!!
errata happens so often it might automatically be included in the download ... ;)

Alain

Aussie Barry
- 30th October 2013, 04:59
Hi All,

I have now swapped over to PIC16F1823 for this project and I am now having difficulty using pins on PORTA as inputs with Weak Pull-ups enabled.
I have stripped down my code as follows:


#CONFIG
__config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _MCLRE_OFF & _BOREN_OFF
__config _CONFIG2, _PLLEN_OFF & _LVP_OFF & _WRT_HALF
#ENDCONFIG

OSCCON = %01101000 ; Fosc = 4MHz
; Clock determined by Fosc<1:0> Config Word
DEFINE OSC 4 ; Define oscillator as 4MHz

ANSELA = 0 ; Set PORTA as digital I/O
ANSELC = 0 ; Set PORTC as digital I/O
ADCON0.0 = 0 ; Disable ADC
DACCON0.7 = 0 ; Disable DAC
CM1CON0.7 = 0 ; Disable comparator 1
CM2CON0.7 = 0 ; Disable comparator 2
CPSCON0.7 = 0 ; Disable CPS module
T1CON.7 = 0 ; Timer1 OFF
TRISC = 0 ; All PORTC as outputs
TRISA = 1 ; All PORTA as inputa
OPTION_REG.7 = 0 ; Enable Weak Pull-ups
WPUA = %00111111 ; Pull-ups enabled on PORTA


LED1 var PORTC.5
LED2 var PORTC.1

Start: ; Flash LED1 and LED2 at 1Hz


high LED1
High LED2
Pause 500
low LED1
low LED2
pause 500


Goto Start


The program flashes LED1 and LED2 as expected but I get strange readings when I probe PORTA.1, .2, .4 or .5 with my oscilloscope.
With PORTA set as digital inputs and weak pull-ups enables on PORTA I would expect those pins to read +5v but they are in fact reading 0v

I need to connect switches to PORTA.2, .4 and .5 to make selections for my program to function but can't switch these pins to ground if they are already permanently there!

Can anyone shed any light on what might be happening or what I might be doing wrong?

Cheers
Barry
VK2XBP

Darrel Taylor
- 30th October 2013, 05:10
Except for PORTA.0, you've set all PORTA pins to OUTPUT mode.

TRISA = 1 ; All PORTA as inputa
By default at power-up, all pins are in INPUT mode.
So unless you need to set a pin to output, you don't need to change the TRIS register.

Aussie Barry
- 30th October 2013, 05:16
Oh Dear.....

I just want to crawl into a hole and hide form the world...

Thanks Darrel