Port E pullup on 18F66J16

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
User avatar
RadioT
Registered User
Registered User
Posts: 157
Joined: Tue Nov 27, 2007 12:50 pm
Location: Winnipeg, Canada

Port E pullup on 18F66J16

Post by RadioT » Sat Dec 29, 2007 11:31 am

Hello,
Anyone ever run into an issue with activating the pullups on Port E pins on the 18F66J16? Seems setting PORTG.6 doesn't do the trick. No difference on the output of Port E output pins when G.6 is set or not, voltage is only about 250 mV max. Drops to 0 when the switch is activated (pulled to ground), then increases to about 40 mV as it slowly draws up. I also tried to read PORTG.6 back to see the state, and it says it's not set, reads a 0.

Anyway, here's the code, unadulterated. I'm using the SSD1339 OLED GLCD for debugging, it's nice using that instead of stringing serial port wires to other PCs when doing the debug. Any suggestions??

Code: Select all

Device = 18F66J16

Clock = 32   
Include "GLCD.bas"
Include "ssd1339.bas"
Include "Verdana.bas"   
Include "convert.bas"
Include "system.bas"

 Function CheckButton(ByRef aPin As Boolean) As Boolean 
    result = aPin //used this method to check pin - didn't make any difference
End Function

Config Fosc = intoscpll //use internal PLL

Dim Power_LED As PORTC.0

output(portc.0)
   

   
Dim
   S0 As PORTE.booleans(0), //tried setting port 0 to bool to see if it showed the status correctly - measuring V showed it does
   S1 As PORTE.1, 
   S2 As PORTE.2,        
   S3 As PORTE.3,               
   S4 As PORTE.4         
   
   OSCTUNE.6 = 1 //turn on the PLL for 32 MHz with intosc
   OSCCON.6 = 1
   OSCCON.5 = 1
   OSCCON.4 = 1
   
 TRISA = %00001101         ' Configure PORTA pins As inputs And outputs
 TRISB = %11000011         ' Configure PORTB 
 TRISD = %00000000         ' Configure PORTD as outputs for diplay
 TRISE = %00011111         ' Configure PORTE as inputs for switches, outputs for display control

 TRISF = %01111111         ' Configure PORTF as inputs
 TRISG = %11011100         ' Configure PORTG as inputs for switches, outputs for display control


   Input(PORTE.0) //tried setting these switch inputs again to see if it worked - apparentlyl it does not
   Input(PORTE.1) 
   Input(PORTE.2)        
   Input(PORTE.3)               
   Input(PORTE.4)

High (PORTG.6)           // Enable the pull-ups on Port E (switches)

 High (PORTG.7)           // Enable the pull-ups on Port D (display data)

 // Initialize display
 GLCD.Brush.Color = $00 
 Pen.Color = $DA
 OLEDPower           //set up the OLED for powering up
 QPWR = 1              'turn on high voltage supply
  
 { ASM
CLRF PORTG 
CLRF LATG 
MOVLW D4 
MOVWF TRISG 
End ASM   } 'here's where I tried using assembler to set G.6
                       //wait 5 seconds for supercaps to charge up
 InitializeOLED         //put initialize here to ensure 5V initialization occurs before high V is turned on 
 Cls(0,0,132,132) //clear entire screen
 GLCD.SetFont(VerdanaBold)
 GLCD.WriteAt(0,2,"Powered Up")
 

 i=0

 If CheckButton(S0) Then 
  GLCD.WriteAt(0,15,"S0 is high ")
  Else
   GLCD.WriteAt(0,15,"S0 is low ")
  EndIf
  
 GLCD.WriteAt(0,28,"G =",HexToStr(PORTG.6)) //Here's where I get the status back of G.6)

 GLCD.WriteAt(0,41,"S2 =",HexToStr(PORTE.2))
 GLCD.WriteAt(0,54,"S3 =",HexToStr(PORTE.3))
 GLCD.WriteAt(0,67,"S4 =",HexToStr(PORTE.4))
 Power_LED = 0

 GoTo check_switches
 
Last edited by RadioT on Wed Jan 09, 2008 12:34 pm, edited 1 time in total.

xor
Posts: 286
Joined: Sun Nov 05, 2006 1:15 pm
Location: NYC
Contact:

Post by xor » Sat Dec 29, 2007 10:21 pm

You need to disable the Parallel Serial Port feature of PORTE. Default startup is active:

Code: Select all

MEMCON.7 = 1
Pullups active on PORTE (Inputs Only) is:

Code: Select all

PORTG.6 = 1
Also, consider that the pullups are "weak" pullups. The leak current is 30-240uA, which is equivalent to a 166K to 21K pullup resistor. If your circuit requires hard, or fast, pullups, you need to use pullup resistors. Anywhere in the range of 1K to 10K will work depending on your requirements.

User avatar
RadioT
Registered User
Registered User
Posts: 157
Joined: Tue Nov 27, 2007 12:50 pm
Location: Winnipeg, Canada

Post by RadioT » Sun Jan 06, 2008 5:19 pm

Hello XOR,

You're on the right track for the 80 pin device, but I should have mentioned that I am using the 64 pin device, so that port is not enabled.

After some messing about I discovered in the assembler that even when the BASIC code in SF is PORTG.6 = 1, the assembler generated by SF comes out as:

Code: Select all

?I000335_F000_000113_M000000 ; L#MK PORTG.6 = 1
        BSF LATG,6,0
thus attempting to set the latch on Port G line 6. However, the latches on Port G are only implemented on pins 0 to 5.

To fix the problem, I added the following line:

Code: Select all

ASM
BSF PORTG,6,0
End ASM
Now the pullups work! Also, when testing the bit on PORTG.6, it reports back as 1.

73's
-Tom

User avatar
rocketbob
Registered User
Registered User
Posts: 51
Joined: Sun Apr 01, 2007 1:36 am
Location: Indiana USA

Post by rocketbob » Sun Jan 06, 2008 11:07 pm

How did your code compile? You have a typo:

hgih (PORTG.6)

Regards,
Bob

User avatar
RadioT
Registered User
Registered User
Posts: 157
Joined: Tue Nov 27, 2007 12:50 pm
Location: Winnipeg, Canada

Post by RadioT » Tue Jan 08, 2008 4:14 am

I took out a bunch of unnecessary comments that where there and must have had to retype the line. I edited the code so now it's correct.

Anyway, the assembler line in my last post does work now. If David Barker wants to look at my results for this particular signal (pullup enable bits on Port G), perhaps he would find something I need to do or see a need to make a small change to how the compiler produces the asm output so it sets the port pin and not tries to set a latch.

Mikeclx
Posts: 20
Joined: Mon Feb 09, 2009 5:36 am
Location: New Zealand

Thanks

Post by Mikeclx » Mon Jan 07, 2013 8:59 am

This saved my neck..
I had been messing around with the port D pullups on a PIC18F4550 and it has this same issue as the bit is in the Port E Reg.

After hours of stuffing around with it i found your fix on here and set

ASM
BSF PORTe,7,0 'this sets port D pullups on as setting PortE.7=1 does not work
End ASM

User avatar
Jason
Posts: 50
Joined: Mon Mar 10, 2008 1:10 pm
Location: Australia

Post by Jason » Wed Feb 06, 2013 4:44 pm

Hi RadioT,
Would I be able to ask you to post a picture of the Oled GLCD that you are using with that SSD module? I've been looking to use an Oled GLCD in a project for ages. .

Pleeeese. ....

Thanks. ...

Jason.

Post Reply