I'm working on a project which uses an ATMEGA328P chip on a custom PCB of my own design. Under certain circumstances the reset pin, usually pulled high with an external resistor have fitted, of this ATMEGA gets taken low by an external signal and the ATMEGA resets. Resetting like this is necessary for my project's design. I've described this as an "uno" because on the custom PCB my ATMEGA chip is fitted with the same 16MHz Oscillator and 22pF capacitor pair that an uno has, it runs from a regulated 5V supply like an uno does, and as there are not the necessary pins free for any form of in system programming I pop this ATMEGA out of the custom board's 28pin DIP holder, stick it into the DIP socket of an actal arduino uno, program it as if it were an uno, then put my programmed ATMEGA back in the DIP socket of the PCB. Once the project is finished the ATMEGA will no longer need reprogramming unless I find a bug in need of fixing, I hence don't want to do anything weird with fuse bits which makes the ATMEGA non-reprogrammable (I don't want to have to turn to high voltage programming to reset it), but don't mind doing things which mean the ATMEGA will need a it mroe laborious a programming process than clicking "upload".
My problem is that after resetting the ATMEGA with the reset pin it takes more thn 2 seconds to get my arduino sketch running, I need to reduce this time to 0.5 seconds maximum, though I'd ideally like it to be under 100ms or even under 50ms from the reset pin going high again to my sketch starting.
When I reset an atmega by cutting off the 5V supply, then turning it on again the booting is much quicker than 2 seconds, but due to what else is on my custom PCB and what pins of the ATMEGA and other things are available I am NOT able to use a "cut off the power supply the restore it" method to reset the atmega. I am also not able to use software methods and cannot do anything involving using an input pin to somehow trigegr a reset. I need reset to be done in the usual way by taking the first pin of the ATMEGA328P DIP packaae to ground.
I have already written a sketch in the arduino IDE using a mix of arduino functions and AVR register access functions, it works very well and I don't want to change it. I don't want to do anything which would force me to use a more raw form of code without the useful arduino functions.
I understand that the reason booting up takes so long after the reset pin has been low and then released to 5V again is because the arduino bootloader is waiting to see if it is being reprogrammed, but 2 seconds is a long time.
I think that a fix will either involve changing the bootloader to be faster or getting my code onto the ATMEGA without using a bootloader at all.
If I try to change the bootloader how is this done, or would reducing the booting time to reduce the 2 second delay to more like 50ms to100ms cause problems with my ability to upload programs to the ATMEGA?
The alternative seems to be getting tid of the bootloader entirely, but I don't know hpw easily this is done. Firstly I need to check whether, if programmed with an ISP method rather than the usual arduino way, the time for starting a .ino sketch after reset went high again would be reduced to nearly instantaneous?
I have several uno boards and loads of arduino uno bootloaded ATMEGA328P chips to hand and believe that I could take the ATMEGA out of an uno, put into it the ATMEGA which will go into my cutom PCB, then use one of my other unos as an arduino ISP. I have used an arduino uno as an ISP before, but only to put the usual bootloader onto a brand new unbootloaded ATMEGA328P chip. I'm not sure whether, or if so how, an arduino uno as a ISP can be used to put sketches on another ATMEGA328P in a way which allows that latter ATMEGA328P to run the sketch wthout first bootloading.
I hear rumours about an "upload with programmer" function in the arduino IDE but coldn't find a good tutorial about getting a sketch onto an atmega328p such that it doesn't have a bootloader on, nor am I sure whether all arduino functions will still work properly if a .ino sketch is directly programmed to an ATMEGA and the bootloader is avoided. I also hear rumours about using AVR dude from command line but this looks quite complex and seems to involve make files and compiling lots of source code before it can be done. Even then there look to be lots of command line options which avrdude needs to be fed with, and I'm not sure what the correct set of arguments for an uno like atmega328p chip would be when an arduino is being used as the ISP.
Also, once a sketch is uploaded by an ISP method and the atmega328p chip no longr has a bootloader, does reprogramming the atmega328p with new versions of the sketch require any weird steps, or is it just the same as programming it with an ISP the first time, and if you ever did want to make the chip act like a regular uno again could you put a bootloader back onto it (not that I itend to unless my sketch suddenyl needs further debugging).
Can anyone provide advice on these matters? Thanks.
P.S.I could buy an actual AVR ISP of some kind if necessary, but would rather use an arduino uno as ISP instead because I have to work from many different computers (windows x86, linux x86 (multiple different distros, some machines intel, others AMD), raspbian ARM...) and hear that ISP devices often have bothersome drivers which don't handle different types of computer too well.