OverClock. at Runtime ~90MHz

Post here first, or if you can't find a relevant section!
alexandros
Posts: 42
Joined: Mon Oct 02, 2017 6:51 pm

OverClock. at Runtime ~90MHz

Post by alexandros » Thu Nov 23, 2017 7:12 am

Hello there ,
is there any way to overclock the speed of the CPU at Runtime , but not with fullspeed 128Mhz , but somewhere around like 90Mhz.

User avatar
zoomx
Posts: 541
Joined: Mon Apr 27, 2015 2:28 pm
Location: Mt.Etna, Italy

Re: OverClock. at Runtime ~90MHz

Post by zoomx » Thu Nov 23, 2017 3:32 pm

I wander if it is also possible to go down, in other words it it is possible to change clock speed at runtime, taking in account that serial baudrate and other things will change too.

User avatar
RogerClark
Posts: 7465
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: OverClock. at Runtime ~90MHz

Post by RogerClark » Thu Nov 23, 2017 8:13 pm

The LibMaple Core is not designed to allow changes to clock frequency at runtime

If you look at the places where the F_CPU definition is used

https://github.com/rogerclarkmelbourne/ ... _cpu&type=

It’s used in multiple places

All of those would need to be changed to use a variable rather than a definition, and some macros changed to functions etc

Additionally, parts of the system startup code e.g. places that set the hardware clock PLL would need to be run, and I susoect the startup code would need to be broken into smaller modules, or you would need to duplicate some code


It’s an interesting project if you want to take it on, as you could also integrate stopping and restarting the USB, so the processor could switch to overclocked for a short period, to do intensive processing, then switch back to 72MHz to run USB

Or, it may be possible to run at 128MHz for a few milliseconds without impacting the USB at all.

Please bear in mind, that at 96Mhz the USB will not work. It only works at 72MHz and 48MHz as this is a limitation in the MCU internal hardware

alexandros
Posts: 42
Joined: Mon Oct 02, 2017 6:51 pm

Re: OverClock. at Runtime ~90MHz

Post by alexandros » Fri Nov 24, 2017 8:20 am

RogerClark wrote:
Thu Nov 23, 2017 8:13 pm

Or, it may be possible to run at 128MHz for a few milliseconds without impacting the USB at all.
Thanks Roger!!

Any code snippet for that??

edogaldo
Posts: 285
Joined: Fri Jun 03, 2016 8:19 am

Re: OverClock. at Runtime ~90MHz

Post by edogaldo » Fri Nov 24, 2017 9:03 am

Looking at the usage of F_CPU looks like it should be enough to define F_CPU as a multiple of HSE (from 1*HSE to 16*HSE) to get the expected clocking (in a static way though).
Instead I'm in doubt with:

Code: Select all

#define SYSTICK_RELOAD_VAL (F_CPU/1000) - 1
I think it should be better as:

Code: Select all

#define SYSTICK_RELOAD_VAL (F_CPU/1000 - 1)
because else there's the risk that, once converted the macro, the resulting expression will not be the expected one.

Cheers, E.

User avatar
RogerClark
Posts: 7465
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: OverClock. at Runtime ~90MHz

Post by RogerClark » Fri Nov 24, 2017 10:32 am

alexandros wrote:
Fri Nov 24, 2017 8:20 am
RogerClark wrote:
Thu Nov 23, 2017 8:13 pm

Or, it may be possible to run at 128MHz for a few milliseconds without impacting the USB at all.
Thanks Roger!!

Any code snippet for that??
No. I'm not aware of any code to change the clock speed during at runtime.

User avatar
Pito
Posts: 1627
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: OverClock. at Runtime ~90MHz

Post by Pito » Fri Nov 24, 2017 11:19 am

You can change the cpu clock at runtime with F103.
I did it on F103 in past (with mecrisp forth) and it worked perfectly. I was changing on-the-fly the clock in a loop in a sequence like 72MHz/8MHz/128MHz/48MHz without a crash. Mind the clock's PLL setting (the phase loop needs to lock itself at the new freq) takes some time thus there always will be a small "time gap" while the PLL locks.
You have to take the clock setting routine from the core, and you want to add ticks and baudrate settings change such you stay consistent with ms/micros and uart speed. I did not test with USB as it is supported by a few clock freqs only.

Code: Select all

void set_clock(uint32_t clk_khz, uint32_t baudrate) {
set_cpu_clk(clk_khz);  // see core
set_ticks(clk_khz);  // see core
set_baudrate(baudrate);  // see core
}
..
#define baudrate 115200;
set_clock(8000, baudrate);
set_clock(128000, baudrate);
set_clock(48000, baudrate);
set_clock(72000, baudrate);
set_clock(96000, baudrate);
..
Last edited by Pito on Fri Nov 24, 2017 11:54 am, edited 2 times in total.
Pukao Hats Cleaning Services Ltd.

alexandros
Posts: 42
Joined: Mon Oct 02, 2017 6:51 pm

Re: OverClock. at Runtime ~90MHz

Post by alexandros » Fri Nov 24, 2017 11:51 am

WOWW pito!! :shock: :o :o

User avatar
Pito
Posts: 1627
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: OverClock. at Runtime ~90MHz

Post by Pito » Fri Nov 24, 2017 11:57 am

The big Q is why do you need such on-the-fly clock switch.

Energy?? You may run BluePill at 96MHz easily and go sleep when needed.
The total energy spent might be much lower than when switching between various freqs.. ;)

Or do you want to have the USB available (ie at 48/72MHz) and only switch to 96/128MHz in order to speed up some calcs??
Pukao Hats Cleaning Services Ltd.

alexandros
Posts: 42
Joined: Mon Oct 02, 2017 6:51 pm

Re: OverClock. at Runtime ~90MHz

Post by alexandros » Fri Nov 24, 2017 12:08 pm

Pito wrote:
Fri Nov 24, 2017 11:57 am
The big Q is why do you need such on-the-fly clock switch.

Energy?? You may run BluePill at 96MHz easily and go sleep when needed.
The total energy spent might be much lower than when switching between various freqs.. ;)

Or you do want to have USB available (ie at 48/72MHz) and switch to 96/128MHz in order to speed up some calcs??
i just want to test if i get good results in specific parts of the code with 96MHZ and the rest with 72
i notice thought a temperature raise in CPU when overclocking OK thats normal

Post Reply