Is possible to set the oscillator frequency by code?

Hi, I am using the Arduino Nano that has an external frequency of 16Mhz, if I load it is Sketch using the Arduino, everything runs fine, but if I load it using an external programmer (Atmel-ICE) it changes the behavior and the process becomes very slow. , to some way in which you can configure the work frequency by code so as not to have this problem?

How slow? The frequency of the crystal does not change but the microcontroller has a built-in divider 8, which is activated by a fuse bit CKDIV8 and then it will work as if the frequency is 16:8 = 2MHz.

How slow? The frequency of the crystal does not change but the microcontroller has a built-in divider 8, which is activated by a fuse bit CKDIV8 and then it will work as if the frequency is 16:8 = 2MHz.

You're right I'm going to change that, possibly that's the cause of my problem

Another possibility is that it is running at half speed. That would happen if the fuses were changed to use the internal 8 MHz oscillator instead of the 16 MHz crystal/resonator.

And if both happen: 1 MHz.

But is there any way to place a command or a definition setting the value of the oscillator frequency, which in this case would be 16MHz?

If the CKDIV8 fuse is accidentally set you can undo that in software:

CLKPR = _BV(CLKPCE);  // Set Clock Prescale Change Enable
CLKPR = 0; // Set Clock Prescale Register to 0 (Prescale == 1)

Don't need to specify oscillator frequency?

It's only about a prescaler. It divides the oscillator frequency, no matter what this frequency is.

The base oscillators are hardware. They are what they are and can't be changed in software. All you can do is change the amount by which the oscillator is divided before it is used.