I have a strange intermittent problem with a self shutdown circuit that is not working as it is supposed to, for an AT90CAN128
The idea is the following:
-the microcontroller board will be power permanently by 12V, the uC gets 5V from a Linear Regulator that has an ENABLE signal.
This enable signal is controlled externally.
When this ENABLE signal is 12V, them the ENABLE_5V for the LTO is high and the uC will be woken up, and the uC will enable a pin that will hold this enable HIGH.
When the ENABLE signal goes from 12V to 0, the the uC is able to hold the ENABLE for the LTO high as long as it needs to do some operations, and then it can turn the pin off
and shut down it's own 5V supply.
The circuit is more complicated than this, but this is the basic operation, I also checked it in detail with the HW guys and can't find any problem.
Unfortunately the circuit doesn't work, or it does work intermittently, like it works 1 out of 10.
From the uC side I am constantly sending high for the PIN that enable the LTO from the moment the uC is powered on, but when I turn off the 12V enable signal, most of the time
both the uC pin and the enable pin turn off and then of course the 5V drops a little later.
The delay between the 12 ENABLE going off and the uC turning it's pin off is around 1.6s, but I can't correlate it to anything in my SW.
I even tried to add some delay before the startup to see if this will change and there is no change.
I am also reading the 5V equivalent of the 12V ENABLE and outputting it's value to a LED and the uC has time to see that the 12V ENABLE is off.
Of course the HW guys blame the uC, even if I told them that I am just sending constant 5V for the enable signal and it is out of my control what is happening.
I already checked all the important signal with the oscilloscope, indeed the hardware which is just an optocoupler, a diode and an LTO seems to work ok, but I can't find any clue to what is happening.
Any ideas of what could happen and how to debug it?