PIC18F45K22 Clock setup

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
User avatar
jollybv
Flowcode v5 User
Posts: 374
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times
Contact:

PIC18F45K22 Clock setup

Post by jollybv »

Hi guys

I'm a bit confused I have been trying to set the clock speed to run internally at 64 Mhz but with no luck I see in the data sheet

• Precision 16 MHz Internal Oscillator Block:
- Factory calibrated to ± 1%
- Selectable frequencies, 31 kHz to 16 MHz
- 64 MHz performance available using PLL –
no external components required

If I set the Extended instruction set bit when I compile I get

Flasher_PIC18F45K22.c:
35: __config("__PROG_CONFIG", "pic18", 0x4, 0xFF);
^ (1504) the PIC18 extended instruction set was enabled but is not supported by this compiler

I have tried just about every setting with no luck is there anyone who can help please
Flasher_PIC18F45K22.fcfx
(7.96 KiB) Downloaded 10 times

medelec35
Valued Contributor
Valued Contributor
Posts: 9329
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2558 times
Been thanked: 3772 times
Contact:

Re: PIC18F45K22 Clock setup

Post by medelec35 »

Hi, Brian.
jollybv wrote:
Wed Jul 28, 2021 3:18 pm
If I set the Extended instruction set bit
The Extended instruction set must always be set to disabled as Flowcode Does not support this.
You also need to remember that setting the clock speed within Flowcode Project Options does not set the hardware speed.
The clock speed options are for setting delays and components with delays.
It is the OSCCON command within a C code block at the start of Main that sets the hardware internal clock speed, or crystal/ceramic resonator that sets the external hardware speed.
The PLL when enabled, normally sets the hardware oscillator at x4 speed.
To set the clock speed to 64MHz you need to set OSCCON to 64/4 = 16MHz
There is a component within Flowcode called Internal Oscillator Helper You can find that within Runtime, or you can use component search and enter intos
Select 16MHz.
That will give you the value of

Code: Select all

OSCCON=0x70;
:
Internal osc1.png
Internal osc1.png (21.83 KiB) Viewed 575 times
Select it all and right-click copy.
Add a C code clock at the top of main and paste

Code: Select all

OSCCON=0x70;
OSCCON Setting 16MHz.png
OSCCON Setting 16MHz.png (27.25 KiB) Viewed 558 times
I have noticed you have the Project clock set to 64000000 which is correct.
Martin

User avatar
jollybv
Flowcode v5 User
Posts: 374
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times
Contact:

Re: PIC18F45K22 Clock setup

Post by jollybv »

Hi Martin

Thanks for the explanation it has helped a lot I learnt something new, I always thought setting the clock in the project options set everything up but now I know why I have always battled setting the clock speed.

User avatar
jollybv
Flowcode v5 User
Posts: 374
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times
Contact:

Re: PIC18F45K22 Clock setup

Post by jollybv »

Hi Martin

I don't know if I'm being stupid but I have been trying to get the UART to work I have connected a display to the hardware an that works but the UART refuses. It send data but garbage (øxxxøxøxøx€) and I'm almost sure it is something to do with timing. I have sent the day trying to get this to work but alas nothing. I would use another chip, but I have 50 of these chips so its not an option how do you think i can sort this?
Flasher_PIC18F45K22.fcfx
(11.76 KiB) Downloaded 10 times

medelec35
Valued Contributor
Valued Contributor
Posts: 9329
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2558 times
Been thanked: 3772 times
Contact:

Re: PIC18F45K22 Clock setup

Post by medelec35 »

Hi, Brian
First step with a new project.
Always spend a few mins doing the one sec flasher test.
Otherwise it could end up wasting hours if your hardware or clock speed is incorrect.
I have noticed you did that with 500ms delays.
Can you time the flashing LED and let me know how long each flash is?
Do you have a scope or logic analyser
Martin

User avatar
jollybv
Flowcode v5 User
Posts: 374
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times
Contact:

Re: PIC18F45K22 Clock setup

Post by jollybv »

Hi Martin

I set the scope to 1 second per division and it give me just under 2s, but what I can understand is that the display on the board is displaying correct.
scope shot 1.png
scope shot 1.png (50.96 KiB) Viewed 538 times

medelec35
Valued Contributor
Valued Contributor
Posts: 9329
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2558 times
Been thanked: 3772 times
Contact:

Re: PIC18F45K22 Clock setup

Post by medelec35 »

If you are using a 500ms delay then the 2 seconds states that the PLL is not being enabled.
Displays are forgiving with osc speed, UART is not.
From memory, there are devices that require a line of c code to enable PLL.
I will see if I can find out what it is.
Martin

User avatar
jollybv
Flowcode v5 User
Posts: 374
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times
Contact:

Re: PIC18F45K22 Clock setup

Post by jollybv »

Thanks Martin

Will wait to hear from you.

medelec35
Valued Contributor
Valued Contributor
Posts: 9329
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2558 times
Been thanked: 3772 times
Contact:

Re: PIC18F45K22 Clock setup

Post by medelec35 »

Hi, Brian.
Within the OSCCON C code block, can you also add

Code: Select all

st_bit(OSCTUNE,PLLEN);
Martin

User avatar
jollybv
Flowcode v5 User
Posts: 374
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times
Contact:

Re: PIC18F45K22 Clock setup

Post by jollybv »

Wow Martin
That worked I really appreciate your help, now to see if the SPI works in my other program on the board

medelec35
Valued Contributor
Valued Contributor
Posts: 9329
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2558 times
Been thanked: 3772 times
Contact:

Re: PIC18F45K22 Clock setup

Post by medelec35 »

That's excellent news,
I'm sure your UART should work now.
If it does not, I will have another trick up my sleeve.
Thanks for keeping us updated.
Martin

User avatar
jollybv
Flowcode v5 User
Posts: 374
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times
Contact:

Re: PIC18F45K22 Clock setup

Post by jollybv »

No need for more tricks UART working like a dream you a genius thanks again. Next is to get the spi to read a Max 6675 but I will deal with that next week.

medelec35
Valued Contributor
Valued Contributor
Posts: 9329
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2558 times
Been thanked: 3772 times
Contact:

Re: PIC18F45K22 Clock setup

Post by medelec35 »

Hi Brian
jollybv wrote:
Thu Jul 29, 2021 8:01 pm
you a genius thanks again
Thank you for that. I wish :lol:
I just needed my memory jogging as I have used that command in the past.
Martin

User avatar
jollybv
Flowcode v5 User
Posts: 374
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times
Contact:

Re: PIC18F45K22 Clock setup

Post by jollybv »

Hi Martin

I still seem to have a slight timing problem and it is very weird. I have set the board to 16Mhz internal clock and the SPI prescale Fosc/16 the weird part is that if I connect the scope to the SCK on the max6675 it reads the correct temperature. When I take the scope probe off then I read back the wrong temperature so I'm thinking that when i put the probe on the SCK it dose something to the clock frequency. I am also using the uart to debug and that is working fine so I'm very lost now as to what is causing this.

medelec35
Valued Contributor
Valued Contributor
Posts: 9329
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2558 times
Been thanked: 3772 times
Contact:

Re: PIC18F45K22 Clock setup

Post by medelec35 »

Hi Brian,
jollybv wrote:
Sun Aug 15, 2021 8:32 am
When I take the scope probe off then I read back the wrong temperature so I'm thinking that when i put the probe on the SCK it dose something to the clock frequency. I am also using the uart to debug and that is working fine so I'm very lost now as to what is causing this.
Could it be the probe is loading the pin down, so improving the shape of the clock pulse.
What value of pullup resistors are you using?
OSC Frequency sounds ok a UART being asynchronous is extremely fussy with clock frequencies.
Martin

User avatar
jollybv
Flowcode v5 User
Posts: 374
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times
Contact:

Re: PIC18F45K22 Clock setup

Post by jollybv »

Hi Martin

I am not using any pull up resistors as all the documents say you don't need pull ups for SPI but I did put a 10 pull up in and it did not change anything so what I have done is put a 33pf cap to ground and it seems to work right. The only problem I'm having now is that if the K probe outer shield is connected to ground it gives me the false readings again.

medelec35
Valued Contributor
Valued Contributor
Posts: 9329
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2558 times
Been thanked: 3772 times
Contact:

Re: PIC18F45K22 Clock setup

Post by medelec35 »

jollybv wrote:
Tue Aug 17, 2021 7:28 am
am not using any pull up resistors as all the documents say you don't need pull ups for SPI
Sorry, yes that is true.
I have been working with I2C and had that on my mind.
Sounds like it could be grounding issue?
would a 100nf across the supply help?
There could be some ringing going on and the capacitance of the probe is reducing it.
You could try using a series resistor on the line that's casing the issue, e.g 56R.
Are you using long wires between SPI board and micro?
Martin

User avatar
LeighM
Matrix Staff
Posts: 2173
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: PIC18F45K22 Clock setup

Post by LeighM »

Have you also checked (or tried variations for) Clock Phase, Polarity and Sample point?

User avatar
jollybv
Flowcode v5 User
Posts: 374
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times
Contact:

Re: PIC18F45K22 Clock setup

Post by jollybv »

Hi
Thanks I'm going to play around with this and see what I can do I have checked around and many people are having problems with the grounding of the probe using the max6675. So I will see if I can find a solution somewhere out there.

Post Reply