Change OSC FQ in code

Post your requests and ideas on the future development of mikroC.
Post Reply
Author
Message
jumper
Posts: 466
Joined: 07 Mar 2007 14:36

Change OSC FQ in code

#1 Post by jumper » 02 Feb 2009 09:48

Hi,

Now when there are PICs with so many different OSC confirgurations I would like to have a funktion mikroC that allows me to change the OSC frequency in the compiler from the code. I have a project now that will run some part of the code on 40 Mhz and other parts of the code at 31kHz so save power.

Since I can (have to) setup the pic registers to choose the configuration I would like to have the ability to tell the compiler what is done.
i.e.

Change_OSC_FQ(40000000);

This will only affect the internal parts of the compiler to make sure the delays, lcd and other things are run at normal speed, it has nothing to do with the PIC's registers. Of couse this will bloat the code by maybe having 2 or more LCD libraries.. one for each speed but that is up the the person writing the PIC software :-)

If I want to change to 31kHz I would setup the PIC and tell the compiler

Change_OSC_FQ(31250);

Please, Please, Please, Please, Please, Please, Please, Please, Please, Please, Please, Please, it would be a killer functionality that would solve these new problems...

/Per

Boghdady
Posts: 8
Joined: 18 Jan 2008 12:09

supposed solution

#2 Post by Boghdady » 02 Feb 2009 12:50

I think you can put for example 2 crystals in your circuit and using a pin from any port you can toggle between them.
It is a hardware solution... :lol:

jumper
Posts: 466
Joined: 07 Mar 2007 14:36

hmmm

#3 Post by jumper » 02 Feb 2009 13:12

Maybe I didn't explain well enough.

Look at the 18F46K20 as an example and let us only use the internal oscillator in this example.

Internal Oscillator Block:
- 8 user selectable frequencies, from 31 kHz to
16 MHz
- Provides a complete range of clock speeds
from 31 kHz to 64 MHz when used with PLL

So just by setting the registers in this PIC in different ways I can choose how fast it should run. However in the project settings of mikroC there is the oscillator setting so the compiler can get all timing right during compilation. If you set it to 40 MHz in the project settings and then change speed inside the code to i.e 4 Mhz all delays will be 10 times too long. Probably the LCD will stop working.. or acting really slow and so on.

If we had a compiler directive that could change the project setting from the code it would be possible to setup the pic to a new FQ and then tell the compiler what has been done. Then the compiler will use this speed in calculating timing until we tell it to change again....

The HW is already there... it is just a question how we can use it in a mixed osc environment.


"#define OSC_SPEED 31250" to make the compiler calculate with this setting until further notice....and then it is up to the SW maker to make sure he has selected the right FQ for the task at hand.

Boghdady
Posts: 8
Joined: 18 Jan 2008 12:09

I understand the problem

#4 Post by Boghdady » 03 Feb 2009 09:55

I understand the problem but it is to hard to solve...
I think there is no compiler directive to do that but if you find it please let me know

Post Reply

Return to “mikroC Wish List”