News:

;) This forum is the property of Proton software developers

Main Menu

PIC18F24K42 Port A Simple problem.

Started by Maggie, Sep 28, 2021, 08:29 AM

Previous topic - Next topic

Maggie

Hello,

I am having a issue with what I think is a very simple and basic problem, but after many hours of debugging I just cannot seem to find the cause.

What I am simply trying to do is set Port A as a digital GPIO port with the lower 4 bits (0,1,2 & 3) set to output and the the upper 4 bits (4,5,6,7) set to input.
As a simple test I have hooked up 4 LEDS on the four outputs which work fine, then simply read the inputs and turn on the four LEDS to replicate whats on the four inputs.

These are my results.

All 4 outputs work.
inputs on A.4 and A.5 can be read and work ok.
Inputs on A.6 and A.7 do not work, these always read as low. Even when I put 5V high signal on the pin (A.6 or A.7)

I have not seen this with other PICs, and have always just turned off or configured the peripherals to allow the ports to function how I want.
The K42 device does have PPS remappable pins, which I have checked, although positron states PPS is not supported on this device.

I can only assume that somewhere another peripheral is enabled and the two suspect pins are being routed to some other digital or analog input.
But I just cannot find what. I have turned off and configured everything I can think of and read in the data sheet, but now I am just going round in circles.

According to the data sheet for the pIC18F24K42 the only pin functions on A.6 and A.7 are ANA5 and ANA6, ICA6 and ICA7, and CLKout and CLKin
The clock is set to and internal clock at 8MHz which works fine, interrupts are turned off and all Analog channels are turn off.

I know I am just missing something very simple here, but I have run out of ideas now, so I thought posting on here might be a good start.

Any ideas?

Thanks

charliecoutas

Maggie

There are some bits in OSCCON that may be the problem. The following is for 18F26K22 but I would think your device is similar. Check these bits for your device.

            OSCCON  = %01110000                                           
            Nop
            OSCCON2 = %10000100
            Nop                               
            Set OSCTUNE.6                                                                

Charlie

Stephen Moss

It would help if you had posted as a minimum your device setup so that we could check it for any errors/ommissions otherwise you may get advice to do things you have already done, that said...
The compiler should automatically set all analogue pins to digital, personally I like to set that anyway, just to be sure so if you have not already done so add ANSELA = $00.

The pins with the extra peripherals on are A4 and A5 and which I would think the most problematic yet you say they are working. A6 and A7 just have the clock/Xtal functions which should be disabled if you have the internal oscillator selected, are you certain you have the TRIS registers setting correct (TRISA=$F0).
Try including...
OSCCON=$70    'HFOSC @ 8MHz, Primary clock selected via Config Bits
OSCOCN2 = $00  'HFOCS is already set to 8MHz so you are not taking the clock from the PLL and you don't need the Primary Oscillator Driver circuit on as you are using the Internal Oscillator
OSCTUNE = $00  'You should not have to do this as the default is PLL Disabled but it does not hurt to include it so you know what it's setting is

As you have not provided any code, in case the problem lies there try...

Dim Input_Data as byte
Start:
Input_Data = PortA
Input_Data = Input_Data >> 4  'Shift Data input bits to output bits
PortA = Input_Data
Goto Start

Maggie

Hi,

Thank you for your replies.

All fixed now with you help.
I went back through the data sheet and checked every bit of OSCONN1, OSCCON2 and OSCCON3.

I have now set these to the following, which seems to have fixed the problem. Looking at it I had what I had did not add up. Think I must have accidently changed these because I originally went through them when I started.
Found that they were just totally wrong. But all good now, all though some bits are read only this works perfectly at 8MHz with the internal clock.

osccon1 = %01110000
osccon2 = %00000000
osccon3 = %00000000

Thanks again.

oh,next time I will post the original code, which would have course helped in the first place.



charliecoutas

Glad we could help Maggie. It is always frustrating how simple things can be overlooked and then become big problems.

Best regards
Charlie