D1 mini switch between 80mhz to 160mhz in code?

Hello, I was wondering If it is possible to have some kind of push button press to switch between 80mhz to the 160mhz? I know in board mange I can select 80mhz or 160mhz. I searched online and the ones I did mange to find is for the esp32.

Joseph

The obvious question is : "why would you want to ?"

Answer is why not. I was wondering what would be the best way that I can change it while in code instead of changing it in board manger and have to keep on reuploading it.

Joseph

Not exactly. Maybe because there is no good reason. I, like @Deva_Rishi, do not see a meaningful reason.

Honestly I don't have a good reason. I wanted to know If it can be done in code without having to be done changing it in the ide and keep reuploading the code. It is for a future project coming up. for a smart watch.

Joseph

I wouldn’t think it could because that clock is used by the compiler to set things like the converting how the delay code is handled. I think the boot loader also sets the configuration bits in the processor that can’t be accessed programatly by code.

If only that processor had a real data sheet for it instead of the pathetic excuse for a data sheet that it has.

Hey Grumpy_Mike, Thank you. That makes total sense. I'm working on a smart watch of my own for a spring time project. But I wanted to see a Difference between running it at 80mhz compare to the 160mhz clock speed because it is a esp8266.

Joseph

The compiler does produce code “knowing” what the processor clock is set for, that means many things will break or one would need to compensate.

Def possible.

And the boot loader - isn’t that just a program that accepts code and burns it into wherever it is run from?

I have always assumed it is only through ICSP that the fuses can be messed with. For some fuses, allowing a program to change them would defeat their purpose.

Someone somewhere because why not has probably made a setup of two Arduino boards wired to be able to program each other, code, EEPROM, fuses whatever.

A bit more googling, please tell me I got this wrong:

The boot loader can do things programmatically that a normal program cannot. However, the mechanism is available, and by using all the same tricks a boot loader uses, where it resides in program memory and so forth, a program can be written that would be able to change the running configuration. While running.

A kinda boot-loader / application Frankenstein.

a7

That is true, I always understood that to mean writing to the program memory to facilitate self modifying code. Which in a true Harvard architecture processor is something you can’t do. It is only code running in a specific page of memory that can do this. This page of memory is where the boot loader is placed and it takes up virtually all the memory. It would be possible to implement the equivalent of the BASIC poke call using just a few bytes.

However we are not talking about a normal Arduino here but an ESP processor so it is probably different.

I guess the big difference would have to be something like requiring use of ICSP dedicated mechanism that burns but isn't really a program that is running on the chip.

Like the old days of needing a high voltage or other special burning tools.

I am all for the progress that lets us do without that now. but it did make some thing impossible way harder, and left questions about changing the clock frequency (or program code!) whilst running mostly unasked.

a7

Well I have found some information about that and it might just be possible.
From the Technical reference manual of the ESP32 processor, it might also be the same for the ESP8266.


  1. 3.2.3 CPU Clock As Figure 6 shows, CPU_CLK is the master clock for both CPU cores. CPU_CLK clock can be as high as 240 MHz when the CPU is in high performance mode. Alternatively, the CPU can run at lower frequencies to reduce power consumption. The CPU_CLK clock source is determined by the RTC_CNTL_SOC_CLK_SEL register. PLL_CLK, APLL_CLK, RTC8M_CLK, and XTL_CLK can be set as the CPU_CLK source; see Table 10 and 11.


*SEL_0: The vaule of register RTC_CNTL_SOC_CLK_SEL *SEL_1: The vaule of register CPU_CPUPERIOD_SEL

Grumpy_Thank you very much. I will look at this carefully it looks promising. Thank you.

Joseph

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.