News:

Let's find out together what makes a PIC Tick!

Main Menu

PORT A6 and A7 Problem on PIC18F27Q43

Started by laserline, May 31, 2023, 03:52 PM

Previous topic - Next topic

laserline

Hi folks!

I am having serious problems making the RA6 and RA7 ports function like standart I/O ports on the PIC18F27Q43. Yes, I am working with the HFINTOSC, set the fuses correctly and not using any peripheral that in principle could use the same port. TRIAS, ANSELA are also set correctly ant the USART is disabled.
FEXTOSC = Off
RSTOSC = HFINTOSC_64MHZ
CLKOUTEN = Off

I've read the datasheet countless times and I am really stucked.
Any ideas?? please...
Obs. I also used another chip (new) ... same result. :|

John Lawton

Have you cleared the relevant ANSELx (and ODCONx) registers?

JonW

May not be related but when we used the q10 parts there were a crap load of errata problems and we had the devices with the issues and more that were related to the setup of the SFR..

Think it was Tumbleweed or Les who said... avoid newer devices if you want it to work first time as the newer devices are riddled with bugs.

Try to create a very simple program that toggles the IO as it may br related the setup (as John said)  or PPS or even be a rare bug in the compiler, doing it this way is easier to debug the ASM.  Post the code too so others can take a look

J

laserline

Yes John, yes, ANSELA = 0x00 and ODCON in its default (0).

Tomorrow I will try a very simple program but I am not believing that I will succeed, I must be missing something, and it doesn't seem to be something very evident.

Unfortunately switching to another part is not an option as this one has all the features I need.

Best!

top204

The compiler sets the pins to standard digital mode before a user's program starts, and the commands to perform that task are at the end of each device's .def file. For the PIC18F27Q43 device, its .def file has the BASIC commands listed below in it:

'
'-----------------------------------------------------------------------------------
' Make the device's I/O pins digital (if required) before the main program starts
' This can be added too by the user and shared on the forum
'
#IfnSym __SYSCOM_LIBRARY_OFF_       ' Has the library been disabled in the compiler?
    ANSELA = $00
    ANSELB = $00
    ANSELC = $00
    ANSELE = $00
    SLRCONA = $00
    SLRCONB = $00
    SLRCONC = $00
    SLRCONE = $00
    INLVLA = $00
    INLVLB = $00
    INLVLC = $00
    INLVLE = $00
    CM1CON0 = $00
    CM2CON0 = $00
#EndIfSym

Just to make sure there are no quirks with the device's I/O lines, I wrote a simple test program and programmed a PIC18F27Q43 with it. The test code listing I used is shown below:

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Demonstrate using the two OSC pins as digital I/O pins when operating with the PIC18F27Q43 device's internal oscillator.
'
' Written for the Positron8 compiler by Les Johnson.
'
    Device = 18F27Q43                               ' Tell the compiler what device to compile for
    Declare Xtal = 64                               ' Tell the compiler what frequency the device will be operating at (in MHz)

'--------------------------------------------------------------------------------------------
' The main program starts here
' Flash two LEDs attached to PORTA.6 and PORTA.7
'
Main:
    Do                                              ' Create a loop
        PinHigh PORTA.6                             ' \
        PinHigh PORTA.7                             ' | Illuminate the LEDs for half a second
        DelayMS 500                                 ' /

        PinLow PORTA.6                              ' \
        PinLow PORTA.7                              ' | Extinguish the LEDs for half a second
        DelayMS 500                                 ' /
    Loop                                            ' Do it forever

'--------------------------------------------------------------------------------------------
' Set the config fuses to use the internal oscillator at 64MHz on a PIC18F27Q43 device
' Its OSC pins can also be used as digital I/O pins
'
Config_Start
    FEXTOSC = Off                   ' External oscillator not enabled
    RSTOSC = HFINTOSC_64MHZ         ' HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1
    CLKOUTEN = Off                  ' CLKOUT function is disabled
    PR1WAY = Off                    ' PRLOCKED bit can be set and cleared repeatedly
    CSWEN = On                      ' Writing to NOSC and NDIV is allowed
    FCMEN = On                      ' Fail-Safe Clock Monitor enabled
    MCLRE = INTMCLR                 ' MCLR pin enabled
    PWRTS = PWRT_64                 ' PWRT set at 64ms
    MVECEN = Off                    ' Interrupt controller does not use vector table to prioritze interrupts
    IVT1WAY = Off                   ' IVTLOCKED bit can be cleared and set repeatedly
    LPBOREN = On                    ' Low-Power BOR enabled
    BOREN = SBORDIS                 ' Brown-out Reset enabled
    BORV = VBOR_2P85                ' Brown-out Reset Voltage (VBOR) set to 2.8V
    ZCD = Off                       ' ZCD module is disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
    PPS1WAY = Off                   ' PPSLOCKED bit can be set and cleared repeatedly (subject to the unlock sequence)
    STVREN = On                     ' Stack full/underflow will cause reset
    LVP = Off                       ' HV on MCLR/VPP must be used for programming
    XINST = Off                     ' Extended Instruction Set and Indexed Addressing Mode disabled
    WDTCPS = WDTCPS_31              ' Divider ratio 1:65536. software control of WDTPS
    WDTE = Off                      ' WDT Disabled
    WDTCWS = WDTCWS_7               ' Window always open (100%). Software control. Keyed access not required
    WDTCCS = SC                     ' Software Control
    BBSIZE = BBSIZE_512             ' Boot Block size is 512 words
    BBEN = Off                      ' Boot block disabled
    SAFEN = Off                     ' SAF disabled
    Debug = Off                     ' Background Debugger disabled
    WRTB = Off                      ' Boot Block not Write protected
    WRTC = Off                      ' Configuration registers not Write protected
    WRTD = Off                      ' Data EEPROM not Write protected
    WRTSAF = Off                    ' SAF not Write Protected
    WRTAPP = Off                    ' Application Block not write protected
    Cp = Off                        ' PFM and Data EEPROM code protection disabled
Config_End

As I type this reply, I can see the two LEDs attached to pins PORTA.6 and PORTA.7 flashing on an Amicus18 board beside me with its crystal removed to make the pins accessable as I/O pins, and the microcontroller replaced with a PIC18F27Q43 type.

laserline

Done. I replaced my Breadboard and now it's working! It seems that Operating @64MHz needs some extra decoupling. What I do was to ground the botton metal plate of the breadboard, this get rid of interferences and it's a good practice.
Thanks a lot!!

top204

#6
Be careful of the cheap chinese solderless breadboards. They are absolutely dreadful and have caught me out a couple of times, until I figured out why things were not working as they should on them. Their connections are so feeble they open up after a few component inserts, so the component leads do not make good contact. Also, their conductivity is not very good. I hate to think what metals they are using, but they are certainly not valid types for the job.

The same with their wires.... They are certainly not copper because they cannot be soldered!

I have used devices operating at 200MHz on the better quality solderless breadboards with no problems and minimum decoupling used. I know they cost a little more, but they last for years and give good service, so it is better to save up and buy a better quality one if available money is short. My piece of advice is "Stay away from chinese, mass produced, Crap. With most things made in china, you may as well put your money down the toilet bowl, and "never" trust a CE mark on them!". :-) And I do not mean that as a disrespect to the chinese people, but I certainly do to the chinese companies who produce the crap, and know they are producing crap!