I am working on a project where I am using the Arduino to control a compressor using a relay and a few valves using a high-side switch on a vehicle. Everything seems to be working fine but for example, if the compressor is running and the engine is cranked. This freezes the whole system and it becomes completely unresponsive and must be reset at the power supply. This keeps the compressor running and running and never turning off which a huge safety hazard as well. I thought it might be the undervoltage that is causing it but after doing some tests it is not undervoltage that hangs it. I even have a watchdog timer programmed which does not work either when the MCU hangs. Could it be some sort of EMI? Please let me know. Kind regards.
Can you test this without starting, running or stopping any of the heavy duty stuff you have hanging off the Arduino board? Like disconnect the wires driving any relays or solenoids or motors or the drivers you've used to lower them.
Faults like this are almost certainly a matter of EMI or power supply inadequacy or similar. We see works here, doesn't work there alla time.
So it would be of diagnostic value to prove that the logic is correct. Perhaps by having it on your nice work bench with a good power supply and only pushbuttons, LEDs and potentiometers as proxies for the real world stuff you want to get to.
Even better would be doing such a test entirely within a simulator, so I will mention
I guess you are expecting around 8V from your adjustable regulator. R1 in your schematic is usually set at around 120R. Your higher resistor values may be affecting regulation.
I'm still thinking that's what it is. Have you tried powering the Arduino from a separate power supply, or from your computer's USB port, or from a separate a battery?
You might need a back-up battery, or maybe a diode/capacitor circuit like this:
It will work best with the circuit on the 12V side of the voltage regulator and you might need a bigger capacitor so the capacitor discharges more slowly and the voltage holds-up longer.
Voltage regulators make pretty-good "filters" but they can't "make voltage" when the voltage drops.
It could also be an input or output pin getting an over-voltage or negative-voltage glitch into the processor and somehow crashing it.
Maybe you can wire something into the reset circuit so it resets every time you crank the engine?
You probably need to "reverse the logic" (or something) to make it "fail safe" so the compressor is off when it fails. However you do that, it shouldn't rely on the microprocessor or software/firmware. For example, most relays are double-throw with normally-open or normally-closed contacts.
@omersaeed - I looked at the NCV1117STAT3G data sheet wondering if some small capacitors weren't in the reference circuit, placed in parallel with the 10 uF units.
There were none. But they do say
A 10 F ceramic or tantalum capacitor should be adequate for most applications
and since I heard that no one uses tantalum capacitors any more, I ask what kind of capacitor you have there and wonder above my pay grade if ceramic would be a better choice than tantalum of old fashioned electrolytic caps.
The datasheet also says
A minimum capacitance value of 4.7 F with an equivalent series resistance (ESR) that is within the limits of 33 milliohms (typ) to 2.2 ohms is required.
so to be thorough, you'd want to check that too. Even if it isn't the problem.
Thank you everyone for replying. The input to the MCU after the voltage regulator is constant 5V even on engine crank so it is certainly not undervoltage. Which means the current capacitors should be fine to provide the MCU with constant 5V. So I am not sure what else could it be.
Also I have tested the system with a bench supply and tried to replicate the undervoltage when the engine is cranked. But it works absolutely fine with the bench supply. However, when powered using the car battery the MCU hangs sometimes when the engine is cranked.
An automobile electrical system is among the electrically nosiest systems.
On engine crank, the battery voltage can drop to below 6 volts when cranking hard in an cold environment. The voltage is approximately a sine wave being lowest at each compression cycle.
The "ground" can vary up to 2 volts from location to location in the vehicle.
Voltage spikes up to 1500 are quite common.
Periodic (not when starting) voltages can be as high as 50 Volts.
The grounding, input voltage protection and protection of all signals in and out needs to considered.
This was part of my responsibility when I worked at an automotive OEM.
A full schematic and physical layout need to be evaluated.
Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable. Please include ALL hardware, power supplies, component names and pin labels.
What voltage do you measure on the 5V pin of the "MCU"?
If you meant just leaving everything as it is in the vehicle and supplying good power from a bench supply, you can see why we might still thing your provision of five volts to the project is the main suspect.
There are things that can happen on the power lines that you just won't see on a DMM…
Hi, from what you're talking about it seems like you are dealing with some transient voltage spikes from the vehicle electrical system, especially when cranking. I am not an expert in any way but I had to deal with something similar on one of my projects (an 8v battery running a small brushed motor was creating spikes up to 40v resetting/frying my microcontrollers). I asked about that on this thread and received pretty good help:
and I was ultimately able to fix it for my little project (check out my last post).
As @JohnRob said the voltage on a car electrical system can be all over the place (especially if you're also running a compressor or other "dirty" load) and our microcontroller doesn't really like that.
On top of that if you have access to an oscilloscope to check the voltage going into the microcontroller that would be even better for troubleshooting.
Hope this helps
Welcome to the wonderful world of automotive electronics. It is a very complex system with many things that have to be taken into consideration and appropriate application of the components. It is NOT a simple 12V system. Try these links:
There is a good app note AN2689 by ST on automotive electronics. reading it will help you a lot.
These are a starting point, not a solution. I hope this is a one up application. At a minimum you will need a scope in the minimum of 500 Mhz range. You also need to understand failsafe and what it encompasses. You might want to download the AEQ series of specifications for automotive and its associated components. Good Luck. Is this going on a vehicle that will be on the public road?