PDA

View Full Version : 18F26K80 Serial setting sanity check and 4xPLL.



retepsnikrep
- 27th July 2022, 16:11
Does this look right for a pic runing at 80mhz? Thanks (I appreciate it is overclocked)

DEFINE HSER_RCSTA 90h 'Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h 'Enable transmit, BRGH = 1
DEFINE HSER_CLROERR 1 'Clear overflow automatically
DEFINE HSER_SPBRG 90 '57600 Baud @ 80MHz, -0.064% (346 Decimal = $15A)
define HSER_SPBRGH 1
BAUDCON1.3 = 1 'Enable 16 bit baudrate generator


I'm also trying to set the PIC to activate the PLL wiith a 20mhz external resonator. It seems stuck at 1/4 speed.
Note the program runs fine at 64mhz with the internal oscillator and 4 xPLL but I can't seem to get the PLL enabled with an external resonator.




CONFIG RETEN = OFF ; Ultra low-power regulator is Enabled (Controlled by SRETEN bit)
CONFIG INTOSCSEL = HIGH ; High power mode during Sleep
CONFIG SOSCSEL = DIG ; Disabled RC0 & RC1 I/0
CONFIG XINST = OFF ; Disabled
CONFIG FOSC = HS2 ; External 20mhz Resonator
CONFIG PLLCFG = ON ; Enabled



OSCCON = %00000000 'External Resonator
OSCCON2 = %00000000 'Clear
OSCTUNE = %01000000 'Enable PLL x 4 = 80mhz


Comments?

tumbleweed
- 27th July 2022, 23:12
Overclocking it 25% might be asking a lot, but assuming it's running at 80MHz those serial settings look to be correct.

You might have better luck powering up @ 20MHZ and then enabling the PLL by setting OSCTUNE = $40 once things are up and running.
I'd start with


config FOSC = HS2 ; HS oscillator (High power, 16 MHz - 25 MHz)
config PLLCFG = OFF ; Disabled
config FCMEN = OFF ; Disabled
config IESO = OFF ; Disabled
config PWRTEN = ON ; Enabled

retepsnikrep
- 28th July 2022, 06:43
No change with that so far. Hmmm??

tumbleweed
- 28th July 2022, 13:52
How are you verifying the freq?

Could you post your whole setup, including the config?

retepsnikrep
- 28th July 2022, 16:23
The code is massive.

I have a 1hz led timer1 interrupt flasher routine.

It's only working at 1/4 speed with the 20mhz resonator but works correctly at 64mhz with the internal osc.

retepsnikrep
- 28th July 2022, 16:25
'-------------------------- General 18F26K80 configuration ---------------------

#CONFIG
CONFIG RETEN = OFF ; Ultra low-power regulator is Enabled (Controlled by SRETEN bit)
CONFIG INTOSCSEL = HIGH ; High power mode during Sleep
CONFIG SOSCSEL = DIG ; Disabled RC0 & RC1 I/0
CONFIG XINST = OFF ; Disabled
CONFIG FOSC = HS2 ; External 20mhz Resonator
CONFIG PLLCFG = ON ; Enabled
CONFIG FCMEN = OFF ; Disabled
CONFIG IESO = OFF ; Disabled
CONFIG PWRTEN = OFF ; Disabled
CONFIG BOREN = OFF ; Disabled
CONFIG BORV = 3 ; 1.8V
CONFIG BORPWR = ZPBORMV ; ZPBORMV instead of BORMV is selected
CONFIG WDTEN = OFF ; WDT disabled in hardware; SWDTEN bit disabled
CONFIG WDTPS = 512 ; WDTPS 1:256 = 1.024 Second Timeout
CONFIG CANMX = PORTB ; ECAN TX and RX pins are located on RB2 and RB3, respectively
CONFIG MSSPMSK = MSK7 ; 7 Bit address masking mode
CONFIG MCLRE = OFF ; MCLR Enabled, RE3 Disabled
CONFIG STVREN = ON ; Enabled
CONFIG BBSIZ = BB2K ; 2K word Boot Block size
CONFIG CP0 = OFF ; Disabled
CONFIG CP1 = OFF ; Disabled
CONFIG CP2 = OFF ; Disabled
CONFIG CP3 = OFF ; Disabled
CONFIG CPB = OFF ; Disabled
CONFIG CPD = OFF ; Disabled
CONFIG WRT0 = OFF ; Disabled
CONFIG WRT1 = OFF ; Disabled
CONFIG WRT2 = OFF ; Disabled
CONFIG WRT3 = OFF ; Disabled
CONFIG WRTC = OFF ; Disabled
CONFIG WRTB = OFF ; Disabled
CONFIG WRTD = OFF ; Disabled
CONFIG EBTR0 = OFF ; Disabled
CONFIG EBTR1 = OFF ; Disabled
CONFIG EBTR2 = OFF ; Disabled
CONFIG EBTR3 = OFF ; Disabled
CONFIG EBTRB = OFF ; Disabled
#ENDCONFIG

'************************************************* ******************************
'************************** PBP Basic Defines ********************************
'************************************************* ******************************

DEFINE OSC 40 '80mhz (If overclocking at 96mhz set define to 48mhz ot if 80mhz set at 40mhz)
DEFINE NO_CLRWDT 1 'No Clear WDT Instructions added

'*********************** Direct Pic Register Settings ************************

OSCCON = %00001000 'External Resonator
OSCCON2 = %00000000 'Clear
HLVDCON = %00000000 'HLVCON Disabled

T1CON = %00110000 'Timer 1 Setup.
'TRISA = %11111111 'SET PORTA.0-7 Inputs
TRISA = %00111111 'SET PORTA.0-5 Inputs 6,7 Outputs
TRISB = %00001000 'SET PORTB.3 Input rest as Outputs
TRISC = %10010000 'SET PORTC.4,7 Inputs rest as Outputs

ANCON0 = %00000001 'Analog Inputs on A0
ANCON1 = %00000000 'No Analog Inputs

ADCON2 = %00011110 'SETUP ADC FOSC/64 LEFT JUSTIFY TAD 6
ADCON1 = %00000000 'SETUP ADC SET REFV to VDD & VSS AN0
ADCON0 = %00000011 'SETUP ADC & ENABLE ADC MODULE & START CONVERSION

SLRCON = %00000000 'Ports slew at standard rate!

SSPSTAT = %11000000 'Configure SPI Module
SSPCON1 = %00101010 'Enable SPI Master Mode Fosc/8 (10mhz) Clock idle low
SSPCON2 = %00000000 'Configure SPI Module

'bit 3-0 SSPM<3:0>: Master Synchronous Serial Port Mode bits(3)

'0010 = SPI Master mode: clock = FOSC/64 (1mhz)
'0001 = SPI Master mode: clock = FOSC/16 (4mhz)
'1010 = SPI Master mode: clock = FOSC/8 (8mhz at 64fosc) (10mhz at 80fosc) (12mhz at 96fosc)
'0000 = SPI Master mode: clock = FOSC/4 (16mhz) (Doesn't Work!)

'Eusart 1 (64mhz FOSC) 'Serial/Video Comms (16mhz x 4)
'DEFINE HSER_RCSTA 90h 'Enable serial port & continuous receive
'DEFINE HSER_TXSTA 24h 'Enable transmit, BRGH = 1
'DEFINE HSER_CLROERR 1 'Clear overflow automatically
'DEFINE HSER_SPBRG 22 '57600 Baud @ 64MHz, -0.44% (277 Decimal = $115)
'define HSER_SPBRGH 1
'BAUDCON1.3 = 1 'Enable 16 bit baudrate generator

''Eusart 1 (80mhz FOSC) 'Serial/Video Comms (20mhz x 4)
DEFINE HSER_RCSTA 90h 'Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h 'Enable transmit, BRGH = 1
DEFINE HSER_CLROERR 1 'Clear overflow automatically
DEFINE HSER_SPBRG 90 '57600 Baud @ 80MHz, -0.064% (346 Decimal = $15A)
define HSER_SPBRGH 1
BAUDCON1.3 = 1 'Enable 16 bit baudrate generator

''Eusart 1 (96mhz FOSC) 'Serial/Video Comms (24mhz x 4)
'DEFINE HSER_RCSTA 90h 'Enable serial port & continuous receive
'DEFINE HSER_TXSTA 24h 'Enable transmit, BRGH = 1
'DEFINE HSER_CLROERR 1 'Clear overflow automatically
'DEFINE HSER_SPBRG 160 '57600 Baud @ 96MHz, -0.080% (416 Decimal = $1A0)
'define HSER_SPBRGH 1
'BAUDCON1.3 = 1 'Enable 16 bit baudrate generator

retepsnikrep
- 29th July 2022, 18:49
I tried changing chip, no difference.

Still stuck at 1/4 speed and PLL not activating.

Hmm I wonder if my resonator marked 20mhz really is a 20mhz one!!

tumbleweed
- 30th July 2022, 13:46
I don't have any 20MHz xtals to try.

FWIW, I was able to get an 18F26K80 running at 80MHz with an external 20MHz osc into OSC1/CLKIN (using CONFIG = EC3).
The 4x PLL worked using either CONFIG PLLCFG = ON or CONFIG PLLCFG = OFF and setting OSCTUNE.PLLEN = 1.

I didn't even have a cap on the VDDCORE pin, and it worked with VDD down to 3V.

According to the datasheet EC and HS modes use the same clock tree, so I would think if you're using HS2 mode with a 20MHz xtal it would work too.

retepsnikrep
- 28th November 2022, 17:05
Hi all I'm still fiddling with this.

Any new ideas on why it might not run at 80mhz with external resonator?

tumbleweed
- 29th November 2022, 00:13
Did you try powering up with the PLL off and then turning it on later?

Try changing some of the CONFIG settings


CONFIG FOSC = HS2 ; HS oscillator (High power, 16 MHz - 25 MHz)
CONFIG PLLCFG = OFF ; Disabled
CONFIG PWRTEN = ON ; Enabled
CONFIG BOREN = SBORDIS ; Enabled in hardware, SBOREN disabled
CONFIG BORV = 0 ; 3.0V


and then at startup


'*********************** Direct Pic Register Settings ************************
OSCCON = %00000000 'SCS[1:0] = 00, Default primary oscillator
OSCCON2 = %00000000 'Clear

' enable the 4xPLL
delayms 100 ' allow some time for osc and power to stabilize
OSCTUNE.6 = 1 ' PLLEN = 1

CuriousOne
- 30th November 2022, 07:46
I had issues with 20mhz external oscillator as well - needed to fine tune capacitors for it to run.
Don't remember exactly, but had to replace recommended 22pf with 10pf or something like that.

Ioannis
- 30th November 2022, 09:15
may be you have too much stray capacitance on your pcb or breadboard.

Ioannis

HenrikOlsson
- 1st December 2022, 16:21
Crystals, crystal oscillators and ceramic resonators are three different things.


Crystals needs load capacitors (whose value CAN sometimes be picky). The crystal uses the oscillator inside the PIC.
Crystal oscillators have the crystal, load capacitors and oscillator in one package and drives the CLKIn pin of the PIC at roughly TTL levels. The oscillator IN the PIC is not used.
Ceramic resonator, like crystal oscillators, does not need external capacitors but unlike crystal oscillator, they do use the oscillator inside the PIC.


The PLL is a block that is tacked on after the oscillator or CLKIn signal.

Apparently Peter is using a resonator and if that resonator works when the PIC is configured to NOT use the PLL, ie it's configured to run and does run at 20MHz then I'd say the external circuitry is OK. As we know, the PIC is specified to run at up to 64MHz so expecting it to run at 80MHz might be a bit of a stretch. The fact that it works on one device doesn't mean it works on all devices. Then again, I would expect it to either not run at all or start up and randomly crash - not run at the base frequency.

A) Get it to work at whatever frequency resonator you put at it's input.
B) Get the PLL to work while using an inout frequency that does nor overclock the PIC.
C) Now that you know the PLL is indeed working, try the overclocking thing.

/Henrik.

tumbleweed
- 2nd December 2022, 11:56
the PIC is specified to run at up to 64MHz so expecting it to run at 80MHz might be a bit of a stretch.
Pretty much what I raised back in post 2. My part ran at 80 using an external clock+PLL, but that doesn't mean much.


Ceramic resonator, like crystal oscillators
You mention that crystal oscillators have logic-level outputs, so I think in your comparison a resonator is closer to a plain crystal (but as you mention they usually include the caps).

Acetronics2
- 16th August 2023, 16:05
Hi, Peter

does not your oscillator run or does not your program work as expected ??? Here is THE big question ...

80 Mhz looks to be "reachable" ( with careful design ... :rolleyes: ) with Pics but, as PBP "timed " commands are not available for more than 64Mhz clocking, some commands in your program can't work properly ... ( assembler Ghost in sight !!! )

sooo, to me, it's no use to go on the " overclocking way " ... without using some assembler.

Sorry ... Even I do love Hondas ( mine is a 2020 Civic 4D 1.5L CVT ... and I Have Driven only Hondas for ... 32 Years ! )

Alain

retepsnikrep
- 16th August 2023, 17:42
I will revisit all the replies. Thanks

retepsnikrep
- 19th August 2023, 14:14
I have the PIC running at 80 and 96mhz on the bench now.
Looks like it was a setting issue and not waiting for clock to settle before engaging PLL.
Thanks for the ideas/help.

tumbleweed
- 19th August 2023, 14:25
Great.

Keep us posted on how it goes. I'd be interested to know if you have any problems with peripherals operating at those speeds, esp the builtin CAN controller.

retepsnikrep
- 19th August 2023, 16:16
I also had a bad/fake 20mhz resonator. :mad:

I then tried some Farnell ones and decent crystals all worked ok, even at 96mhz.

The board actually worked in the car at 96mhz but that is overspec (12mhz) for the 10mhz MCP2515 CAN controllers SPI so I dialled the PIC back to 80mhz for reliability and (10mhz SPI)

So a decent increase in speed over 64mhz at zero cost so far. ;)

Now back to the other thread to do some code speed optimisation before I add additional functionality with my extra free time.

HenrikOlsson
- 19th August 2023, 16:38
I'll admit, I've been sceptical about relying on overclocking for something that is actually being used but I suppose if it works at 96MHz(!) then dialing it back to 80MHz does provide some margin.
Since it's going to end up in a car I'd probably test it at something other than room temperature before banking on the extra instruction cycles. I know you said it did work in the car at 96MHz but at what temperature?

Looking forward to the optimisation thread!

retepsnikrep
- 20th August 2023, 16:05
To be fair it worked ok at 64mhz without any optimisation I'm just being greedy and trying to free up/gain some cycles in advance of other stuff.
I have a heat gun and freeze spray so it's pretty easy to stress it.

It's been working fine in the summer sun for last two days at 80mhz.
30-35C in the car.