PIC 18F26K22

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
Corto
Posts: 26
Joined: Thu Sep 04, 2014 7:01 am
Contact:

PIC 18F26K22

Post by Corto »

Hello All,
I would like the speed clock of the PIC to be set to 64 MHz.
I wrote in C Code "OSCCON = 0x7C", General Option (in Flowcode) 16000000Hz clock speed and Configure 0x1 = 39ff; 0x2 = 0x3cf9; 0x3 = 0x9bff
My problem is that I am not sure of my 0x7C and I hesitate with 0x74 (OSCCON), or maybe I am not good with these 2 proposals.
I admit that I am a little lost.
Thank you in advance for your answer.
Luc

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8874
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Contact:

Re: PIC 18F26K22

Post by medelec35 »

7C looks like it should work.
Looking at the datasheet it states:
Datasheet wrote:Unlike external clock modes, when internal clock
modes are enabled, the PLL can only be controlled
through software. The PLLEN control bit of the
OSCTUNE register is used to enable or disable the
PLL operation when the HFINTOSC is used.
You could try adding

Code: Select all

st_bit(OSCTUNE,PLLEN);
to C code block
once that is done, just run 1 second clock flasher.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Corto
Posts: 26
Joined: Thu Sep 04, 2014 7:01 am
Contact:

Re: PIC 18F26K22

Post by Corto »

Thanks a lot Martin, I shall try your adding proposal.
through my question and your answer, I discovered the "IntOsc Helper", (it's good to ask questions and especially to get good answers). unfortunately in the Helper it is not possible to go above 16 MHz, the Helper does not take into account the PLL.
on the other hand I have another question, I would use the EEPROM to memorize the value of a counter that will go beyond 255 (ff), how to do?
In detail, I coupled an encoder on the axis of an electric motor.
I consulted the forum but I did not find anything about it, otherwise memorizing decimal.
many thanks in advance
Luc

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8874
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Contact:

Re: PIC 18F26K22

Post by medelec35 »

Your welcome.
Corto wrote:unfortunately in the Helper it is not possible to go above 16 MHz, the Helper does not take into account the PLL.
You can use the helper to set the Speed at 16MHz.
Then enable PLL in configuration settings.
according to osccon helper the value should be 0x70.
But as I stated earlier 0x7c will work.
The difference (0xC) is only

Code: Select all

Oscillator Start-up Time-out Status bit
&

Code: Select all

HFINTOSC Frequency Stable bit 
Both of which are read only so would not have affected the speed of oscillator.
Corto wrote: I would use the EEPROM to memorize the value of a counter that will go beyond 255 (ff), how to do?
You will need to separate the inter value into two seperate bytes which will then take up two EEPROM locations instead of one.
Take a look at this thread
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Corto
Posts: 26
Joined: Thu Sep 04, 2014 7:01 am
Contact:

Re: PIC 18F26K22

Post by Corto »

Many thanks Martin,
For the osccon that's OK, thanks.
but for the EEPROM, I took a look at the thread and I don't understand, because you wrote :
ByteHigh = (IntValue/ 256)
ByteLow = IntValue - ByteHigh* 256
for exemple, IntValue = 1000; ByteHigh = 1000/256 = 3.9; ByteLow = 1000 - (3.9*256) = 0.
I am sorry but something is wrong, I can't separate the value.
Sorry a new time
Luc

User avatar
Benj
Matrix Staff
Posts: 14837
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: PIC 18F26K22

Post by Benj »

Hello,

Bytes can only hold integer values so this is incorrect.

Code: Select all

ByteHigh = 1000/256 = 3.9
It would actually be like this.

Code: Select all

ByteHigh = 1000/256 = 3
ByteLow = 1000 - (3*256) = 232

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8874
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Contact:

Re: PIC 18F26K22

Post by medelec35 »

Corto wrote:for the EEPROM, I took a look at the thread and I don't understand, because you wrote :
ByteHigh = (IntValue/ 256)
ByteLow = IntValue - ByteHigh* 256
Personally, I would use:

Code: Select all

ByteLow = IntValue & 0xFF 
ByteHigh = (IntValue >> 8) & 0xFF 

Code: Select all

IntValue = ByteLow+(ByteHigh << 8) 
Bit shifiting i.e << and >> is much more efficient than using division or muliplication.
Also if interested in storing floats then I would use

Code: Select all

FloatToString$()
function then follow this thread
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Corto
Posts: 26
Joined: Thu Sep 04, 2014 7:01 am
Contact:

Re: PIC 18F26K22

Post by Corto »

thank you very much Martin, I finally understood!
I need time, but now it's ok.
I will follow your advice and avoid using divisions and multiplication
the bit shifting will do the trick.
Many thanks a new time
Luc

Corto
Posts: 26
Joined: Thu Sep 04, 2014 7:01 am
Contact:

Re: PIC 18F26K22

Post by Corto »

Sorry Benj,
Many thanks also, it is clear now for me.
Luc

Post Reply