PIC18F45K22 Clock setup
Moderator: Benj
- 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
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
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
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: PIC18F45K22 Clock setup
Hi, Brian.
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:
Select it all and right-click copy.
Add a C code clock at the top of main and paste
I have noticed you have the Project clock set to 64000000 which is correct.
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;
Add a C code clock at the top of main and paste
Code: Select all
OSCCON=0x70;
Martin
- 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
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.
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.
- 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
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?
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?
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: PIC18F45K22 Clock setup
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
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
- 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
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.
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.
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: PIC18F45K22 Clock setup
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.
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
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: PIC18F45K22 Clock setup
Hi, Brian.
Within the OSCCON C code block, can you also add
Within the OSCCON C code block, can you also add
Code: Select all
st_bit(OSCTUNE,PLLEN);
Martin
- 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
Wow Martin
That worked I really appreciate your help, now to see if the SPI works in my other program on the board
That worked I really appreciate your help, now to see if the SPI works in my other program on the board
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: PIC18F45K22 Clock setup
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.
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
- 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
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.
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: PIC18F45K22 Clock setup
Hi Brian
I just needed my memory jogging as I have used that command in the past.
Thank you for that. I wish
I just needed my memory jogging as I have used that command in the past.
Martin
- 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
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.
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.
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: PIC18F45K22 Clock setup
Hi Brian,
What value of pullup resistors are you using?
OSC Frequency sounds ok a UART being asynchronous is extremely fussy with clock frequencies.
Could it be the probe is loading the pin down, so improving the shape of the clock pulse.jollybv wrote: ↑Sun Aug 15, 2021 8:32 amWhen 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.
What value of pullup resistors are you using?
OSC Frequency sounds ok a UART being asynchronous is extremely fussy with clock frequencies.
Martin
- 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
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.
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.
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: PIC18F45K22 Clock setup
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
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: PIC18F45K22 Clock setup
Have you also checked (or tried variations for) Clock Phase, Polarity and Sample point?
- 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
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.
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.
- Bachman
- Posts: 116
- Joined: Sun Sep 07, 2014 11:37 am
- Location: Hungary
- Has thanked: 9 times
- Been thanked: 53 times
- Contact:
Re: PIC18F45K22 Clock setup
Maybe not too late info. Check the datasheets. The trick is in the SPI waveform modes.