Arduino nano startup time

Hello all,
I'm getting crazy trying to make the Nano startup as fast as possible.
Some tested and verified points.
1 - With Optiboot I'm sure the bootloader is not starting at power supply.
2 - to test I made a very simple sketch that is turning high pins (D3 and D4) in setup or in loop
3 - The pins go high always after 60-70ms.
4 - i did try with register function too and no change. Time to time if I set in setup, it not go high (never)

#define TOP_LED 4 // D4 il top led arancione

void setup() {

  //pinMode(TOP_LED, OUTPUT); //Led L su Nano
	//digitalWrite(TOP_LED,HIGH);
DDRD |= (1 << PD4);      
  PORTD &= (0 << PD4);       
  
}

void loop() {
  // put your main code here, to run repeatedly:
  //digitalWrite(TOP_LED,LOW);
  PORTD |= (1 << PD4);       // imposta D4 alto
  //digitalWrite(TOP_LED,HIGH);
}

With this condition i did start to goggle why.
I discovered (in the DS as well) there is a sort of waiting time that allows to get stable clock and voltage and it seems to end in this 65ms.
This can be changed via fuse and i think i did try almost all the possible configurations! :smile:
Even killing one Nano that now I'm not able to recover.
I did try as well the calculator:

But again none of the configuration bring me to a 0ms or 4ms startup time. Always 65ms.

last info, to reload the fuse and the optiboot i use the optiloader.

Did some of you get success in changing the startup time?
Any feedback is very welcome .... and also how to recover the two dead Nano boards.
Thx!

Have you tried uploading the sketch using the ICSP interface ?

Doing so has the side effect of removing the bootloader. This eliminates the delay at startup while the bootloader waits for a possible upload before running the sketch that is already present

thx @UKHeliBob for the suggestion. I have not an ICSP programmer apart the arduino AS ICSP that I know is not the same.
nevertheless I used it to load a file compiled with MSYS2 and avr-gcc with just the same low to high pin and a while(1).
Exactly the same behaviour - 65-70ms delay.
I'm sure it is not the bootloader delay because the last optiboot checks the reset and WDT register status to enter or not in bootmode.
it is something related to atmega328 timing that i'm not able to solve. :frowning:

Why do you need the short reset time?

Are you using a Nano with an external crystal or a resonator, or some other configuration (external oscillator, internal oscillator, etc)?

Shortest startup with an external crystal seems to be 1K clock cycles + 14 clock cycles + 0mS, but that may depend on how long it takes the crystal/resonator to stabilize.

1 Like

hi @david_2018 .
it is a standard nano V3 clode board with USB C. Atmega on the top and LDO + CH340 on the bottom.
There is a component connected between 7 and 8 and looking at the package and no filter capacitors I guess is an oscillator or a xtal with embedded caps.
And yes, it should be one of the fastest

Or maybe the 258ck +4ms ... but i do not see difference with the oscilloscope if i write low fuse: 0x26 or 0x06
And this is what is making me crazy and then i started to try any config and probably i wrote the wrong one and 2 boards are now dead.
I did also try to use the BOD level 1.8V that should skip the clock setting .... the same damn 65ms! :sob:

... i need to reduce as much as possible to startup at power-on because it is causing a delay in a motor to start.

Hi @sparatutto.

That is incorrect. You can use the "Arduino as ISP" to perform an "Upload Using Programmer" operation, as @UKHeliBob suggested.

2 Likes

Hi, @sparatutto

Why don't you power up the Nano all the time, or prior to needing the motor to run?

What is your project?

Tom.... :smiley: :+1: :coffee: :australia:

ok then it is exactly the same behaviour. no time reduction.

@TomGeorge it is a sort of joystick that you have to plug and unplug. when you plug in it you don't know if the power is already there or will provide afterword.
But when it is powered you need to drive to the right position as fast as you can.
I'm think to power it with a battery bank to kip it powered when moving from one site to the other ... but before to do that i want to check with you experts if I'm doing something wrong and somebody is capable to get out the HIGH" in 4ms or 0ms ... I'm not!

Have you tried a pull-down resistor on the output pin. During startup of the processor that pin is an input and can have any level (high or low). Till you get to setup() where the pin is set to output and controlled by your code.

The pull-down resistor will keep the output low; pull-up will keep it high.

ok it sounds like i'm setting the wrong external clock and in the wrong place.

I was aware the external xtal on a Nano V3 is 16MHz but it seems it is 8MHz. I'll measure ASAP.
So the working set seems to be Low:0xEE (1K ck/14ck - 0ms) and extended:0x04 (4.3V brownout)
The second issue was where i did put in the optiloader image structure:

onst image_t PROGMEM image_328p = {
  {
    "optiboot_atmega328.hex"
  }
  ,
  {
    "atmega328P"
  }
  ,
  0x950F,				/* Signature bytes for 328P */
  {
    0x3F, 0xEE, 0xDE, 0x04, 0               //Original: 0x3F, 0xFF, 0xDE, 0x05, 0 //fuse high: 0x04--> 4.3V 0x05--> 2.7V 0x06--> 1.8V
  }                                                                               //fuse low: 0xA6--> 1K 14CK+0ms 0xB6--> 1K 14CK+4ms 0x97 --> 16K 14CK+0ms 0xEE --> 1K ck/14ck - 0ms
  ,
  {                           
    0x2F, 0xEE, 0, 0x04, 0  
  }
  ,
  128,
  {
    ":107E000001C0DCC0112484B7882361F0982F9A70D8\n"
    ":107E1000923041F081FF02C097EF94BF282E80E09E\n"
    ":107E2000B8D0EEC085E08093810082E08093C000EE\n"

It works if i put in the first entry.
In the second it seems it is a don't care probably because the first flag is the lock and it is written before the other probably.

I record here in case other has the same issue of me.

With this approach I can startup the system in less than 2ms with eeprom read, uart and I2C configuration
:vulcan_salute: :+1:

1 Like

Why, is this a game controller?

Tom.... :smiley: :+1: :coffee: :australia:

a kind of .... more a toy for fun than a game controller
Any proposal from your side to recover the dead (wrong fuse) or something else that can help me independently by the reason of why i need that? :grimacing: :smiling_face_with_sunglasses:

If you got the fuses really wrong, so that nothing works anymore, you need a 'high voltage programmer' to correct that. But high voltage programming can only be done with the bare chip ( +12V is applied to the reset line and a lot of IO's are used ) - so this might be difficult with a Nano ...

Problem could be only +12V for RESET. FT232RL does not tolerate it. Although there is a C4 100nF capacitor there that can be removed fairly easily. The rest of necessary pins are available.