Page 1 of 1

PIC 18F26K22

Posted: Sun Sep 30, 2018 11:56 am
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

Re: PIC 18F26K22

Posted: Sun Sep 30, 2018 2:55 pm
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.

Re: PIC 18F26K22

Posted: Mon Oct 01, 2018 4:05 am
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

Re: PIC 18F26K22

Posted: Mon Oct 01, 2018 5:55 am
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

Re: PIC 18F26K22

Posted: Mon Oct 01, 2018 1:11 pm
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

Re: PIC 18F26K22

Posted: Mon Oct 01, 2018 1:20 pm
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

Re: PIC 18F26K22

Posted: Mon Oct 01, 2018 1:56 pm
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

Re: PIC 18F26K22

Posted: Mon Oct 01, 2018 5:10 pm
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

Re: PIC 18F26K22

Posted: Mon Oct 01, 2018 5:12 pm
by Corto
Sorry Benj,
Many thanks also, it is clear now for me.
Luc